Skip to content

[New Query - githubsecuritylab/rust/ssrf-reflection-injection] - detect Rust request forgery through Iron handlers and async closures - #258

Draft
felickz wants to merge 2 commits into
mainfrom
rust/ssrf-reflection-injection
Draft

felickz wants to merge 2 commits into
mainfrom
rust/ssrf-reflection-injection

Conversation

@felickz

@felickz felickz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds githubsecuritylab/rust/ssrf-reflection-injection (CWE-918), an experimental Rust query that extends the standard rust/request-forgery query for Iron handlers, async closures and fixed-host URL templates.

Why

The standard query misses three patterns:

  • In an Iron handler the url, headers and body of the request are attacker controlled (the authority of req.url comes from the Host header), but they are not sources in the standard library.
  • A closure parameter that an async move block captures is not followed into the block, as in a warp Filter::then closure.
  • A URL built with format!("https://my.app/{}", user) is reported, although the host is fixed.

What is reported

The sources, sinks and barriers of rust/request-forgery (through RequestForgeryExtensions, so models for other crates apply to both queries), plus the three additions above: Iron request field sources, a barrier for format! templates that start with a fixed scheme and host, and a flow step for variables that an async block captures.

Evidence

  • Tests use real crates (iron, reqwest, tokio, warp). They cover an Iron request field and a warp path parameter, templates with a fixed host that are nested in a template that must still be reported (format! and std::format!), a value that is derived from the parameter before the async block is created, and five safe forms (including a fixed URL that is assigned before, or inside, the async block). They pass with the pinned CLI (codeql test run), and the query compiles with --warnings=error.
  • On a random sample of 11 public Rust repositories (1,521 source files, plus the crates they depend on) the query reports 0 alerts, so there is no true positive from real code yet.
  • Cost: the query's own predicates take about 1 second on the largest database (about 19,000 Rust files, almost all of them dependency sources). A whole run takes about 1 minute on the smaller database and about 8 minutes on the larger one, almost all of it the shared library.

Known limitations

  • The format! barrier is a text check on the template. A host that is built by concatenation, push_str or Url::join is not recognized as fixed (a path-only control is still reported).
  • The three additions are query local. The barrier and the async flow step could move into the standard library later, which would remove the overlap with the standard query.
  • A flow that both queries report is reported twice when both run.

Notes

  • Metadata: @precision medium, tags security, experimental, external/cwe/cwe-918. The query is selected by rust.qls.
  • The pack version is not changed here. It changes when a release is cut.

…osures

Add githubsecuritylab/rust/ssrf-reflection-injection (CWE-918). It uses the
sources, sinks and barriers of the standard rust/request-forgery query and adds
three things: reads of the url, headers and body of an inbound Iron request as
sources, a barrier for format! templates that start with a fixed scheme and
host, and a flow step for variables that an async block captures, as in a warp
Filter::then closure.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active findings identify a false positive from ignoring an overwrite before async capture and a missed attacker-controlled-host flow caused by qualified nested format macros, both requiring fixes and regression tests.

2 open issues
What changed in this PR

Adds an experimental CWE-918 query to the Rust security pack, extending standard request-forgery analysis for Iron handlers and variables captured by async blocks.

Changes:

  • Models Iron request fields as sources and adds async capture flow tracking.
  • Adds a fixed-host format! barrier to reduce false positives.
  • Includes query documentation and real-crate regression fixtures with expected results.
File Description
rust/​test/​security/​CWE-918/​SsrfReflectionInjection/​warp_app.rs Tests async captures, nested templates, and safe URL construction.
rust/​test/​security/​CWE-918/​SsrfReflectionInjection/​SsrfReflectionInjection.qlref Connects the fixtures to the new query.
rust/​test/​security/​CWE-918/​SsrfReflectionInjection/​SsrfReflectionInjection.expected Records expected alerts and flow paths.
rust/​test/​security/​CWE-918/​SsrfReflectionInjection/​options.yml Enables Cargo checking and declares test dependencies.
rust/​test/​security/​CWE-918/​SsrfReflectionInjection/​iron_app.rs Tests Iron request URL sources and fixed-host construction.
rust/​test/​security/​CWE-918/​SsrfReflectionInjection/​Cargo.lock Locks fixture dependencies for reproducibility.
rust/​src/​security/​CWE-918/​SsrfReflectionInjection.ql Implements the extended request-forgery query.
rust/​src/​security/​CWE-918/​SsrfReflectionInjection.md Documents coverage, recommendations, and examples.

Review effort: Balanced

…ated

Start the async capture step from the value that a variable has when the
async block is created: the pattern that declares it, or the right-hand side
of an assignment that is not overwritten before the block. A fixed URL that
is assigned before the block no longer reports, and a value that is derived
from the parameter before the block still does.

Add regressions for an overwrite before the capture, a derived value before
the capture, and a nested std::format! template.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Active findings show that nested formatting can hide an attacker-controlled host from SSRF detection, while cross-scope capture handling can report safe requests after tainted parameters are overwritten.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Nested format_args! can hide an attacker-controlled host

rust/​src/​security/​CWE-918/​SsrfReflectionInjection.ql:64

format!("https://{}/{}", tainted_param, format_args!("https://my.app/{}", "constant")) is treated as a barrier because the descendant search accepts the inner fixed-host template. This suppresses a request-forgery flow through the outer, attacker-controlled host. Select only the outermost FormatArgsExpr belonging to each format! call, and add this nested format_args! regression.

Medium severity Closure fallback ignores reassignment before capture

rust/​src/​security/​CWE-918/​SsrfReflectionInjection.ql:140

The cross-scope fallback still bypasses assignments before capture. For example, a then handler that overwrites its tainted parameter with a constant URL and then creates let f = move || async move { reqwest::get(tainted_param).await }; f() gets an edge directly from the original parameter pattern to the sink read, reporting the safe request. Resolve the value reaching the intervening closure's capture site rather than unconditionally using the declaring pattern, and add a nested-closure overwrite regression.

2 resolved since last review

Review effort: Balanced

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.

2 participants