Potential fix for code scanning alert no. 1: Uncontrolled command line#83
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds documentation comments to two existing validation functions (validate_container_name and validate_log_filename) in the FastAPI backend. The PR aims to address a CodeQL security alert about uncontrolled command line execution by improving code clarity around input validation.
Key changes:
- Added clarifying comment to
validate_container_namefunction - Enhanced documentation for
validate_log_filenamewith detailed NOTE about restrictions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Potential fix for https://github.com/karam-ajaj/atlas/security/code-scanning/1
General approach: Ensure that all user-controlled values that influence the subprocess command line are strictly validated/normalized before being used, and that CodeQL can clearly see this validation. Continue to avoid
shell=True, keep commands as hard-coded literals, and only allow benign, tightly constrained arguments that are necessary for functionality.Best concrete fix here, without changing existing behavior:
subprocessinvocations (already safe).safe_filenameandvalidate_log_filename, but CodeQL’s taint trace suggests it still considers the value “tainted” when used to buildfilepathand thencmd.validate_log_filenameby:/and\.cmdare:"docker","logs","tail", flags).safe_containerfromvalidate_container_name.filepathderived fromsafe_filenamewith strong directory confinement (os.path.commonpath).Since all of this is already largely implemented, the change is minimal; we mainly clarify and preserve the existing safe pattern so the data flow is obviously constrained. There is no need for new imports or additional helper methods beyond what’s already present in the snippet.
Concretely, in
config/scripts/app.py:cmdconstruction instream_log, which already uses only validated values and a safe, non-shell subprocess call.No functional behavior is changed: the same filenames and container names that were allowed before remain allowed, and the same subprocess calls are made, but the code remains explicitly and defensively structured around validation.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.