Conversation
…nsitive information Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
| redacted_payload = payload.copy() | ||
| if "password" in redacted_payload: | ||
| redacted_payload["password"] = "***REDACTED***" | ||
| print(f"[DEBUG] POST {login_url} payload={redacted_payload}") |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 8 months ago
To fix the problem, we should avoid logging any sensitive information, including usernames and authentication payloads, even in debug mode. Instead, we can log only non-sensitive information, such as the URL being accessed and the fact that a login attempt is being made. Specifically, in the block where the payload is logged, we should remove the payload from the log message or, at most, log only the non-sensitive fields (e.g., the presence of a logintoken, but not its value, and not the username or password). The change should be made in the _standard_login method, around line 113 in src/py_moodle/auth.py. No new imports or methods are required.
| @@ -109,6 +109,3 @@ | ||
| if self.debug: | ||
| redacted_payload = payload.copy() | ||
| if "password" in redacted_payload: | ||
| redacted_payload["password"] = "***REDACTED***" | ||
| print(f"[DEBUG] POST {login_url} payload={redacted_payload}") | ||
| print(f"[DEBUG] POST {login_url} (login attempt)") | ||
| resp = self.session.post(login_url, data=payload, allow_redirects=True) |
Potential fix for https://github.com/erseco/python-moodle/security/code-scanning/3
To fix the problem, we should avoid logging sensitive information such as passwords. The best way to do this is to redact or omit the password field from the payload before logging it. We can create a copy of the payload dictionary with the password replaced by a placeholder (e.g.,
"***REDACTED***"), and log this redacted version instead. This change should be made only in the debug log statement on line 110, and does not require changing the actual payload sent to the server. No new imports are needed, as dictionary copying and manipulation are built-in Python features.Suggested fixes powered by Copilot Autofix. Review carefully before merging.