Repository navigation
Conversation
…et Part.write Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
|
@copilot A rescan of the synthetic corpus found additional findings that fit this gap. Please re-run your analysis against them, confirm whether the proposed change covers each scenario, and extend it where it does not.
Please continue on this pull request. |
… upload root (Files.copy) Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
I re-ran the analysis on the VulnerableApp Level 8 finding. It doesn't need new model rows, because stock CodeQL already covers the whole flow. How the code flows:
Each step is already modeled in
I added a cut-down copy of this pattern, My guess is that this is a location mismatch, not a missed finding. CodeQL reports the alert at the The rows this PR adds ( |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the upload-destination sink-model changes.
No open issues 🎉
What changed in this PR
Adds Java CodeQL sink models so java/path-injection detects request-controlled upload destinations passed to Spring and servlet APIs. This addresses issue #35 through missing sinks rather than additional taint summaries.
Changes:
- Introduces a model pack covering both
MultipartFile.transferTooverloads andPart.writein javax and jakarta. - Adds regression fixtures for vulnerable uploads, constant destinations, and sanitized inputs.
- Connects the Java test pack to the models and standard queries, with expected alerts and model provenance.
| File | Description |
|---|---|
languages/java/custom/test/qlpack.yml |
Adds query and model-pack dependencies. |
languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.qlref |
Runs the path-injection query with test postprocessing. |
languages/java/custom/test/PathInjectionUsernameUpload/TaintedPath.expected |
Records expected alerts and model provenance. |
languages/java/custom/test/PathInjectionUsernameUpload/ProfileController.java |
Tests Spring upload paths and safe alternatives. |
languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/multipart/MultipartFile.java |
Stubs multipart APIs, including both transfer overloads. |
languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestParam.java |
Stubs request-parameter annotations. |
languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/web/bind/annotation/RequestMapping.java |
Stubs request-mapping annotations. |
languages/java/custom/test/PathInjectionUsernameUpload/org/springframework/stereotype/Controller.java |
Stubs the controller annotation. |
languages/java/custom/test/PathInjectionUsernameUpload/JavaxServletUpload.java |
Tests javax upload destinations. |
languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/ServletRequest.java |
Stubs javax request-parameter access. |
languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/Part.java |
Stubs javax multipart writes. |
languages/java/custom/test/PathInjectionUsernameUpload/javax/servlet/http/HttpServletRequest.java |
Stubs javax multipart retrieval. |
languages/java/custom/test/PathInjectionUsernameUpload/JakartaServletUpload.java |
Tests jakarta upload destinations. |
languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/ServletRequest.java |
Stubs jakarta request-parameter access. |
languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/Part.java |
Stubs jakarta multipart writes. |
languages/java/custom/test/PathInjectionUsernameUpload/jakarta/servlet/http/HttpServletRequest.java |
Stubs jakarta multipart retrieval. |
languages/java/custom/test/PathInjectionUsernameUpload/ContentDispositionUpload.java |
Tests filename-derived paths through a shared upload helper. |
languages/java/custom/models/qlpack.yml |
Declares the Java model-extension pack. |
languages/java/custom/models/path-injection.model.yml |
Adds four upload-destination sink models. |
Review effort: Balanced
📝 Data Extension Information
languages/java/custom/models/path-injection.model.yml, in the new model packlanguages-java-custom-modelssinkModelorg.springframework.web.multipart,javax.servlet.http,jakarta.servlet.http🎯 Description
What This Data Extension Models
java/path-injectionmisses a requestusernamethat gets concatenated into an upload destination path. The issue suspected a missing summary. That is not the cause.codeql/java-all9.3.2@RequestParam/getParametersourcenew File(String),new File(File,String),Paths.get,Path.resolvetaint stepsMultipartFile.transferTo(File|Path),Part.write(String)sinkThis PR adds the missing sinks only. No summary rows are needed.
languages/java/custom/models/:library: true, withextensionTargets: codeql/java-all. Itsqlpack.ymlmatches the one in [NEW DATA EXTENSION] http4k request sources and response sinks (Java/Kotlin) #7, so expect a trivial conflict if both merge.codeql/java-queriesandlanguages-java-custom-models.languages/java/custom/test/PathInjectionUsernameUpload/: usesTaintedPath.qlrefwith inline expectations and minimal Spring and servlet stubs.Threat Model
remoteExample Vulnerable Code
The test also covers the original app's pattern: an
if (!username.equals(current))branch followed by the upload. Theequalsguard only sanitizes its true branch, so the alert is still reported.Example Safe Code
📦 Extension Details
Extension YAML
Access Path Explanation
Argument[0]is the destination path or file that the uploaded content is written to.subtypes: Truemakes the rows apply to framework implementations such asStandardMultipartFileandCommonsMultipartFile.transferTo(Path)is a default interface method (Spring 5.1+), so it gets its own row.🧪 Testing
codeql database createorcodeql test extract)codeql query run --additional-packs=<model-pack-dir>): not run separately. The test pack resolves the model pack through its${workspace}dependency.codeql test run; the model pack is applied through the test pack dependency rather than--additional-packs)transferToandPart.writealerts are missing without the model and reported with it📋 Checklist
languages/[language]/custom/src/): deviates on purpose. It lives in a separate model pack (languages/java/custom/models/), because thecustom/srcquery pack cannot declareextensionTargets. This matches [NEW DATA EXTENSION] http4k request sources and response sinks (Java/Kotlin) #7.qlpack.ymlincludesdataExtensionsconfigurationPrettyPrintModelsoutput inTaintedPath.expected.🔗 References
java/path-injection(Security/CWE/CWE-022/TaintedPath.ql)Note: This data extension was developed following CodeQL Models as Data best practices.