Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/py_moodle/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@
"anchor": "",
}
if self.debug:
print(f"[DEBUG] POST {login_url} payload={payload}")
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

This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.
This expression logs
sensitive data (password)
as clear text.

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.


Suggested changeset 1
src/py_moodle/auth.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/py_moodle/auth.py b/src/py_moodle/auth.py
--- a/src/py_moodle/auth.py
+++ b/src/py_moodle/auth.py
@@ -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)
EOF
@@ -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)
Copilot is powered by AI and may make mistakes. Always verify output.
resp = self.session.post(login_url, data=payload, allow_redirects=True)
if self.debug:
print(f"[DEBUG] Response {resp.status_code} {resp.url}")
Expand Down
Loading