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 and models - githubsecuritylab/rust/iron-response-xss] - detect Rust Iron response XSS and add Iron models - #260
Adds data extension rows for the Iron web framework and githubsecuritylab/rust/iron-response-xss (CWE-79), an experimental Rust query for cross-site scripting through a modifier tuple that is passed to Response::with.
Why
An Iron response is built from modifiers, as in Response::with((status::Ok, body)). A body that is added this way carries no Content-Type unless a modifier sets one, so browsers guess the type from the body and render markup as HTML. The standard rust/xss query cannot see this: Iron has no models, and a sink that sits inside a tuple cannot be written as a model row.
What is added
rust/ext/manual/iron.model.yml:
the request that is passed to a handler registered with Iron::new or Chain::new is a remote source,
the argument of Response::with is an html-injection sink (this covers a body that is passed on its own),
Url::path returns tainted data when the URL is tainted.
The query reports user input that is part of a tuple (or of a variable that holds one) passed to Response::with, unless an element of the tuple is a content type parsed from a string literal that does not name HTML or XML, for example "text/plain".parse::<Mime>().unwrap().
Evidence
One test directory has two tests that share the Iron crate. The query test has 5 alerts (a tuple, a tuple with iron::prelude imports, a tuple that is built first and passed later, an explicit text/html content type, and a body that is built from a parsed literal and so does not set a content type) and 3 safe forms (text/plain, application/json and a constant body). A body that is passed on its own is not a tuple, so the query leaves it to the sink row. The model test lists the 10 remote sources and the 9 sinks that the rows create.
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. None of them depends on Iron, so this shows only that the query is cheap and quiet elsewhere.
Cost: the query's own predicates take about 1.7 seconds on the largest database (about 19,000 Rust files, almost all of them dependency sources).
Known limitations
A content type that another modifier sets, such as Header(ContentType::json()), is not recognized, so the body of such a response is still reported.
A content type is recognized only when it is the value parsed from a string literal (also through unwrap, expect, ? or a local variable), and the type that the literal is parsed into is not checked.
Iron is an old framework (the tests use 0.6.1), so the rows are narrow.
Notes
Metadata: @precision medium, tags security, experimental, external/cwe/cwe-079, external/cwe/cwe-116. The query is selected by rust.qls.
The pack version is not changed here. It changes when a release is cut.
Add source, sink and summary rows for the Iron web framework, and
githubsecuritylab/rust/iron-response-xss (CWE-79), which reports user input in
a modifier tuple that is passed to Response::with when no modifier sets a
content type other than HTML or XML. A body passed to Response::with on its
own is covered by the html-injection sink row.
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
The query can miss unsafe HTML responses because a parsed non-markup literal influencing any tuple field suppresses the entire response without an actual MIME modifier; narrow the suppression and add a regression test.
A string literal that was parsed and then merely formatted into the body
suppressed the whole response, because the suppression used taint tracking
from the literal to any tuple element. Require the tuple element to be the
parsed value itself (the parse call, also through unwrap, expect, ? and local
variables) and add a regression for a body built from a parsed literal.
State in the query help that the parsed type is not checked.
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
The MIME safety check can suppress tainted HTML responses when values are ambiguous, and a standard-query regression is missing for handler-to-body-only sink flow.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Add standard XSS regression for body-only response sink
rust/ext/manual/iron.model.yml:17
CONTRIBUTING.md:139–148 requires data-extension tests to exercise the real standard query, but IronModels.ql only lists source and sink nodes, and the tuple query excludes the body-only case. This leaves taint flow from the Chain::new handler to the body-only sink unverified. Add a regression using the standard Rust XSS query that expects an alert for bad_body_only_handler.
Mixed MIME values can suppress tainted HTML response findings
This suppresses a response when a safe literal is only one possible value of its MIME modifier. For example, let mime: Mime = if condition { "text/plain".parse().unwrap() } else { "text/html".parse().unwrap() }; Response::with((status::Ok, mime, body)) is excluded even when body is tainted and the HTML branch is taken: local value flow includes both branches, and the existential safe-literal check succeeds. Require the modifier to be safe for all reaching values (or conservatively retain the sink when safety is ambiguous), and add a mixed plain-text/HTML 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 data extension rows for the Iron web framework and
githubsecuritylab/rust/iron-response-xss(CWE-79), an experimental Rust query for cross-site scripting through a modifier tuple that is passed toResponse::with.Why
An Iron response is built from modifiers, as in
Response::with((status::Ok, body)). A body that is added this way carries noContent-Typeunless a modifier sets one, so browsers guess the type from the body and render markup as HTML. The standardrust/xssquery cannot see this: Iron has no models, and a sink that sits inside a tuple cannot be written as a model row.What is added
rust/ext/manual/iron.model.yml:Iron::neworChain::newis a remote source,Response::withis anhtml-injectionsink (this covers a body that is passed on its own),Url::pathreturns tainted data when the URL is tainted.Response::with, unless an element of the tuple is a content type parsed from a string literal that does not name HTML or XML, for example"text/plain".parse::<Mime>().unwrap().Evidence
iron::preludeimports, a tuple that is built first and passed later, an explicittext/htmlcontent type, and a body that is built from a parsed literal and so does not set a content type) and 3 safe forms (text/plain,application/jsonand a constant body). A body that is passed on its own is not a tuple, so the query leaves it to the sink row. The model test lists the 10 remote sources and the 9 sinks that the rows create.codeql test run), and the query compiles with--warnings=error.Known limitations
Header(ContentType::json()), is not recognized, so the body of such a response is still reported.unwrap,expect,?or a local variable), and the type that the literal is parsed into is not checked.Notes
@precision medium, tagssecurity,experimental,external/cwe/cwe-079,external/cwe/cwe-116. The query is selected byrust.qls.