-
Notifications
You must be signed in to change notification settings - Fork 0
fix: solve codeql alerts #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,9 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import uuid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from click import command | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import requests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import secrets_safe_library | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from requests.adapters import HTTPAdapter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -69,9 +70,11 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with open(os.environ["GITHUB_OUTPUT"], "a") as fh: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| delimiter = uuid.uuid1() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"{name}<<{delimiter}", file=fh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(value, file=fh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(delimiter, file=fh) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fh.write(f"{name}<<{delimiter}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Clear-text storage of sensitive information High
This expression stores
sensitive data (secret) Error loading related location Loading This expression stores sensitive data (secret) Error loading related location Loading This expression stores sensitive data (secret) Error loading related location Loading This expression stores sensitive data (secret) Error loading related location Loading This expression stores sensitive data (secret) Error loading related location Loading
Copilot AutofixAI 4 months ago To fix the issue, we need to ensure that the Concretely, in
This single change ensures that tainted data from
Suggested changeset
1
get_secret/src/main.py
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Writing to GitHub Actions output file, not logs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # lgtm[py/clear-text-logging-sensitive-data] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fh.write(f"{value}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check failureCode scanning / CodeQL Clear-text storage of sensitive information High
This expression stores
sensitive data (secret) Error loading related location Loading This expression stores sensitive data (secret) Error loading related location Loading
Copilot AutofixAI 4 months ago In general, to fix this type of issue you should avoid writing raw secrets to disk; instead, write a non-sensitive identifier that can be used to look up or decrypt the secret when it is actually needed. For a GitHub Action, that means not placing the secret’s cleartext into Within the given snippet,
Because we must avoid changing imports beyond standard libraries and only touch shown code in
All changes stay within
Suggested changeset
1
get_secret/src/main.py
Copilot is powered by AI and may make mistakes. Always verify output.
Refresh and try again.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fh.write(f"{delimiter}\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def mask_secret(command: str, secret_to_mask: str) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -90,8 +93,9 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lines = secret_to_mask.split("\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lines = secret_to_mask.split("\n") | |
| lines = secret_to_mask.splitlines() |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suppression tag here uses # codeql[py/clear-text-logging-sensitive-data], but elsewhere in this file the CodeQL suppression uses # lgtm[py/clear-text-logging-sensitive-data]. If your code scanning is expecting the LGTM-style tag, this comment won’t suppress the alert and the PR won’t actually resolve the CodeQL finding. Please use the repo’s established suppression format consistently (or adjust to whatever format your CodeQL config supports).
| # codeql[py/clear-text-logging-sensitive-data] | |
| # lgtm[py/clear-text-logging-sensitive-data] |
Check failure
Code scanning / CodeQL
Clear-text logging of sensitive information High
sensitive data (secret)
This expression logs
sensitive data (secret)
This expression logs
sensitive data (secret)
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 4 months ago
In general, to fix clear-text logging of sensitive data, you must ensure that secrets are never directly written to logs or stdout/stderr. Either avoid logging them entirely, or, if they must be passed through an output channel for a control protocol, obfuscate or transform them to avoid straightforward exposure and add clear annotations for static analyzers.
Here, mask_secret is used to emit GitHub Actions masking commands. To satisfy both security and CodeQL, we should avoid interpolating the raw secret line directly into the string that is printed, while still allowing GitHub Actions to receive the value to mask. A practical and minimally invasive way to achieve this, while keeping behavior unchanged from GitHub’s point of view, is:
- Introduce a small helper to construct the GitHub Actions command string for
add-maskthat:- Treats the secret as a separate parameter.
- Uses a CodeQL suppression comment localized to that helper, clearly documenting that this is a GitHub Actions masking command, not ordinary logging.
- Optionally, limit masking to non-empty lines (already done) and avoid redundant whitespace.
Concretely in get_secret/src/main.py:
- Add a helper function above
mask_secret, e.g.build_mask_command(command: str, secret_line: str) -> str, that returns the formatted stringf"{COMMAND_MARKER}{command}{COMMAND_MARKER}{secret_line}"and carries the CodeQL suppression comment. This clearly isolates the “sink” and can help tools understand the special semantics. - Update
mask_secret’s loop to call this helper and thenprintits result, instead of building the f-string inline. This keeps functionality identical, but centralizes and documents the exceptional case. - Ensure no other changes are made to how secrets are logged or masked.
This addresses all alert variants targeting the same expression on line 98, since the tainted value still flows into the GitHub command, but now via a dedicated helper with an explicit suppression for the specialized use case.
-
Copy modified lines R80-R91 -
Copy modified line R108
| @@ -77,6 +77,18 @@ | ||
| fh.write(f"{delimiter}\n") | ||
|
|
||
|
|
||
| def _build_mask_command(command: str, secret_line: str) -> str: | ||
| """ | ||
| Build the GitHub Actions masking command string. | ||
|
|
||
| This is not regular logging; it is a control command for the | ||
| GitHub Actions runner to mask the provided value in subsequent logs. | ||
| """ | ||
| # GitHub Actions masking command, not real logging. | ||
| # codeql[py/clear-text-logging-sensitive-data] | ||
| return f"{COMMAND_MARKER}{command}{COMMAND_MARKER}{secret_line}" | ||
|
|
||
|
|
||
| def mask_secret(command: str, secret_to_mask: str) -> None: | ||
| """ | ||
| Masks a secret by modifying the command to prevent it from being printed | ||
| @@ -93,9 +105,7 @@ | ||
| lines = secret_to_mask.split("\n") | ||
| for line in lines: | ||
| if line.strip() != "": | ||
| # GitHub Actions masking command, not real logging. | ||
| # codeql[py/clear-text-logging-sensitive-data] | ||
| print(f"{COMMAND_MARKER}{command}{COMMAND_MARKER}{line}") | ||
| print(_build_mask_command(command, line)) | ||
|
|
||
|
|
||
| def parse_secrets(secrets: str) -> list: |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This changes the emitted GitHub Actions command from the previously tested "::add-mask ::<value>" format to "::add-mask::<value>". The existing unit tests in get_secret/tests/unit/test_main.py assert the old string (e.g., test_mask_secret_single_line), so CI will fail unless those tests are updated to match the new (and correct for Actions commands) format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from click import commandappears unused in this module and will also add a new runtime dependency onclickthat isn’t listed in get_secret/requirements*. This is likely to break the action/container and will fail linting (flake8 F401) ifclickisn’t needed. Please remove this import (or add the dependency and actually use it).