Repository navigation
Java: Path Injection FP fix - #413
Open
Chanel (chanel-y) wants to merge 7 commits into
Open
Chanel (chanel-y) wants to merge 7 commits into
Chanel (chanel-y) wants to merge 7 commits into
Conversation
Add safe and adversarial helper fixtures, recording the current two false-positive diagnostics before updating containment recognition. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07dbce6b-e7a3-48b2-a656-bddbcb83db5b
Recognize successful canonical parent equality before returning the same candidate. Preserve the allowed-directory parameter's taint at helper calls. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07dbce6b-e7a3-48b2-a656-bddbcb83db5b
Remove the two pre-fix false-positive diagnostics after canonical parent validation is recognized. Unsafe cases retain their inline taint expectations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07dbce6b-e7a3-48b2-a656-bddbcb83db5b
Add safe and adversarial parent-walking helpers, recording four false-positive and four missed-taint diagnostics before adding ancestor-loop recognition. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07dbce6b-e7a3-48b2-a656-bddbcb83db5b
Require all loop SSA-phi inputs to be candidate-parent initialization or self-parent update, with successful equality controlling return of the unchanged candidate. Preserve directory taint for generic calls and method references. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07dbce6b-e7a3-48b2-a656-bddbcb83db5b
Remove the four false-positive and four missed-taint diagnostics after ancestor-loop recognition and directory-taint propagation are updated. Unsafe cases and the documented pre-existing lexical-prefix gap retain their inline expectations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07dbce6b-e7a3-48b2-a656-bddbcb83db5b
Remove change notes and retain the reported helper patterns with closely related unsafe cases. Focused canonical-containment tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 07dbce6b-e7a3-48b2-a656-bddbcb83db5b
This branch has not been deployed
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
False-positive
java/path-injectionalerts where static helper methods already validate that a canonical file path stays inside an allowed directory. The query entry point is unchanged; the correction is in the shared JavaPathSanitizer.qlllibrary.The two patterns below are simplified versions of the reported validation helpers. In both, the allowed directory is trusted, callers use the returned file only when it is non-null, and canonicalization failures prevent the helper from returning a file.
False-positive patterns
1. The file's direct parent must equal the allowed directory
Why this is a false positive: the user controls the name, but the helper returns the file only if its canonical parent is exactly the canonical allowed directory. A path that escapes that directory, including through
.., fails the check. Canonicalization alone is not the protection; the subsequent parent-equality check is.How the query changes: recognize a successful
File.equalscomparison between the canonical directory and the canonical candidate's parent, provided that comparison controls the return of the same candidate. Treat that validated return as a path-injection sanitizer.2. Walking the parents must find the allowed directory
Why this is a false positive: the helper returns the canonical candidate only after finding the allowed directory among its parents. This permits files in nested subdirectories but rejects paths outside the allowed directory.
How the query changes: recognize the ancestor-walking loop and its successful equality check. The analysis verifies that every input to the loop's parent variable is either the candidate's initial parent or the previous parent's parent, and that equality controls the return of the unchanged candidate. This prevents an unrelated or unchecked value from satisfying the modeled containment check.