Skip to content

[Data Extension Create]: CWE-22 CRITICAL - Java: Java summary models so request usernames reach file path sinks in upload handlers #35

Open

Description

@felickz

Target Language

java

Library Repository / Documentation URL

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/File.html

Data Extension Name (Optional)

path-injection.model.yml

Library Modules / Components

  • java.io.File, java.nio.file.Paths/Path constructors (verify they are already modeled)
  • Spring MultipartFile.transferTo and servlet Part.write

Data Extension Description

A public synthetic Spring app accepts an unvalidated username on profile update and uses it in a filesystem path for the upload. java/path-injection did not alert; the workbook calls it a missing summary. Verify which step (string concat into new File(base, user) or a stored value rather than a request value) is not covered before adding rows.

Linked findings (gap-key: java/data-extension/path-injection-username-upload)

Repo CWE Severity AI scan alert Summary
verademo CWE-22 critical https://github.com/codeql-forks-felickz/verademo/security/code-scanning/78 Profile updates accept an unvalidated username and use it in a filesystem path for the uploaded file.

Findings come from AI Scan on public synthetic apps. CodeQL alerts were not produced in the baseline CodeQL default-setup scan. Hypotheses above are unverified until reproduced with a test database.

Code Examples

File dest = new File(uploadDir + "/" + username + ".png"); // should be flagged
file.transferTo(dest);

Additional References (Optional)

https://cwe.mitre.org/data/definitions/22.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    enhancement
    CWE-22
    severity:critical
    on Oct 9, 2026
  2. felickz commented on Oct 16, 2026

    @felickz
    Author

    Additional high-severity AI Scan findings matching this gap:

    Repo CWE Severity AI scan alert Summary
    AltoroJ CWE-22 high https://github.com/codeql-forks-felickz/AltoroJ/security/code-scanning/42 The public index page prefixes the attacker-controlled content parameter with static/ and passes it directly to <jsp:include>, without canonicalization or an allowlist.
    JavaVulnerableLab CWE-22 high https://github.com/codeql-forks-felickz/JavaVulnerableLab/security/code-scanning/45 The file parameter is appended to the docs directory and opened without canonical-path validation.
  3. felickz commented on Oct 30, 2026

    @felickz
    Author

    Update: additional findings from a later rescan fit this gap (gap-key java/data-extension/path-injection-username-upload). Forwarded to pull request #62 for the Copilot agent to re-validate.

    Repo CWE Severity AI scan alert Summary
    VulnerableApp CWE-22 high https://github.com/codeql-forks-felickz/VulnerableApp/security/code-scanning/128 Level 8 stores the upload under contentDispositionRoot using the raw original file name supplied by the client. Traversal characters in that
  4. added
    precision:very-high
    on Nov 3, 2026
  5. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:very-high Exact API/type-based fix, no heuristics. github/codeql candidate if the pattern is real-world.

    Candidate for github/codeql. Very high precision with a real-world basis and no material performance or false-positive concerns. No tags:experimental label.

    Linked pull request: #62

    Why. Stock CodeQL models MultipartFile and Part as sources but has no path-injection sink for MultipartFile.transferTo(File|Path) or Part.write(String), which write an upload to a caller-supplied path. Four exact sink rows for public Spring and Servlet APIs, with javax and jakarta variants and passing tests, are a clear model addition used by many upload handlers. Precision is very-high and the real-world basis is general.

    Change Data extension (model) addition
    Target java/path-injection sinks: Spring MultipartFile.transferTo(File|Path) and servlet Part.write(String), javax and jakarta
    Precision assessed very-high. Four sinkModel rows with exact qualified names and signatures for public Spring and Servlet APIs whose argument is the destination path; no heuristics. Tests cover javax, jakarta, Spring File and Path, and Content-Disposition filename cases.
    Real-world basis general. Spring MVC MultipartFile.transferTo(File|Path) and servlet Part.write(String) (javax and jakarta) are standard upload-handling APIs used by many applications; no synthetic identifiers in the model.
    Stock overlap none. java-all 9.3.0 ext models MultipartFile and Part as sources only (grep); github/codeql main has no transferTo or Part.write sink (gh code search and multipart model file).
    Concerns, overlap and next steps

    False-positive concerns

    • Part.write(String) resolves relative names against the configured upload location, so a tainted bare file name is lower impact than an absolute path.

    What an upstream change would look like. Add the four path-injection sinkModel rows to java/ql/lib/ext/jakarta.servlet.http.model.yml, javax.servlet.http.model.yml and org.springframework.web.multipart.model.yml; test under java/ql/test/query-tests/security/CWE-022 with upstream stubs; java/ql/lib/change-notes minorAnalysis note.

    Before opening an upstream pull request

    • Move the rows from the custom pack into the three existing ext model files instead of a new model file.
    • Rebuild the test on the upstream Spring multipart and servlet Part stubs under java/ql/test/stubs and the CWE-022 query test.
    • Add a java/ql/lib/change-notes entry (minorAnalysis).
    • Describe a real upload handler where an unsanitized name reaches transferTo or Part.write in the PR text.

    This is a recommendation only. A human reviews it before any pull request is opened against github/codeql or the Community Packs repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

CWE-22data-extension-createenhancementprecision:very-highseverity:critical

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions