JavaBuilder setUpSourceJars resolves .srcjar entry names without containment check (same pattern as #28120)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 83/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- java
- Domain
- build-system
Research direction
Start with SimpleJavaLibraryBuilder.setUpSourceJars and compare its extraction logic with the GenClass fix for #28120. Check both the normal and collision-renamed destination paths for entries containing ..; the issue proposes rejecting any normalized path outside sourcesDir. Done means escaping entries fail with a clear error while entries inside the extraction directory still work.
Written by the indexing model from the issue text.
Description
Description of the bug:
SimpleJavaLibraryBuilder.setUpSourceJars extracts .java entries from each --source_jars input into the build's temp directory:
String fileName = entry.getName();
if (fileName.endsWith(".java")) {
if (fileName.charAt(0) == '/') {
fileName = CharMatcher.is('/').trimLeadingFrom(fileName);
}
Path to = sourcesDir.resolve(fileName);
...
Files.createDirectories(to.getParent());
Files.copy(jarFile.getInputStream(entry), to);
Leading / is stripped, but .. segments are not, so an entry like ../../x/Foo.java is written outside sourcesDir. The collision path (sourcesDir.resolve(Integer.toString(root++)).resolve(fileName)) has the same issue.
This is the same pattern fixed in GenClass for #28120 (559326a301). Following the discussion there, we're not claiming a security boundary, since srcjars come from build inputs, which can already run code. The point is hermeticity: a buggy srcjar producer (genrule, codegen tool, third-party srcjar) should fail with a clear error rather than write outside the extraction root.
CodeQL's java/zipslip query flags this location.
Proposed fix
After computing to (including the collision-renamed path), reject entries that don't stay under sourcesDir:
Path root = sourcesDir.normalize();
...
if (!to.normalize().startsWith(root)) {
throw new IOException(
String.format("%s: entry %s escapes the source extraction directory", sourceJar, entry.getName()));
}
This is a lexical check; it doesn't address symlinks already present in sourcesDir (which cleanupDirectory empties first).
Which operating system are you running Bazel on?
Any (code path is platform-independent).
What is the output of bazel info release?
Present at 9.3.1 and on master as of 7849f5e0d3.
- Dominant language
- Java
- Stars
- 26.2k
- Forks
- 4.7k
- Avg merge
- 3d 11h
- Merged PRs (30d)
- 125
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazelbuild/bazel
-
Remote repo contents cache rejects repos with a backslash in a file name on UnixPossibly taken A pull request linked to this issue is open or already merged. Openteam-Remote-Exec type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bazelbuild/bazel#32601 · 3 comments · 1 assignee ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bazelbuild/bazel#32132 ·
Maintainers usually reply within 2 days
-
team-Local-Exec type: documentation (cleanup)
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bazelbuild/bazel#31318 ·
Maintainers usually reply within 2 days
-
Docs: run/build.mdx describes a sandboxing warning removed in 2017 and a flag deleted in 9.0.0Possibly taken @lavishdev claimed this 70 days ago. Openhelp wanted P2 team-Documentation team-OSS type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
bazelbuild/bazel#31316 ·
Maintainers usually reply within 2 days
-
Rename gen_mdx_reference_docs to gen_reference_docsPossibly taken @kapunahelewong claimed this 73 days ago. OpenP2 team-Documentation team-OSS type: documentation (cleanup)
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
bazelbuild/bazel#31211 · 2 comments ·
Maintainers usually reply within 2 days
All issues in bazelbuild/bazel
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Lincoln-cn/JAiRouter#1473 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
exercism/java-analyzer#379 ·
-
area: ui bug priority: low
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
tetsuji16/microProject#1893 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
liberation-data/fornax4j#325 ·
Maintainers usually reply within 1 day
-
[Bug]: FE and Kinesis extraction pipes render flow starting at the centre and scroll the source arm backwardsPossibly taken @chonkzillaofficial claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
BCCE-team/BuildCraft#85 ·