Potential fix for code scanning alert no. 9: Uncontrolled data used in path expression#53
Merged
justindobbs merged 1 commit intomainfrom Feb 28, 2026
Merged
Potential fix for code scanning alert no. 9: Uncontrolled data used in path expression#53justindobbs merged 1 commit intomainfrom
justindobbs merged 1 commit intomainfrom
Conversation
…n path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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/justindobbs/Tracecore/security/code-scanning/9
General strategy: Treat all externally provided run references (
run_id,replay,a,b,run_a,run_b) as untrusted and constrain them to safe identifiers before using them to construct filesystem paths. For identifiers that are meant to reference files in.agent_bench/runs, we can restrict them to a safe pattern (e.g., alphanumeric, dash, underscore) and possibly a maximum length. This avoids directory traversal and prevents using absolute or relative paths. Because we cannot modifyload_run_artifacthere, the most direct fix for the reported alert path is to hardenload_runinrunlog.py, since that’s the function CodeQL flags and it’s the one used in all the tainted flows.Best concrete fix: Introduce a small helper in
agent_bench/runner/runlog.pyto validaterun_idstrings, then call it from bothpersist_runandload_run. The helper will enforce a whitelist of allowed characters (e.g.,A-Za-z0-9_-) and a reasonable length limit. If validation fails, raise aValueError. This preserves existing semantics for normal IDs (which presumably match this pattern) while making path traversal impossible and addressing all variants that pass user-controlled IDs intoload_run. We do not need new imports beyond what is already there; we can define a simple check inline usingstr.isalnum()and a small allowed extra character set.Concrete changes in
agent_bench/runner/runlog.py:Add a new private function
_validate_run_id(run_id: str) -> strnear the top of the file (after the constants, before_ensure_root). This function:-, or_.ValueErrorif any check fails.run_idif valid.In
persist_run, after fetchingrun_id = result.get("run_id")and checking for truthiness, pass it through_validate_run_idand use the validated value to build the path.In
load_run, validate the incomingrun_idvia_validate_run_idbefore using it to construct the path.These targeted edits keep behavior the same for legitimate IDs, avoid assumptions about other modules, and directly fix the uncontrolled path construction in the snippets referenced by CodeQL.
Suggested fixes powered by Copilot Autofix. Review carefully before merging.