Java: fix bug in partial path traversal#21734
Merged
owen-mc merged 5 commits intogithub:mainfrom Apr 20, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes recognition of file-separator appends in the Java partial path traversal queries so that x += File.separator is handled correctly (in addition to x = x + File.separator), and updates the associated tests and release notes.
Changes:
- Extend the separator-append detection to cover
+=in the PartialPathTraversal library. - Convert the PartialPathTraversal test to inline expectations with per-query alert IDs and add a regression case for
+= File.separator. - Add a changelog entry describing the analysis fix.
Show a summary per file
| File | Description |
|---|---|
| java/ql/test/query-tests/security/CWE-023/semmle/tests/PartialPathTraversalTest.java | Updates inline alert expectations to be query-id specific and adds foo25 covering path += File.separator. |
| java/ql/test/query-tests/security/CWE-023/semmle/tests/PartialPathTraversal.qlref | Switches to query: + postprocess: format and enables PrettyPrintModels + InlineExpectations postprocessing. |
| java/ql/lib/semmle/code/java/security/PartialPathTraversal.qll | Updates separator-append matching to include compound += expressions. |
| java/ql/lib/change-notes/2026-04-18-partial-path-traversal-fix.md | Adds change note for the fix affecting both query variants. |
Copilot's findings
Comments suppressed due to low confidence (1)
java/ql/test/query-tests/security/CWE-023/semmle/tests/PartialPathTraversalTest.java:238
- Adding
foo25here shifts all subsequent line numbers inPartialPathTraversalTest.java. ThePartialPathTraversalFromRemoteTest.expectedfile references later locations (for example around thesock.getInputStream()source currently on line 260), so its expected output will need to be regenerated/updated to account for the new line numbering.
void foo25(File parent) throws IOException {
String path = parent.getCanonicalPath();
path += File.separator;
if (!dir().getCanonicalPath().startsWith(path)) {
throw new IOException("Invalid directory: " + dir().getCanonicalPath());
}
}
- Files reviewed: 4/4 changed files
- Comments generated: 1
Contributor
Author
Rerun has been triggered: 4 restarted 🚀 |
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
3bf9483 to
c6f641e
Compare
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.
The code to recognise file separator appends worked for
x = x + File.separatorbut not for+=, as inx += File.separator.