Skip to content

[New Query and models - githubsecuritylab/rust/iron-response-xss] - detect Rust Iron response XSS and add Iron models - #260

Merged
felickz merged 5 commits into
mainfrom
rust/iron-response-xss
Nov 23, 2026
Merged

felickz merged 5 commits into
mainfrom
rust/iron-response-xss

Conversation

@felickz

@felickz felickz commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

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 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, or of a tuple that is nested in it) passed to Response::with, unless a modifier of the response is a content type parsed from a string literal that does not name HTML or XML, for example "text/plain".parse::<Mime>().unwrap(), and none is parsed from a literal that does.

Evidence

  • One test directory has three tests that share the Iron crate. The query test has 9 alerts (a tuple, a tuple with iron::prelude imports, a tuple that is built first and passed later, an explicit text/html content type, a body that is built from a parsed literal and so does not set a content type, a content type that is plain text on one branch and HTML on the other, a body in a nested tuple (written in place, or built first), and a text/html modifier after a text/plain one) and 4 safe forms (text/plain, application/json, a constant body and a text/plain modifier in a nested tuple). A body that is passed on its own is not a tuple, so the query leaves it to the sink row. A body that is assigned to a tuple field after the tuple is built is a known limitation, and its fixture has no alert. The model test lists the 16 remote sources and the 15 sinks that the rows create. A third test runs the standard rust/xss query with the data extension rows and has 1 alert: the body that is passed on its own, from a handler that is registered with Chain::new.
  • 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 second 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.
  • When several parsed literals can reach the content types of a response (for example one on each branch of an if, or one in each of two modifiers), the response is treated as safe only if none of them names HTML or XML: the query does not tell which of two content types is applied last. A value that does not come from a parsed literal is not considered.
  • The sinks are the expressions that a modifier tuple is built from, so a tuple that is changed after it is built (for example modifiers.1 = body;) is not tracked.
  • 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 Rust test pack now depends on codeql/rust-queries 0.1.47 (the version that the pinned CLI bundles), as the test packs of the other languages depend on their standard query pack, so that the data extension rows can be tested with the standard rust/xss query. The test lock file lists it and codeql/suite-helpers.
  • 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
Copilot AI balanced review requested due to automatic review settings November 22, 2026 03:02

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

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.

1 open issue
What changed in this PR

Adds experimental cross-site scripting detection for Iron response modifier tuples, extending the Rust query pack with Iron framework models.

Changes:

  • Adds a tuple-specific XSS query with suppression for recognized non-markup content types.
  • Models handler requests as remote sources, direct response arguments as sinks, and URL-path taint propagation.
  • Adds regression fixtures, expected results, query help, and safe/unsafe examples.
File Description
rust/​test/​security/​CWE-079/​IronResponseXss/​options.yml Declares the Iron test dependency.
rust/​test/​security/​CWE-079/​IronResponseXss/​main.rs Adds vulnerable and safe response fixtures.
rust/​test/​security/​CWE-079/​IronResponseXss/​IronResponseXss.qlref Links fixtures to the new query.
rust/​test/​security/​CWE-079/​IronResponseXss/​IronResponseXss.expected Records four expected alerts and flow paths.
rust/​test/​security/​CWE-079/​IronResponseXss/​IronModels.ql Checks modeled sources and sinks.
rust/​test/​security/​CWE-079/​IronResponseXss/​IronModels.expected Records expected source and sink matches.
rust/​test/​security/​CWE-079/​IronResponseXss/​Cargo.lock Pins test dependencies.
rust/​src/​security/​CWE-079/​IronResponseXssGood.rs Demonstrates an explicit plain-text response.
rust/​src/​security/​CWE-079/​IronResponseXssBad.rs Demonstrates an unsafe response without a content type.
rust/​src/​security/​CWE-079/​IronResponseXss.ql Implements tuple-specific XSS detection.
rust/​src/​security/​CWE-079/​IronResponseXss.qhelp Documents behavior, remediation, and limitations.
rust/​ext/​manual/​iron.model.yml Adds Iron source, sink, and taint-summary models.

Review effort: Balanced

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
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

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

Medium severity 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.

Medium severity Mixed MIME values can suppress tainted HTML response findings

rust/​src/​security/​CWE-079/​IronResponseXss.ql:84

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.

1 resolved since last review

Review effort: Balanced

…th the rows

A content type that several parsed literals can reach, for example one on each
branch of an if, was treated as safe when any of them was not markup. It is
now safe only when a parsed literal reaches it and none of them names HTML or
XML. Add a regression for a plain text and HTML mix.

Add the standard rust/xss query as a test of the data extension rows, as the
test packs of the other languages do: the Rust test pack depends on
codeql/rust-queries 0.1.47 (the version that the pinned CLI bundles) and the
lock file lists it and codeql/suite-helpers. The new test has one alert, the
body that is passed on its own to Response::with.

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 23, 2026 15:23
@felickz

felickz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the second pass. Both findings in the review body were valid, and both are fixed in d09c1a7.

  • Mixed content types: bad_mixed_mime_handler (plain text on one branch of an if, HTML on the other) was not reported. A content type is now safe only when a parsed literal reaches it and none of the parsed literals that reach it names HTML or XML. The query help and the pull request body say that a value that does not come from a parsed literal is still not considered.
  • Standard query regression: agreed, and it follows the pattern of the other languages. The Rust test pack now depends on codeql/rust-queries 0.1.47 (the version that the pinned CLI bundles), and XSS.qlref runs the standard rust/xss query on the Iron fixtures. It has one alert: the handler that is registered with Chain::new, through Url::path and format!, into the body-only Response::with sink. The test lock file lists the two packs that the dependency adds (codeql/rust-queries and codeql/suite-helpers).

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

The query misses potential XSS sinks when a later HTML MIME modifier overrides a safe type or when response bodies appear in nested modifier tuples.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Nested modifier tuples are not traversed for response sinks

rust/​src/​security/​CWE-079/​IronResponseXss.ql:96

Only immediate tuple fields become sinks, so a nested modifier tuple such as Response::with((status::Ok, (status::Ok, body))) is missed even when body contains request data. Modifier tuples compose recursively, but the sink here is the inner tuple as a whole; tuple-field taint is not implicitly read by this configuration (the same reason the model row cannot cover the outer tuple). Traverse nested modifier tuples to their leaf elements, preserving content-type handling for the complete response, and add a nested-tuple regression.

Medium severity Safe MIME modifier can suppress a markup response sink

rust/​src/​security/​CWE-079/​IronResponseXss.ql:100

A safe MIME modifier suppresses the response even when a later modifier replaces it with HTML. For example, with plain parsed from "text/plain" and html from "text/html", Response::with((status::Ok, plain, html, body)) is served as HTML, but this existential check removes every sink. Account for modifier order, or conservatively retain the sink whenever another MIME modifier can select markup, and add a regression with both modifiers in the same tuple.

Review effort: Balanced

…nt type

Only the immediate elements of the modifier tuple were sinks, so a body in a
nested tuple was missed. A content type that is parsed from a safe literal
removed the sinks of the whole tuple, even when another modifier of the same
response is parsed from an HTML literal and is applied after it.

Use the leaf elements of the tuple and of the tuples that are nested in it
as the sinks, and judge the content type of the whole response: it is safe
only when a modifier is parsed from a literal that is not markup and no
modifier is parsed from one that is.

Add regressions for a body in a nested tuple (written in place, or built
first), a text/html modifier after a text/plain one, and a text/plain
modifier in a nested tuple.

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 23, 2026 17:25
@felickz

felickz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the third pass. Both findings in the review body were valid and are fixed in 9d1e023, each with a failing test first.

  • Nested tuples: Response::with((status::Ok, (status::Ok, response))) was not reported (bad_nested_tuple_handler). The sinks are now the leaf elements of the tuple and of every tuple that is nested in it (directly, or through a local variable as in bad_nested_named_tuple_handler), and the content type is judged for the whole response.
  • Modifier order: Response::with((status::Ok, plain, html, response)) was not reported (bad_overriding_mime_handler), because the safe modifier removed every sink of the tuple. A response is now safe only when a modifier is parsed from a literal that is not markup and no modifier of the response is parsed from one that is. I took the conservative option instead of modelling the order, so (html, plain), which Iron serves as plain text, is reported too. The query help and the pull request body say so. good_nested_plain_text_handler (the text/plain modifier is in the inner tuple) still has no alert.

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

The tuple-body sink tracks constructor expressions rather than field contents at Response::with, missing tainted bodies assigned later and requiring call-site tracking with regression coverage.

1 open issue

Review effort: Balanced

The sinks of the query are the expressions that a modifier tuple is built
from, so a body that is assigned to a tuple field after the tuple is built
(modifiers.1 = body) is not a sink. Tracking the field contents at the call
would need a different sink model that also changes where alerts are
reported, for a pattern that Iron code rarely uses, so say so in the query
help and pin it with a fixture.

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 23, 2026 18:21

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.

🟢 Approval recommended

The experimental Iron XSS detection changes have no active review issues.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@felickz
felickz marked this pull request as ready for review November 23, 2026 22:29
@felickz
felickz merged commit 92d109c into main Nov 23, 2026
31 checks passed
@felickz
felickz deleted the rust/iron-response-xss branch November 23, 2026 22:29
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