Skip to content

[Query Fix - githubsecuritylab/rust/iron-response-xss] - find Iron response XSS when the prelude calls have no target - #264

Merged
felickz merged 2 commits into
mainfrom
rust/iron-response-xss-unresolved-prelude
Nov 26, 2026
Merged

felickz merged 2 commits into
mainfrom
rust/iron-response-xss-unresolved-prelude

Conversation

@felickz

@felickz felickz commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: b88b9f6313e9327836dc0b6fe8dbf182d5dc1098

Dimension Assessment Rationale
Change confidence 8/10 ↑ The test directory passes with the pinned CLI (4 tests, 19 alerts), and no row of the existing fixture's expected files is removed or changed compared with main.
↑ Mutations of the file guard, the method step, the one path clause, the field guard, the HTML encoder match and the sink for a resolved body on its own each changed the result as intended.
↑ The previous commit of this branch passed all 31 CI checks. Copilot's two findings on it (an encoder match by substring that hid the taint of escape_default, and a missed body on its own in a handler that nothing registers) are fixed here and pinned by fixtures.
↑ On the database that a default setup run built (no build) from a public Iron sample, the unchanged query reports 0 alerts and this one 3, including the intended one. The sample that sanitizes the body reports none.
↑ measure on two local Rust databases (the larger has about 19,000 files): cost class low, own predicates 0.08 s and 0.50 s, 0 alerts.
↓ The fallback goes by names and no local corpus uses Iron, so its precision on real programs is untested beyond that one sample.
↓ CI for this commit and a Copilot re-review are pending.
Diagnosis confidence 9/10 ↑ The calls through the prelude glob have no target in that database (listed with getStaticTarget()), the query and the data extension rows match resolved targets only, and the same query with the fallback finds the alert there.
↓ Why the extraction leaves them unresolved is not determined. The fix does not depend on it.
Evidence fit 8.5/10 ↑ The missed alert has the shape that the fallback finds on that database: the request path formatted into markup and returned through Response::with.
↓ Not confirmed in a live scan, which needs a release that carries this change and a new scan.

Summary

githubsecuritylab/rust/iron-response-xss found nothing in code that uses Iron through a glob import of its prelude (use iron::prelude::*;), which is how Iron programs usually import it. This adds a fallback that recognizes the API by its names when the calls have no target, in files that use iron, with tests for it.

Why

A database that is built without compiling the code (code scanning default setup uses buildMode: none) leaves the calls that go through names from the prelude glob without a target: Iron::new, .http, Response::with and the methods of the request. The Iron data extension rows and the query's sink for Response::with match canonical paths, so none of them applies. The tests did not show it, because the fixture of the query also imports the same names explicitly, and that makes them resolve.

Reproduction (CLI 2.27.5, iron = "0.6.1", --build-mode none, calls listed with getStaticTarget().getCanonicalPath()):

use iron::prelude::*;
use iron::status;

fn handler(req: &mut Request) -> IronResult<Response> {
    let res = req.url.path();
    let response = format!("<h1>{:?}</h1>", res);
    Ok(Response::with((status::Ok, response)))
}

pub fn main() {
    Iron::new(handler).http("localhost:3000").unwrap();
}
Imports Iron calls (Iron::new, .http, Response::with, .path())
use iron::prelude::*; at the crate root, or inside a module when nothing else imports the names no target
use iron::prelude::{IronResult, Request, Response}; no target
use iron::{Iron, IronResult, Request, Response}; all resolve
the explicit import at the crate root and the glob inside a module all resolve

The cause is not determined. The iron crate is edition 2015, which may be relevant.

What is changed

  • rust/src/common/IronFallback.qll (new): isIronFile (a use whose first segment is iron, or extern crate iron), IronRequestParameter, ironUnresolvedStep and isUnresolvedIronResponseWith.
  • rust/src/security/CWE-079/IronResponseXss.ql uses them. In files that use iron, for calls that have no target:
    • a parameter of type Request, &Request or &mut Request is a source,
    • the url, headers, body and extensions fields of a request that do not resolve to a field, and the result of a method call that has no target, carry the data on (except methods that only tell a property, such as len, and names that say that they escape or encode for HTML, such as escape_html, which are taken to do so),
    • a call of Response::with that has no target is a sink for the elements of a modifier tuple, and for a body that is passed on its own, as the data extension row does for a call that resolves.
  • Also in IronResponseXss.ql:
    • a body on its own that goes to a call of Response::with that resolves is a sink too, for the handlers that no registered source reaches (one that a router registers, for example). The standard query reports the registered ones, so this query leaves them to it,
    • a handler that the modelled source already reaches is reported through that source, not twice.
  • IronResponseXss.qhelp describes the fallback and its limits.
  • One test directory (the existing one) gains:
    • glob_prelude.rs: a file that has only the glob import, with 8 alerts (a tuple, a body on its own, a tuple that is built first, a nested tuple, the query string, a value that goes through another method, a value that goes through escape_default, which keeps markup, and a closure handler) and 6 safe forms (a constant body, the length only, text/plain, a method that says that it escapes for HTML, a sanitizer call, a parameter that is not a request),
    • GlobCalls.ql: lists the calls of that file that have no target, so that the test changes if the extraction ever resolves them and the file stops exercising the fallback,
    • other_framework.rs: the same names from another framework, with no use of iron, which must not alert,
    • two handlers in main.rs that nothing registers (a tuple, and a body on its own to a call that resolves), which now alert (and add two rows to the model test).

Evidence

  • codeql test run passes with the pinned CLI (4 tests, 19 alerts). Compared with main, no row of the existing fixture's expected files is removed or changed: the 9 alerts and the model rows stay, and the two handlers that nothing registers add 2 alerts and 2 model rows. With the unchanged query the glob-only file has no alert.
  • The query compiles with --warnings=error and the format check passes.
  • Mutations, each reverted. Older ones: with the file guard true everywhere the other framework's file alerts, without the method step the glob-only alerts go, without the one path clause the handlers that the data extension rows reach are reported twice, and without the guard for resolved fields the path edges of the existing alerts change. After the review: with the old substring match for encoders (escape, encode anywhere in a name) the escape_default alert goes (18 instead of 19), without the sink for a resolved body on its own the alert of the unregistered body-only handler goes (18), and without the clause that leaves registered handlers to the standard query the registered body-only handler is reported twice (20).
  • On the database that a code scanning default setup run built (no build) from a public sample project that uses Iron through the prelude glob, the unchanged query reports 0 alerts and this one reports 3: the request path formatted into markup and returned, and two where the body is the text of the response to an outbound reqwest request, a remote source of the standard query. The sample that sanitizes the body with ammonia::clean reports none (clean resolves there, and no taint comes out of it).
  • On two local databases of public Rust projects (the larger one has about 19,000 Rust files, almost all of them dependency sources) the query reports 0 alerts, as before. No file in either uses iron, although they hold 134,270 and 28,376 calls that have no target, and the file guard keeps the fallback away from all of them. So this shows that the change is cheap and quiet elsewhere, not how precise it is on Iron programs.
  • Cost (measure, idle machine): the whole run takes 9 s and 21 s on the two databases, the query's own predicates 0.08 s and 0.50 s (the largest one 0.43 s), no cartesian product, cost class low.

Known limitations

  • The fallback goes by names. A type called Request of another crate in a file that uses iron is a source, and every method of the request that has no target passes its receiver on, so a method that encodes the value is recognized only when its name says that it escapes or encodes for HTML (escape_html, html_escape), and one that does it under another name, or only partly (escape_default keeps markup), is not.
  • A sanitizer that is a function call is not a step of the fallback. A function that resolves is followed by the standard analysis.
  • The query help lists them next to the earlier limitations of the modifier tuple.

Notes

  • No pack version changes. The pull request changes files that are not queries, so CI runs all of the Rust tests for it, which takes a while.
  • @precision medium and the tags are unchanged. The query stays in the default Rust suite.

A database that is built without compiling the code leaves every call that goes
through a glob import of the iron prelude without a target. The Iron data
extension rows and the sink that matches the canonical path of Response::with
then do not apply, and githubsecuritylab/rust/iron-response-xss found nothing
in code that starts with use iron::prelude::*.

Recognize the API by its names for those calls, in files that use iron: a
function or closure with a Request parameter is a source, the fields of the
request and the method calls that have no target pass the data on, and a call of
Response::with that has no target is a sink (a body on its own as well). A
handler that the modelled source already reaches is reported once.

Add a test file that has only the glob import, a test that lists its calls that
have no target, a file with the same names from another framework that must not
alert, and negative cases (constant body, length only, text/plain, encoded,
sanitized, a parameter that is not a request).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752

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

Critical XSS false negatives remain because the fallback treats non-HTML escaping methods as safe and misses resolved body-only response sinks in unregistered handlers.

2 open issues
What changed in this PR

This PR extends the Rust Iron response XSS query to detect unsafe responses when prelude imports leave API calls unresolved, while preserving existing resolved-call detection.

Changes:

  • Adds name-based fallback sources, flow steps, and response sinks for files using Iron.
  • Adds regression fixtures for unresolved calls, safe responses, other frameworks, and unregistered handlers.
  • Documents fallback behavior and limitations.
File Description
rust/​test/​security/​CWE-079/​IronResponseXss/​other_framework.rs Checks that similarly named non-Iron APIs are excluded.
rust/​test/​security/​CWE-079/​IronResponseXss/​main.rs Adds an unregistered-handler fixture.
rust/​test/​security/​CWE-079/​IronResponseXss/​IronResponseXss.expected Records additional alerts and flow paths.
rust/​test/​security/​CWE-079/​IronResponseXss/​IronModels.expected Adds the new handler’s modeled sink.
rust/​test/​security/​CWE-079/​IronResponseXss/​GlobCalls.ql Checks that the glob-import fixture retains unresolved calls.
rust/​test/​security/​CWE-079/​IronResponseXss/​GlobCalls.expected Records expected unresolved calls.
rust/​test/​security/​CWE-079/​IronResponseXss/​glob_prelude.rs Adds fallback detection and exclusion fixtures.
rust/​src/​security/​CWE-079/​IronResponseXss.ql Integrates fallback analysis and suppresses overlapping source reports.
rust/​src/​security/​CWE-079/​IronResponseXss.qhelp Describes fallback coverage and limitations.
rust/​src/​common/​IronFallback.qll Defines name-based Iron recognition and flow predicates.

Review effort: Balanced

Comment thread rust/src/common/IronFallback.qll Resolved
…ody-only handlers

Two review findings on the fallback.

A method whose name only contains escape or encode was taken to encode for HTML,
which hid the taint of escape_default (it keeps markup) and of unescape_html.
Only names that say HTML (escape_html, html_escape, encode_html) are taken to
encode now. escape_default is an alert in the glob-only fixture, and a method
that says escape_html is the safe form.

A body that is passed on its own to a call of Response::with that resolves was
reported only through the data extension sink, which needs a handler that
Iron::new or Chain::new registers. A handler that nothing registers has no
modelled source, so the flow was missed. Add the sink for the flows from the
request parameter, and leave the flows of modelled sources to the standard
query. Add the regression in main.rs.

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

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

A critical filtering flaw can suppress both queries’ results for a vulnerability when a flow passes through an unresolved intermediate method; suppression must depend on actual standard-analysis reachability and be covered by a regression test.

1 open issue
2 resolved since last review

Review effort: Balanced

Comment on lines +207 to +208
sinkNode.getNode() instanceof IronResolvedResponseBody and
sourceNode.getNode() instanceof Xss::Source
@felickz
felickz added this pull request to stack #268 November 25, 2026 19:21
@felickz
felickz marked this pull request as ready for review November 26, 2026 06:19
@felickz
felickz merged commit fc99006 into main Nov 26, 2026
32 checks passed
@felickz
felickz deleted the rust/iron-response-xss-unresolved-prelude branch November 26, 2026 06:19
felickz added a commit that referenced this pull request Nov 26, 2026
…sponse XSS when the prelude calls have no target (#264)

* Rust: find Iron response XSS when the prelude calls have no target

A database that is built without compiling the code leaves every call that goes
through a glob import of the iron prelude without a target. The Iron data
extension rows and the sink that matches the canonical path of Response::with
then do not apply, and githubsecuritylab/rust/iron-response-xss found nothing
in code that starts with use iron::prelude::*.

Recognize the API by its names for those calls, in files that use iron: a
function or closure with a Request parameter is a source, the fields of the
request and the method calls that have no target pass the data on, and a call of
Response::with that has no target is a sink (a body on its own as well). A
handler that the modelled source already reaches is reported once.

Add a test file that has only the glob import, a test that lists its calls that
have no target, a file with the same names from another framework that must not
alert, and negative cases (constant body, length only, text/plain, encoded,
sanitized, a parameter that is not a request).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752

* Rust: restrict the Iron fallback encoder match, report unregistered body-only handlers

Two review findings on the fallback.

A method whose name only contains escape or encode was taken to encode for HTML,
which hid the taint of escape_default (it keeps markup) and of unescape_html.
Only names that say HTML (escape_html, html_escape, encode_html) are taken to
encode now. escape_default is an alert in the glob-only fixture, and a method
that says escape_html is the safe form.

A body that is passed on its own to a call of Response::with that resolves was
reported only through the data extension sink, which needs a handler that
Iron::new or Chain::new registers. A handler that nothing registers has no
modelled source, so the flow was missed. Add the sink for the flows from the
request parameter, and leave the flows of modelled sources to the standard
query. Add the regression in main.rs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
felickz added a commit that referenced this pull request Nov 26, 2026
… that pass a call that has no target (#267)

* [Query Fix - githubsecuritylab/rust/iron-response-xss] - find Iron response XSS when the prelude calls have no target (#264)

* Rust: find Iron response XSS when the prelude calls have no target

A database that is built without compiling the code leaves every call that goes
through a glob import of the iron prelude without a target. The Iron data
extension rows and the sink that matches the canonical path of Response::with
then do not apply, and githubsecuritylab/rust/iron-response-xss found nothing
in code that starts with use iron::prelude::*.

Recognize the API by its names for those calls, in files that use iron: a
function or closure with a Request parameter is a source, the fields of the
request and the method calls that have no target pass the data on, and a call of
Response::with that has no target is a sink (a body on its own as well). A
handler that the modelled source already reaches is reported once.

Add a test file that has only the glob import, a test that lists its calls that
have no target, a file with the same names from another framework that must not
alert, and negative cases (constant body, length only, text/plain, encoded,
sanitized, a parameter that is not a request).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752

* Rust: restrict the Iron fallback encoder match, report unregistered body-only handlers

Two review findings on the fallback.

A method whose name only contains escape or encode was taken to encode for HTML,
which hid the taint of escape_default (it keeps markup) and of unescape_html.
Only names that say HTML (escape_html, html_escape, encode_html) are taken to
encode now. escape_default is an alert in the glob-only fixture, and a method
that says escape_html is the safe form.

A body that is passed on its own to a call of Response::with that resolves was
reported only through the data extension sink, which needs a handler that
Iron::new or Chain::new registers. A handler that nothing registers has no
modelled source, so the flow was missed. Add the sink for the flows from the
request parameter, and leave the flows of modelled sources to the standard
query. Add the regression in main.rs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752

* Rust: report Iron XSS flows that pass a call that has no target

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Copilot-Session: 4124a708-0b20-41df-a2e2-c945fbf86752
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