You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[New Query - githubsecuritylab/rust/ssrf-reflection-injection] - detect Rust request forgery through Iron handlers and async closures - #258
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
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.
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.
…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
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
Nested format_args! can hide an attacker-controlled host
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.
Closure fallback ignores reassignment before capture
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
githubsecuritylab/rust/ssrf-reflection-injection(CWE-918), an experimental Rust query that extends the standardrust/request-forgeryquery for Iron handlers,asyncclosures and fixed-host URL templates.Why
The standard query misses three patterns:
url,headersandbodyof the request are attacker controlled (the authority ofreq.urlcomes from theHostheader), but they are not sources in the standard library.async moveblock captures is not followed into the block, as in a warpFilter::thenclosure.format!("https://my.app/{}", user)is reported, although the host is fixed.What is reported
The sources, sinks and barriers of
rust/request-forgery(throughRequestForgeryExtensions, so models for other crates apply to both queries), plus the three additions above: Iron request field sources, a barrier forformat!templates that start with a fixed scheme and host, and a flow step for variables that anasyncblock captures.Evidence
format!andstd::format!), a value that is derived from the parameter before theasyncblock is created, and five safe forms (including a fixed URL that is assigned before, or inside, theasyncblock). They pass with the pinned CLI (codeql test run), and the query compiles with--warnings=error.Known limitations
format!barrier is a text check on the template. A host that is built by concatenation,push_strorUrl::joinis not recognized as fixed (a path-only control is still reported).asyncflow step could move into the standard library later, which would remove the overlap with the standard query.Notes
@precision medium, tagssecurity,experimental,external/cwe/cwe-918. The query is selected byrust.qls.