Potential fix for code scanning alert no. 8: Uncontrolled data used in path expression#16
Draft
johnsamuelwrites wants to merge 4 commits intomasterfrom
Draft
Potential fix for code scanning alert no. 8: Uncontrolled data used in path expression#16johnsamuelwrites wants to merge 4 commits intomasterfrom
johnsamuelwrites wants to merge 4 commits intomasterfrom
Conversation
…n path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…n path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in 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/johnsamuelwrites/ShExStatements/security/code-scanning/8
In general, to fix uncontrolled path usage you must (1) normalize the user‑provided path, and (2) enforce that the resulting path is within a designated safe directory or an explicit allow‑list, rejecting anything else. Simply disallowing absolute paths and
..segments is not sufficient if the application can have a sensitive working directory.In this code, the minimal, backward‑compatible fix is to introduce a single “safe root” directory (e.g. the process’ current working directory) for all file accesses in
generate_shex_from_csvwhenfilenameisTrue. We then:filepathto remove redundant separators and..segments.os.path.join(base_dir, normalized_path).base_dirusing a robust prefix check (os.path.commonpath), which correctly handles cases where simple stringstartswithwould fail.safe_fullpathwhen opening the file.This keeps existing functionality (relative paths still work) but prevents traversal outside the chosen base directory and blocks absolute paths implicitly (since
os.path.join(base_dir, abs_path)discardsbase_dir, which will then fail the commonpath check). We only need to modifyshexstatements/shexfromcsv.pyinside theif filename:branch; no changes are required inapplication.py. We will add the new logic in place of the current ad‑hoc normalized_path checks, reusing the existingimport os.Suggested fixes powered by Copilot Autofix. Review carefully before merging.