From eb7dc547d90c569f900bf5db14895b16bea915b0 Mon Sep 17 00:00:00 2001
From: Chad Bentz <1760475+felickz@users.noreply.github.com>
Date: Thu, 26 Nov 2026 01:19:24 -0500
Subject: [PATCH 1/2] [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
From 4cec067829756873f5ea014314e4c19fe5139c0f Mon Sep 17 00:00:00 2001
From: felickz <1760475+felickz@users.noreply.github.com>
Date: Wed, 25 Nov 2026 19:38:01 +0000
Subject: [PATCH 2/2] 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>
---
.../security/CWE-079/IronResponseXss.qhelp | 7 +++--
rust/src/security/CWE-079/IronResponseXss.ql | 30 +++++++++++++++----
.../IronResponseXss/IronModels.expected | 2 ++
.../IronResponseXss/IronResponseXss.expected | 18 +++++++++++
.../security/CWE-079/IronResponseXss/main.rs | 15 ++++++++++
5 files changed, 64 insertions(+), 8 deletions(-)
diff --git a/rust/src/security/CWE-079/IronResponseXss.qhelp b/rust/src/security/CWE-079/IronResponseXss.qhelp
index 01e1cbe7..82cc54c9 100644
--- a/rust/src/security/CWE-079/IronResponseXss.qhelp
+++ b/rust/src/security/CWE-079/IronResponseXss.qhelp
@@ -76,9 +76,10 @@ target, except for a few that only tell a property of the value, such as l
(or only partly, as escape_default does) is not recognized as a barrier. A parameter is
recognized by the name of its type, so it can be a type of another crate that has the same name. A
function that takes a request is a source whether or not a call of Iron::new or
-Chain::new registers it. For a handler that nothing registers in the file, a body that is
-passed on its own to a call of Response::with that resolves is reported by this query, as
-the standard query has no source for it.
+Chain::new registers it. A body that is passed on its own to a call of
+Response::with that resolves is reported by this query only when the standard query does
+not report it: the handler is not registered in the file, or a call that has no target lies between the
+request and the body.
diff --git a/rust/src/security/CWE-079/IronResponseXss.ql b/rust/src/security/CWE-079/IronResponseXss.ql
index 3cccdb66..4c622f7e 100644
--- a/rust/src/security/CWE-079/IronResponseXss.ql
+++ b/rust/src/security/CWE-079/IronResponseXss.ql
@@ -151,8 +151,9 @@ class IronUnresolvedResponseBody extends DataFlow::Node {
/**
* The argument of a call of `Response::with` that resolves, when it is a body on its own and not a tuple
* of modifiers. The data extension row for the function makes it a sink of the standard cross-site
- * scripting query, but only the handlers that the rows make a source reach it there. This query reports
- * the other handlers, whose request parameter is a source of this query only (see the `where` clause).
+ * scripting query. This query reports a flow into it only when the standard query does not (see the
+ * `where` clause): when the handler is not registered, so that the row has no source for it, or when a
+ * call that has no target lies between the request and the body.
*/
class IronResolvedResponseBody extends DataFlow::Node {
IronResolvedResponseBody() {
@@ -187,6 +188,21 @@ module IronResponseXssConfig implements DataFlow::ConfigSig {
module IronResponseXssFlow = TaintTracking::Global;
+/**
+ * The configuration of the standard cross-site scripting query (`rust/xss`), copied from it. It has none
+ * of the steps of this query for calls that have no target, so a flow that it finds is a flow that the
+ * standard query reports.
+ */
+module StandardXssConfig implements DataFlow::ConfigSig {
+ predicate isSource(DataFlow::Node node) { node instanceof Xss::Source }
+
+ predicate isSink(DataFlow::Node node) { node instanceof Xss::Sink }
+
+ predicate isBarrier(DataFlow::Node barrier) { barrier instanceof Xss::Barrier }
+}
+
+module StandardXssFlow = TaintTracking::Global;
+
import IronResponseXssFlow::PathGraph
from IronResponseXssFlow::PathNode sourceNode, IronResponseXssFlow::PathNode sinkNode
@@ -201,11 +217,15 @@ where
modelled.getNode() instanceof Xss::Source
)
) and
- // A body on its own that goes to a call that resolves is reported by the standard query, from the
- // sources that the data extension rows make. This query leaves those flows to it.
+ // A body on its own that goes to a call that resolves is left to the standard query when its analysis
+ // reaches the body from the same source. When a call that has no target lies in between, it does not,
+ // and this query reports the flow.
not (
sinkNode.getNode() instanceof IronResolvedResponseBody and
- sourceNode.getNode() instanceof Xss::Source
+ exists(DataFlow::Node standardSink |
+ StandardXssFlow::flow(sourceNode.getNode(), standardSink) and
+ standardSink.getLocation() = sinkNode.getNode().getLocation()
+ )
)
select sinkNode.getNode(), sourceNode, sinkNode, "Cross-site scripting vulnerability due to a $@.",
sourceNode.getNode(), "user-provided value"
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
index cdb18e3c..2915616c 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
@@ -31,3 +31,5 @@
| main.rs:146:23:146:31 | modifiers | html-injection sink |
| main.rs:154:23:154:44 | TupleExpr | html-injection sink |
| main.rs:162:23:162:30 | response | html-injection sink |
+| main.rs:173:23:173:26 | loud | html-injection sink |
+| main.rs:177:15:177:52 | bad_registered_unresolved_step_handler | remote source |
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
index 0e18d72a..27490b70 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
@@ -201,6 +201,14 @@ edges
| main.rs:159:28:159:55 | ...::must_use(...) | main.rs:159:9:159:16 | response | provenance | |
| main.rs:159:28:159:55 | MacroExpr | main.rs:159:28:159:55 | ...::format(...) | provenance | MaD:371 |
| main.rs:159:28:159:55 | { ... } | main.rs:159:28:159:55 | ...::must_use(...) | provenance | MaD:13380 |
+| main.rs:165:43:165:59 | ...: ... | main.rs:166:15:166:21 | req.url | provenance | |
+| main.rs:166:9:166:11 | res | main.rs:169:16:169:18 | res | provenance | |
+| main.rs:166:15:166:21 | req.url | main.rs:166:15:166:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:166:15:166:28 | ... .path() | main.rs:166:9:166:11 | res | provenance | |
+| main.rs:169:9:169:12 | loud | main.rs:173:23:173:26 | loud | provenance | |
+| main.rs:169:16:169:18 | res | main.rs:169:16:169:26 | res.shout() | provenance | Config |
+| main.rs:169:16:169:26 | res.shout() | main.rs:169:9:169:12 | loud | provenance | |
+| main.rs:177:15:177:52 | bad_registered_unresolved_step_handler | main.rs:165:43:165:59 | ...: ... | provenance | Src:MaD:17584 |
nodes
| glob_prelude.rs:9:16:9:32 | ...: ... | semmle.label | ...: ... |
| glob_prelude.rs:10:9:10:11 | res | semmle.label | res |
@@ -424,6 +432,15 @@ nodes
| main.rs:159:28:159:55 | MacroExpr | semmle.label | MacroExpr |
| main.rs:159:28:159:55 | { ... } | semmle.label | { ... } |
| main.rs:162:23:162:30 | response | semmle.label | response |
+| main.rs:165:43:165:59 | ...: ... | semmle.label | ...: ... |
+| main.rs:166:9:166:11 | res | semmle.label | res |
+| main.rs:166:15:166:21 | req.url | semmle.label | req.url |
+| main.rs:166:15:166:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:169:9:169:12 | loud | semmle.label | loud |
+| main.rs:169:16:169:18 | res | semmle.label | res |
+| main.rs:169:16:169:26 | res.shout() | semmle.label | res.shout() |
+| main.rs:173:23:173:26 | loud | semmle.label | loud |
+| main.rs:177:15:177:52 | bad_registered_unresolved_step_handler | semmle.label | bad_registered_unresolved_step_handler |
subpaths
#select
| glob_prelude.rs:13:36:13:43 | response | glob_prelude.rs:9:16:9:32 | ...: ... | glob_prelude.rs:13:36:13:43 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:9:16:9:32 | ...: ... | user-provided value |
@@ -445,3 +462,4 @@ subpaths
| main.rs:110:49:110:56 | response | main.rs:133:15:133:41 | bad_overriding_mime_handler | main.rs:110:49:110:56 | response | Cross-site scripting vulnerability due to a $@. | main.rs:133:15:133:41 | bad_overriding_mime_handler | user-provided value |
| main.rs:154:36:154:43 | response | main.rs:149:29:149:45 | ...: ... | main.rs:154:36:154:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:149:29:149:45 | ...: ... | user-provided value |
| main.rs:162:23:162:30 | response | main.rs:157:39:157:55 | ...: ... | main.rs:162:23:162:30 | response | Cross-site scripting vulnerability due to a $@. | main.rs:157:39:157:55 | ...: ... | user-provided value |
+| main.rs:173:23:173:26 | loud | main.rs:177:15:177:52 | bad_registered_unresolved_step_handler | main.rs:173:23:173:26 | loud | Cross-site scripting vulnerability due to a $@. | main.rs:177:15:177:52 | bad_registered_unresolved_step_handler | user-provided value |
diff --git a/rust/test/security/CWE-079/IronResponseXss/main.rs b/rust/test/security/CWE-079/IronResponseXss/main.rs
index 8b9f1aad..782c9f8e 100644
--- a/rust/test/security/CWE-079/IronResponseXss/main.rs
+++ b/rust/test/security/CWE-079/IronResponseXss/main.rs
@@ -161,3 +161,18 @@ fn bad_unregistered_body_only_handler(req: &mut Request) -> IronResult
// the standard query has no source for the handler, so this query reports it.
Ok(Response::with(response))
}
+
+fn bad_registered_unresolved_step_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ // The method does not exist for the type, so the call has no target and the standard analysis does
+ // not follow the value through it.
+ let loud = res.shout();
+ // BAD: a body on its own, from a handler that is registered below, to a call that resolves. The data
+ // extension rows make it a flow, but the standard query cannot see it across the call that has no
+ // target, so this query has to report it.
+ Ok(Response::with(loud))
+}
+
+fn register_more() {
+ Iron::new(bad_registered_unresolved_step_handler).http("localhost:3015").unwrap();
+}