Skip to content

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

Draft
felickz wants to merge 2 commits into
mainfrom
rust/iron-response-xss
Draft

felickz wants to merge 2 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) 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
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

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