Repository navigation
Potential fix for code scanning alert no. 9: Uncontrolled data used in path expression - #74
Merged
Merged
Conversation
…n path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…h-policy tests - Remove blanket rejection of all absolute paths; instead resolve them and validate against configured roots (403 if outside, accepted if inside). - Relative paths continue to be resolved from each root in order. - NUL bytes, .. traversal segments, and empty/whitespace paths still rejected with 400 before any filesystem access. - Add tests/api/test_path_policy.py covering all rejected cases (NUL, POSIX absolute outside root, Windows drive path, UNC, .. traversal with forward/backslash separators, empty, whitespace, relative outside root) and accepted cases (bare filename, nested relative, absolute inside root, absolute in subdirectory, path in second of multiple roots, single- dot segments).
…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>
…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>
… roots The bot's autofix re-introduced two problems: 1. Blanket 400 rejection of all absolute paths - breaks integration tests and legitimate clients that supply full paths inside a configured root. 2. _SAFE_PATH_SEGMENT_RE whitelist ([A-Za-z0-9._ -]) rejects parens/plus/etc. in real filenames (e.g. AvBay(470mm)single.wind). Restore the correct approach: absolute paths that resolve within a configured root are accepted; those outside get 403. Relative paths are resolved from each root in order. NUL bytes and '..' segments are still rejected with 400 before any filesystem access. Also fix ruff lint errors in test_path_policy.py (I001 import order, E501 line-too-long on two method signatures).
…ests
Root cause of CI failures on Linux/macOS:
On POSIX, backslash is a regular filename character, so C:\Windows\...
and \\server\share\... were treated as relative paths that resolved
happily within the configured root - no exception raised.
Fix in _resolve_user_path:
- Normalise backslashes to forward slashes before all checks.
- Reject POSIX absolute paths (leading /) with 400.
- Reject Windows drive-absolute paths (alpha + ':') with 400.
- UNC paths (\\server\share) normalise to //... and are caught by the
leading-/ check above - no separate branch needed.
- Build the returned path from Path(*validated_parts) joined onto a
trusted root, never from the raw user string. This breaks the taint
chain that triggered the CodeQL 'Uncontrolled data used in path
expression' alert.
Integration test updates (test_plan_route, test_simulate_route):
- Pass relative paths ('input.wind', 'program.gcode') to the API
instead of absolute tmp_path-based paths, matching the new policy.
- Replace 'rejects path outside allowed roots' (403) tests with
'rejects absolute path' (400) and 'rejects traversal' (400) tests.
test_path_policy updates:
- Split single POSIX-absolute test into dedicated tests per path type
(POSIX /, Windows drive C:, Windows drive C:/, UNC backslash, UNC /).
- All of the above now assert 400 - cross-platform, no skipif needed.
- Replace 'absolute inside root accepted' tests with
'absolute_path_always_rejected' (400).
- Fix multi-root accepted test: relative paths resolve from the first
root, so test each root independently.
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/CameronBrooks11/fiberpath/security/code-scanning/9
General fix approach: enforce strict validation of untrusted path strings before constructing filesystem paths. Accept only relative, non-empty, non-traversing paths, then canonicalize and enforce allowed-root containment.
Best concrete fix in
fiberpath_api/path_policy.py:_resolve_user_path, add pre-validation onuser_path:/...and Windows drive/UNC forms),..traversal segment._is_within_rootscontainment checks.This preserves intended functionality (reading files under configured roots) while removing risky/ambiguous input forms and addressing all 3 variants because all endpoints call
enforce_input_path_policy.No route-file changes are required; central policy hardening covers
plan.py,simulate.py, andvalidate.py.Suggested fixes powered by Copilot Autofix. Review carefully before merging.