Skip to content

[NEW QUERY] Rust: rust/ssrf-reflection-injection (CWE-918) for iron request fields and warp async closures - #144

Draft
felickz with Copilot wants to merge 3 commits into
mainfrom
copilot/rust-query-create-ssrf-reflection-injection
Draft

felickz with Copilot wants to merge 3 commits into
mainfrom
copilot/rust-query-create-ssrf-reflection-injection

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown

📝 Query Information

  • Language: rust
  • Query ID: rust/ssrf-reflection-injection
  • Category: security
  • Severity: error (@security-severity 9.1, @precision high)
  • CWE/CVE (if applicable): CWE-918

🎯 Description

AI Scan reported two SSRF findings that default setup missed. The issue assumed Rust has no SSRF query, but it does: stock rust/request-forgery. I reproduced both misses against a test DB built with the real iron, warp, reqwest and tokio crates (via options.yml qltest_dependencies). The sinks were already modeled, so both misses are source or flow gaps:

Finding Root cause in stock query
iron, reqwest::blocking::get(req.url.to_string()) Iron::new (from the iron::prelude::* glob) is unresolved, so the handler is never a remote source. req and the req.url field do resolve.
warp, path::param().then(|p| async move { client.post(format!("https://{}", p)) }) The closure parameter is already a MaD source and Client::post is a sink. Taint is lost when p is captured by the async move block.

What This Query Detects

This query uses the stock RequestForgery sources, sinks and barriers, and adds:

  • IronRequestFieldSource: reads of url / headers / body on iron::request::Request. It matches on the field, not on Iron::new, so Handler impls are covered too.
  • Async capture flow step: from a variable's pattern to its reads inside an async block that captures it.
  • FixedHostFormatBarrier: a format! whose template starts with a fixed scheme://host followed by /, ? or #. Without it, both safe test cases alert.

Supporting changes:

  • New languages/rust/custom/{src,test} packs (Rust had no packs here).
  • languages/rust/custom/test/.gitignore for the files the extractor generates (Cargo.toml, Cargo.lock, lib.rs, target/).
  • rust added to the language list in scripts/install-codeql-packs.sh.

Example Vulnerable Code

Iron::new(|req: &mut Request| {
    let request_url = req.url.to_string();
    let data = reqwest::blocking::get(request_url) // alert
    ...
});

warp::path::param().then(|tainted_param: String| async move {
    reqwest::Client::new().post(format!("https://{}", tainted_param)) // alert
    ...
});

Example Safe Code

let path = format!("http://my.app/{request_url}");
reqwest::blocking::get(path); // fixed host, no alert

reqwest::Client::new().post(format!("https://my.app/{}", tainted_param)); // fixed host, no alert

🧪 Testing

  • Positive test cases included
  • Negative test cases included
  • Edge cases covered
  • All tests pass

The test downloads crates from crates.io, so extraction needs network access and takes about 3 minutes. CI does not run custom/ tests: the unit-test workflow only covers languages/*/tools/.

📋 Checklist

  • Query compiles without errors
  • Documentation complete (.md and .qhelp): only .md is included
  • Metadata properly set (@name, @id, @kind, etc.)
  • Tests validate query behavior
  • No false positives in test cases

🔗 References


Note: This query was developed using Test-Driven Development methodology.

…ssion tests

Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Copilot AI changed the title [WIP] Add query for SSRF reflection injection in Rust [NEW QUERY] Rust: rust/ssrf-reflection-injection (CWE-918) for iron request fields and warp async closures Oct 16, 2026
Copilot AI requested a review from felickz October 16, 2026 16:05
@felickz
felickz requested a balanced review from Copilot October 30, 2026 18:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Nested format templates can incorrectly suppress genuine SSRF findings, while async capture edges bypass intervening assignments and produce false positives.

2 open issues
What changed in this PR

Adds rust/ssrf-reflection-injection to address the Iron request-field and Warp async-capture coverage gaps identified in #140, extending the existing Rust request-forgery models.

Changes:

  • Adds Iron sources, async capture flow, and a fixed-host formatting barrier.
  • Adds positive and negative fixtures using real Rust framework dependencies.
  • Introduces Rust custom packs, query documentation, and installer support.
File Description
scripts/​install-codeql-packs.sh Accepts Rust as a language filter.
languages/​rust/​custom/​test/​SsrfReflectionInjection/​warp_app.rs Tests vulnerable and fixed-host Warp requests.
languages/​rust/​custom/​test/​SsrfReflectionInjection/​SsrfReflectionInjection.qlref Connects fixtures to the query and inline expectations.
languages/​rust/​custom/​test/​SsrfReflectionInjection/​SsrfReflectionInjection.expected Records expected alerts and flow paths.
languages/​rust/​custom/​test/​SsrfReflectionInjection/​options.yml Configures extraction with real crate dependencies.
languages/​rust/​custom/​test/​SsrfReflectionInjection/​iron_app.rs Tests vulnerable and fixed-host Iron requests.
languages/​rust/​custom/​test/​qlpack.yml Defines the Rust custom test pack.
languages/​rust/​custom/​test/​.gitignore Ignores extractor-generated Cargo artifacts.
languages/​rust/​custom/​src/​SsrfReflectionInjection/​SsrfReflectionInjection.ql Implements extended SSRF detection.
languages/​rust/​custom/​src/​SsrfReflectionInjection/​SsrfReflectionInjection.md Documents coverage, recommendations, and examples.
languages/​rust/​custom/​src/​qlpack.yml Defines the Rust custom query pack.

Review effort: Balanced

Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Query Create]: CWE-918 HIGH - Rust: new query for ssrf reflection injection

3 participants