fix(security): make personal path confinement CodeQL-visible#5713
Closed
RaresKeY wants to merge 1 commit into
Closed
fix(security): make personal path confinement CodeQL-visible#5713RaresKeY wants to merge 1 commit into
RaresKeY wants to merge 1 commit into
Conversation
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.
Summary
Makes the existing personal-directory confinement visible to CodeQL without weakening its runtime boundary. The add and remove routes now canonicalize the requested path with
realpath(), apply a route-local analyzer-recognized prefix guard, and then require either the exact personal-documents root or a separator-delimited descendant.Keeping the guard in each request-to-sink scope is intentional: a local CodeQL reproduction showed that returning a checked path from the previous helper did not carry the safe-access fact to the filesystem and RAG sinks. Endpoint regressions cover both routes, accepted root/descendant forms, parent and sibling-prefix escapes, symlink escape, sink reachability, and unchanged resolved-path identity. No CodeQL query, severity, workflow, or SARIF filter is changed.
Target branch
dev, notmain. All PRs land indev;mainis curated by the maintainer at each release. If your PR is onmainby accident, click "Edit" on this PR and change the base.Linked Issue
Fixes #5712
Type of Change
Checklist
devdocker compose uporuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.Not run: a live app. This is a backend/static-analysis fix; the affected admin-only endpoints were exercised directly through the secretless test runner, including both accepted and rejected paths.
How to Test
Run the focused personal-directory and adjacent RAG regressions:
Expected:
34 passed.Compile the changed Python files and check the diff:
Run the Python CodeQL
py/path-injectionquery. The flow fromDirectoryRequest.directory/ the remove-directory query parameter to the personal route filesystem checks andsrc/rag_vector.pytraversal should produce no alert. A local CodeQL 2.26.0 /python-queries1.8.5 run against this exact head produced no result in either add/remove route and no result insrc/rag_vector.py. The one remainingpersonal_routes.pyresult is an unrelated, pre-existing delete-file flow.Optional broader check:
On the rebased head, the secretless review runner produced
4702 passed,10 skipped, and 12 failures. Cleandevproduced4693 passed,10 skipped, and 11 failures. The additional full-run failure is an upload-backup test that fails on both trees when its test module is run directly, confirming an order-sensitive baseline rather than a changed-file regression. The remaining failures cover the runner-excluded.env.example, an integration URL assumption, upload atomicity fixtures, and network-blocked web-fetch tests; none touches this change.GitHub Actions CodeQL 2.26.1 passed on draft PR #5713, including the Python analysis and aggregate CodeQL check.
Visual / UI changes — REQUIRED if you touched anything that renders
N/A — backend route validation and tests only; no UI rendering changed.
--red,--fg,--bg,--card,--border, etc.) — do not introduce new color values, font sizes, or spacing units.static/index.html) or plain text.Fira Code) for primary UI text. Don't override.Screenshots / clips
N/A — no visual changes.