From d7d3f224a47007428a639a1a1d6a2a1d38a15c68 Mon Sep 17 00:00:00 2001
From: Chad Bentz <1760475+felickz@users.noreply.github.com>
Date: Sat, 21 Nov 2026 13:22:38 -0500
Subject: [PATCH 1/5] Rust: add Iron models and the response modifier tuple XSS
query
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
---
rust/ext/manual/iron.model.yml | 22 +
.../security/CWE-079/IronResponseXss.qhelp | 54 ++
rust/src/security/CWE-079/IronResponseXss.ql | 104 ++++
.../security/CWE-079/IronResponseXssBad.rs | 8 +
.../security/CWE-079/IronResponseXssGood.rs | 10 +
.../CWE-079/IronResponseXss/Cargo.lock | 487 ++++++++++++++++++
.../IronResponseXss/IronModels.expected | 17 +
.../CWE-079/IronResponseXss/IronModels.ql | 16 +
.../IronResponseXss/IronResponseXss.expected | 92 ++++
.../IronResponseXss/IronResponseXss.qlref | 1 +
.../security/CWE-079/IronResponseXss/main.rs | 77 +++
.../CWE-079/IronResponseXss/options.yml | 2 +
12 files changed, 890 insertions(+)
create mode 100644 rust/ext/manual/iron.model.yml
create mode 100644 rust/src/security/CWE-079/IronResponseXss.qhelp
create mode 100644 rust/src/security/CWE-079/IronResponseXss.ql
create mode 100644 rust/src/security/CWE-079/IronResponseXssBad.rs
create mode 100644 rust/src/security/CWE-079/IronResponseXssGood.rs
create mode 100644 rust/test/security/CWE-079/IronResponseXss/Cargo.lock
create mode 100644 rust/test/security/CWE-079/IronResponseXss/IronModels.expected
create mode 100644 rust/test/security/CWE-079/IronResponseXss/IronModels.ql
create mode 100644 rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
create mode 100644 rust/test/security/CWE-079/IronResponseXss/IronResponseXss.qlref
create mode 100644 rust/test/security/CWE-079/IronResponseXss/main.rs
create mode 100644 rust/test/security/CWE-079/IronResponseXss/options.yml
diff --git a/rust/ext/manual/iron.model.yml b/rust/ext/manual/iron.model.yml
new file mode 100644
index 00000000..2175e89d
--- /dev/null
+++ b/rust/ext/manual/iron.model.yml
@@ -0,0 +1,22 @@
+extensions:
+ - addsTo:
+ pack: codeql/rust-all
+ extensible: sourceModel
+ data:
+ # The `&mut Request` passed to a handler registered with `Chain::new` or `Iron::new`.
+ - ["
+The Iron web framework builds a response from a tuple of modifiers, for example
+
+This query finds user-controlled data that is part of a modifier tuple passed to
+
+Set an explicit content type that is not HTML when the body is not markup, or encode the
+user-controlled data for HTML before it is added to the body.
+
+In the following example, the path of the request is written into the body of the response without
+a content type, so a path that contains markup is rendered as HTML:
+
+In the following corrected example, the response declares that its body is plain text:
+
+A content type that is set by another kind of modifier, such as {:?}Response::with((status::Ok, body)). A body that is added this way is sent without a
+Content-Type header unless one of the modifiers sets it, and browsers then guess the
+content type from the body. If the body contains user-controlled data, an attacker can make the
+browser render it as HTML and run a script in the context of the application.
+Response::with. A tuple that also contains a content type parsed from a string literal
+that does not name HTML or XML, such as "text/plain".parse::<Mime>().unwrap(), is
+not reported.
+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 parsed directly from a string literal and flows to the tuple through local
+variables, unwrap, expect or ?.
+Hello, {:?}!
", name);
+ Ok(Response::with((status::Ok, body))) // BAD: no content type, the body may be sniffed as HTML
+}
diff --git a/rust/src/security/CWE-079/IronResponseXssGood.rs b/rust/src/security/CWE-079/IronResponseXssGood.rs
new file mode 100644
index 00000000..a750c098
--- /dev/null
+++ b/rust/src/security/CWE-079/IronResponseXssGood.rs
@@ -0,0 +1,10 @@
+use iron::mime::Mime;
+use iron::status;
+use iron::{IronResult, Request, Response};
+
+fn handler(req: &mut Request) -> IronResultAssessing resource, {:?}!
", res);
+ Ok(Response::with((status::Ok, response)))
+}
+
+fn bad_body_only_handler(req: &mut Request) -> IronResultAssessing resource, {:?}!
", res);
+ // GOOD: an explicit `text/plain` content type is set.
+ let plain: Mime = "text/plain".parse().unwrap();
+ Ok(Response::with((status::Ok, plain, response)))
+}
+
+fn good_json_handler(req: &mut Request) -> IronResultHello
")))
+}
+
+mod prelude_style {
+ use iron::prelude::*;
+ use iron::status;
+
+ pub fn handler(req: &mut Request) -> IronResultAssessing resource, {:?}!
", res);
+ // BAD: same as `bad_handler`, using the `iron::prelude` imports.
+ Ok(Response::with((status::Ok, response)))
+ }
+}
+
+fn bad_named_tuple_handler(req: &mut Request) -> IronResultAssessing resource, {:?}!
", res);
+ // BAD: the tuple is built first and passed to `Response::with` later.
+ let modifiers = (status::Ok, response);
+ Ok(Response::with(modifiers))
+}
+
+fn bad_html_mime_handler(req: &mut Request) -> IronResultAssessing resource, {:?}!
", res);
+ // BAD: an explicit `text/html` content type does not make the body safe.
+ let html: Mime = "text/html".parse().unwrap();
+ Ok(Response::with((status::Ok, html, response)))
+}
+
+fn main() {
+ Iron::new(bad_handler).http("localhost:3000").unwrap();
+ Iron::new(Chain::new(bad_body_only_handler)).http("localhost:3001").unwrap();
+ Iron::new(good_plain_text_handler).http("localhost:3002").unwrap();
+ Iron::new(good_json_handler).http("localhost:3003").unwrap();
+ Iron::new(good_constant_handler).http("localhost:3004").unwrap();
+ Iron::new(prelude_style::handler).http("localhost:3005").unwrap();
+ Iron::new(bad_named_tuple_handler).http("localhost:3006").unwrap();
+ Iron::new(bad_html_mime_handler).http("localhost:3007").unwrap();
+}
diff --git a/rust/test/security/CWE-079/IronResponseXss/options.yml b/rust/test/security/CWE-079/IronResponseXss/options.yml
new file mode 100644
index 00000000..15d7e4ee
--- /dev/null
+++ b/rust/test/security/CWE-079/IronResponseXss/options.yml
@@ -0,0 +1,2 @@
+qltest_dependencies:
+ - iron = "0.6.1"
From dc3f07af1e748c586f8a60b5d489fe4a471426a1 Mon Sep 17 00:00:00 2001
From: Chad Bentz <1760475+felickz@users.noreply.github.com>
Date: Sat, 21 Nov 2026 22:48:06 -0500
Subject: [PATCH 2/5] Rust Iron XSS: only the parsed content type itself
suppresses the alert
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
---
.../security/CWE-079/IronResponseXss.qhelp | 3 +-
rust/src/security/CWE-079/IronResponseXss.ql | 38 +++++++--------
.../IronResponseXss/IronModels.expected | 20 ++++----
.../IronResponseXss/IronResponseXss.expected | 46 ++++++++++++++-----
.../security/CWE-079/IronResponseXss/main.rs | 9 ++++
5 files changed, 76 insertions(+), 40 deletions(-)
diff --git a/rust/src/security/CWE-079/IronResponseXss.qhelp b/rust/src/security/CWE-079/IronResponseXss.qhelp
index fb27ecf4..70b033fc 100644
--- a/rust/src/security/CWE-079/IronResponseXss.qhelp
+++ b/rust/src/security/CWE-079/IronResponseXss.qhelp
@@ -43,7 +43,8 @@ In the following corrected example, the response declares that its body is plain
A content type that is set by another kind of modifier, 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 parsed directly from a string literal and flows to the tuple through local
-variables, unwrap, expect or ?.
+variables, unwrap, expect or ?. The type that the literal is
+parsed into is not checked.
Header(Con
is not recognized, so the body of such a response is still reported. A content type is recognized
only when it is parsed directly from a string literal and flows to the tuple through local
variables, unwrap, expect or ?. The type that the literal is
-parsed into is not checked.
+parsed into is not checked. If several parsed literals can reach the content type, for example one on
+each branch of an if, it is recognized only when none of them names HTML or XML.
diff --git a/rust/src/security/CWE-079/IronResponseXss.ql b/rust/src/security/CWE-079/IronResponseXss.ql
index 49f127de..d8c23c48 100644
--- a/rust/src/security/CWE-079/IronResponseXss.ql
+++ b/rust/src/security/CWE-079/IronResponseXss.ql
@@ -60,6 +60,22 @@ private predicate isParsedFrom(Expr e, ParsedStringLiteral literal) {
)
}
+/**
+ * Holds if `modifier` is a content type that is parsed from string literals, and every parsed literal
+ * that reaches it names a content type that is not markup. A content type that can also be HTML or XML,
+ * for example on one branch of an `if`, is not safe.
+ */
+private predicate isSafeContentType(Expr modifier) {
+ exists(ParsedStringLiteral safe |
+ isParsedFrom(modifier, safe) and
+ not isMarkupContentType(safe)
+ ) and
+ not exists(ParsedStringLiteral markup |
+ isParsedFrom(modifier, markup) and
+ isMarkupContentType(markup)
+ )
+}
+
/**
* An element of a modifier tuple passed to `iron::Response::with`, such as `body` in
* `Response::with((status::Ok, body))`.
@@ -78,9 +94,9 @@ class IronResponseModifierTupleElement extends DataFlow::Node {
DataFlow::localFlow(tupleNode, argumentNode)
) and
this.asExpr() = modifiers.getAField() and
- not exists(ParsedStringLiteral literal |
- not isMarkupContentType(literal) and
- isParsedFrom(modifiers.getAField(), literal)
+ not exists(Expr modifier |
+ modifier = modifiers.getAField() and
+ isSafeContentType(modifier)
)
)
}
diff --git a/rust/test/codeql-pack.lock.yml b/rust/test/codeql-pack.lock.yml
index 18fce78d..5d36ef0f 100644
--- a/rust/test/codeql-pack.lock.yml
+++ b/rust/test/codeql-pack.lock.yml
@@ -15,8 +15,12 @@ dependencies:
version: 1.0.62
codeql/rust-all:
version: 0.2.26
+ codeql/rust-queries:
+ version: 0.1.47
codeql/ssa:
version: 2.0.38
+ codeql/suite-helpers:
+ version: 1.0.62
codeql/threat-models:
version: 1.1.2
codeql/tutorial:
diff --git a/rust/test/qlpack.yml b/rust/test/qlpack.yml
index fd42b6bb..38640d21 100644
--- a/rust/test/qlpack.yml
+++ b/rust/test/qlpack.yml
@@ -2,6 +2,7 @@ name: githubsecuritylab/codeql-rust-tests
groups: [rust, test]
dependencies:
codeql/rust-all: '0.2.26'
+ codeql/rust-queries: '0.1.47'
githubsecuritylab/codeql-rust-queries: '*'
githubsecuritylab/codeql-rust-extensions: '*'
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
index de103ab2..44775b03 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
@@ -7,13 +7,15 @@
| main.rs:57:23:57:31 | modifiers | html-injection sink |
| main.rs:65:23:65:50 | TupleExpr | html-injection sink |
| main.rs:73:23:73:44 | TupleExpr | html-injection sink |
-| main.rs:77:15:77:25 | bad_handler | remote source |
-| main.rs:78:15:78:47 | ...::new(...) | remote source |
-| main.rs:78:26:78:46 | bad_body_only_handler | remote source |
-| main.rs:79:15:79:37 | good_plain_text_handler | remote source |
-| main.rs:80:15:80:31 | good_json_handler | remote source |
-| main.rs:81:15:81:35 | good_constant_handler | remote source |
-| main.rs:82:15:82:36 | ...::handler | remote source |
-| main.rs:83:15:83:37 | bad_named_tuple_handler | remote source |
-| main.rs:84:15:84:35 | bad_html_mime_handler | remote source |
-| main.rs:85:15:85:48 | bad_parsed_literal_in_body_handler | remote source |
+| main.rs:86:23:86:50 | TupleExpr | html-injection sink |
+| main.rs:90:15:90:25 | bad_handler | remote source |
+| main.rs:91:15:91:47 | ...::new(...) | remote source |
+| main.rs:91:26:91:46 | bad_body_only_handler | remote source |
+| main.rs:92:15:92:37 | good_plain_text_handler | remote source |
+| main.rs:93:15:93:31 | good_json_handler | remote source |
+| main.rs:94:15:94:35 | good_constant_handler | remote source |
+| main.rs:95:15:95:36 | ...::handler | remote source |
+| main.rs:96:15:96:37 | bad_named_tuple_handler | remote source |
+| main.rs:97:15:97:35 | bad_html_mime_handler | remote source |
+| main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | remote source |
+| main.rs:99:15:99:36 | bad_mixed_mime_handler | remote source |
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
index 1113fc2c..ff53f038 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
@@ -44,11 +44,21 @@ edges
| main.rs:72:28:72:58 | ...::must_use(...) | main.rs:72:9:72:16 | response | provenance | |
| main.rs:72:28:72:58 | MacroExpr | main.rs:72:28:72:58 | ...::format(...) | provenance | MaD:371 |
| main.rs:72:28:72:58 | { ... } | main.rs:72:28:72:58 | ...::must_use(...) | provenance | MaD:13380 |
-| main.rs:77:15:77:25 | bad_handler | main.rs:5:16:5:32 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:82:15:82:36 | ...::handler | main.rs:44:20:44:36 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:83:15:83:37 | bad_named_tuple_handler | main.rs:52:28:52:44 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:84:15:84:35 | bad_html_mime_handler | main.rs:60:26:60:42 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:85:15:85:48 | bad_parsed_literal_in_body_handler | main.rs:68:39:68:55 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:76:27:76:43 | ...: ... | main.rs:77:15:77:21 | req.url | provenance | |
+| main.rs:77:9:77:11 | res | main.rs:78:28:78:68 | MacroExpr | provenance | |
+| main.rs:77:15:77:21 | req.url | main.rs:77:15:77:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:77:15:77:28 | ... .path() | main.rs:77:9:77:11 | res | provenance | |
+| main.rs:78:9:78:16 | response | main.rs:86:42:86:49 | response | provenance | |
+| main.rs:78:28:78:68 | ...::format(...) | main.rs:78:28:78:68 | { ... } | provenance | |
+| main.rs:78:28:78:68 | ...::must_use(...) | main.rs:78:9:78:16 | response | provenance | |
+| main.rs:78:28:78:68 | MacroExpr | main.rs:78:28:78:68 | ...::format(...) | provenance | MaD:371 |
+| main.rs:78:28:78:68 | { ... } | main.rs:78:28:78:68 | ...::must_use(...) | provenance | MaD:13380 |
+| main.rs:90:15:90:25 | bad_handler | main.rs:5:16:5:32 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:95:15:95:36 | ...::handler | main.rs:44:20:44:36 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:96:15:96:37 | bad_named_tuple_handler | main.rs:52:28:52:44 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:97:15:97:35 | bad_html_mime_handler | main.rs:60:26:60:42 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | main.rs:68:39:68:55 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:99:15:99:36 | bad_mixed_mime_handler | main.rs:76:27:76:43 | ...: ... | provenance | Src:MaD:17584 |
nodes
| main.rs:5:16:5:32 | ...: ... | semmle.label | ...: ... |
| main.rs:6:9:6:11 | res | semmle.label | res |
@@ -100,15 +110,27 @@ nodes
| main.rs:72:28:72:58 | MacroExpr | semmle.label | MacroExpr |
| main.rs:72:28:72:58 | { ... } | semmle.label | { ... } |
| main.rs:73:36:73:43 | response | semmle.label | response |
-| main.rs:77:15:77:25 | bad_handler | semmle.label | bad_handler |
-| main.rs:82:15:82:36 | ...::handler | semmle.label | ...::handler |
-| main.rs:83:15:83:37 | bad_named_tuple_handler | semmle.label | bad_named_tuple_handler |
-| main.rs:84:15:84:35 | bad_html_mime_handler | semmle.label | bad_html_mime_handler |
-| main.rs:85:15:85:48 | bad_parsed_literal_in_body_handler | semmle.label | bad_parsed_literal_in_body_handler |
+| main.rs:76:27:76:43 | ...: ... | semmle.label | ...: ... |
+| main.rs:77:9:77:11 | res | semmle.label | res |
+| main.rs:77:15:77:21 | req.url | semmle.label | req.url |
+| main.rs:77:15:77:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:78:9:78:16 | response | semmle.label | response |
+| main.rs:78:28:78:68 | ...::format(...) | semmle.label | ...::format(...) |
+| main.rs:78:28:78:68 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| main.rs:78:28:78:68 | MacroExpr | semmle.label | MacroExpr |
+| main.rs:78:28:78:68 | { ... } | semmle.label | { ... } |
+| main.rs:86:42:86:49 | response | semmle.label | response |
+| main.rs:90:15:90:25 | bad_handler | semmle.label | bad_handler |
+| main.rs:95:15:95:36 | ...::handler | semmle.label | ...::handler |
+| main.rs:96:15:96:37 | bad_named_tuple_handler | semmle.label | bad_named_tuple_handler |
+| main.rs:97:15:97:35 | bad_html_mime_handler | semmle.label | bad_html_mime_handler |
+| main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | semmle.label | bad_parsed_literal_in_body_handler |
+| main.rs:99:15:99:36 | bad_mixed_mime_handler | semmle.label | bad_mixed_mime_handler |
subpaths
#select
-| main.rs:9:36:9:43 | response | main.rs:77:15:77:25 | bad_handler | main.rs:9:36:9:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:77:15:77:25 | bad_handler | user-provided value |
-| main.rs:48:40:48:47 | response | main.rs:82:15:82:36 | ...::handler | main.rs:48:40:48:47 | response | Cross-site scripting vulnerability due to a $@. | main.rs:82:15:82:36 | ...::handler | user-provided value |
-| main.rs:56:34:56:41 | response | main.rs:83:15:83:37 | bad_named_tuple_handler | main.rs:56:34:56:41 | response | Cross-site scripting vulnerability due to a $@. | main.rs:83:15:83:37 | bad_named_tuple_handler | user-provided value |
-| main.rs:65:42:65:49 | response | main.rs:84:15:84:35 | bad_html_mime_handler | main.rs:65:42:65:49 | response | Cross-site scripting vulnerability due to a $@. | main.rs:84:15:84:35 | bad_html_mime_handler | user-provided value |
-| main.rs:73:36:73:43 | response | main.rs:85:15:85:48 | bad_parsed_literal_in_body_handler | main.rs:73:36:73:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:85:15:85:48 | bad_parsed_literal_in_body_handler | user-provided value |
+| main.rs:9:36:9:43 | response | main.rs:90:15:90:25 | bad_handler | main.rs:9:36:9:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:90:15:90:25 | bad_handler | user-provided value |
+| main.rs:48:40:48:47 | response | main.rs:95:15:95:36 | ...::handler | main.rs:48:40:48:47 | response | Cross-site scripting vulnerability due to a $@. | main.rs:95:15:95:36 | ...::handler | user-provided value |
+| main.rs:56:34:56:41 | response | main.rs:96:15:96:37 | bad_named_tuple_handler | main.rs:56:34:56:41 | response | Cross-site scripting vulnerability due to a $@. | main.rs:96:15:96:37 | bad_named_tuple_handler | user-provided value |
+| main.rs:65:42:65:49 | response | main.rs:97:15:97:35 | bad_html_mime_handler | main.rs:65:42:65:49 | response | Cross-site scripting vulnerability due to a $@. | main.rs:97:15:97:35 | bad_html_mime_handler | user-provided value |
+| main.rs:73:36:73:43 | response | main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | main.rs:73:36:73:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | user-provided value |
+| main.rs:86:42:86:49 | response | main.rs:99:15:99:36 | bad_mixed_mime_handler | main.rs:86:42:86:49 | response | Cross-site scripting vulnerability due to a $@. | main.rs:99:15:99:36 | bad_mixed_mime_handler | user-provided value |
diff --git a/rust/test/security/CWE-079/IronResponseXss/XSS.expected b/rust/test/security/CWE-079/IronResponseXss/XSS.expected
new file mode 100644
index 00000000..91314305
--- /dev/null
+++ b/rust/test/security/CWE-079/IronResponseXss/XSS.expected
@@ -0,0 +1,24 @@
+edges
+| main.rs:12:26:12:42 | ...: ... | main.rs:13:15:13:21 | req.url | provenance | |
+| main.rs:13:9:13:11 | res | main.rs:16:31:16:48 | MacroExpr | provenance | |
+| main.rs:13:15:13:21 | req.url | main.rs:13:15:13:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:13:15:13:28 | ... .path() | main.rs:13:9:13:11 | res | provenance | |
+| main.rs:16:31:16:48 | ...::format(...) | main.rs:16:31:16:48 | { ... } | provenance | |
+| main.rs:16:31:16:48 | ...::must_use(...) | main.rs:16:23:16:49 | MacroExpr | provenance | Sink:MaD:17586 |
+| main.rs:16:31:16:48 | MacroExpr | main.rs:16:31:16:48 | ...::format(...) | provenance | MaD:371 |
+| main.rs:16:31:16:48 | { ... } | main.rs:16:31:16:48 | ...::must_use(...) | provenance | MaD:13380 |
+| main.rs:91:26:91:46 | bad_body_only_handler | main.rs:12:26:12:42 | ...: ... | provenance | Src:MaD:17585 |
+nodes
+| main.rs:12:26:12:42 | ...: ... | semmle.label | ...: ... |
+| main.rs:13:9:13:11 | res | semmle.label | res |
+| main.rs:13:15:13:21 | req.url | semmle.label | req.url |
+| main.rs:13:15:13:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:16:23:16:49 | MacroExpr | semmle.label | MacroExpr |
+| main.rs:16:31:16:48 | ...::format(...) | semmle.label | ...::format(...) |
+| main.rs:16:31:16:48 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| main.rs:16:31:16:48 | MacroExpr | semmle.label | MacroExpr |
+| main.rs:16:31:16:48 | { ... } | semmle.label | { ... } |
+| main.rs:91:26:91:46 | bad_body_only_handler | semmle.label | bad_body_only_handler |
+subpaths
+#select
+| main.rs:16:23:16:49 | MacroExpr | main.rs:91:26:91:46 | bad_body_only_handler | main.rs:16:23:16:49 | MacroExpr | Cross-site scripting vulnerability due to a $@. | main.rs:91:26:91:46 | bad_body_only_handler | user-provided value |
diff --git a/rust/test/security/CWE-079/IronResponseXss/XSS.qlref b/rust/test/security/CWE-079/IronResponseXss/XSS.qlref
new file mode 100644
index 00000000..12aff7f2
--- /dev/null
+++ b/rust/test/security/CWE-079/IronResponseXss/XSS.qlref
@@ -0,0 +1 @@
+query: queries/security/CWE-079/XSS.ql
diff --git a/rust/test/security/CWE-079/IronResponseXss/main.rs b/rust/test/security/CWE-079/IronResponseXss/main.rs
index fb740796..037e07d4 100644
--- a/rust/test/security/CWE-079/IronResponseXss/main.rs
+++ b/rust/test/security/CWE-079/IronResponseXss/main.rs
@@ -73,6 +73,19 @@ fn bad_parsed_literal_in_body_handler(req: &mut Request) -> IronResult
Ok(Response::with((status::Ok, response)))
}
+fn bad_mixed_mime_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Assessing resource, {:?}!
", res);
+ // BAD: the content type is plain text on one branch and HTML on the other, so the body can still be
+ // rendered as HTML.
+ let mime: Mime = if res.len() > 3 {
+ "text/plain".parse().unwrap()
+ } else {
+ "text/html".parse().unwrap()
+ };
+ Ok(Response::with((status::Ok, mime, response)))
+}
+
fn main() {
Iron::new(bad_handler).http("localhost:3000").unwrap();
Iron::new(Chain::new(bad_body_only_handler)).http("localhost:3001").unwrap();
@@ -83,4 +96,5 @@ fn main() {
Iron::new(bad_named_tuple_handler).http("localhost:3006").unwrap();
Iron::new(bad_html_mime_handler).http("localhost:3007").unwrap();
Iron::new(bad_parsed_literal_in_body_handler).http("localhost:3008").unwrap();
+ Iron::new(bad_mixed_mime_handler).http("localhost:3009").unwrap();
}
From 9d1e0234cf220bc4ac400e0894dbceceabca6a5e Mon Sep 17 00:00:00 2001
From: Chad Bentz <1760475+felickz@users.noreply.github.com>
Date: Mon, 23 Nov 2026 10:56:30 -0500
Subject: [PATCH 4/5] Rust Iron XSS: look through nested modifier tuples, judge
every content 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
---
.../security/CWE-079/IronResponseXss.qhelp | 14 ++-
rust/src/security/CWE-079/IronResponseXss.ql | 61 +++++++----
.../IronResponseXss/IronModels.expected | 30 ++++--
.../IronResponseXss/IronResponseXss.expected | 102 ++++++++++++++----
.../CWE-079/IronResponseXss/XSS.expected | 6 +-
.../security/CWE-079/IronResponseXss/main.rs | 36 +++++++
6 files changed, 192 insertions(+), 57 deletions(-)
diff --git a/rust/src/security/CWE-079/IronResponseXss.qhelp b/rust/src/security/CWE-079/IronResponseXss.qhelp
index 58c6c1b0..b277fd50 100644
--- a/rust/src/security/CWE-079/IronResponseXss.qhelp
+++ b/rust/src/security/CWE-079/IronResponseXss.qhelp
@@ -13,9 +13,10 @@ browser render it as HTML and run a script in the context of the application.
This query finds user-controlled data that is part of a modifier tuple passed to
-Response::with. A tuple that also contains a content type parsed from a string literal
-that does not name HTML or XML, such as "text/plain".parse::<Mime>().unwrap(), is
-not reported.
+Response::with, including the elements of tuples that are nested in it. A response
+whose modifiers include a content type parsed from a string literal that does not name HTML or
+XML, such as "text/plain".parse::<Mime>().unwrap(), and none that does, is not
+reported.
@@ -44,8 +45,11 @@ A content type that is set by another kind of modifier, such as Header(Con
is not recognized, so the body of such a response is still reported. A content type is recognized
only when it is parsed directly from a string literal and flows to the tuple through local
variables, unwrap, expect or ?. The type that the literal is
-parsed into is not checked. If several parsed literals can reach the content type, for example one on
-each branch of an if, it is recognized only when none of them names HTML or XML.
+parsed into is not checked. If 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
+recognized only when none of them names HTML or XML. Iron applies the modifiers in order, so a
+text/html modifier after a text/plain one replaces it, and the query does
+not try to tell which of two content types wins.
diff --git a/rust/src/security/CWE-079/IronResponseXss.ql b/rust/src/security/CWE-079/IronResponseXss.ql
index d8c23c48..78a8ca6d 100644
--- a/rust/src/security/CWE-079/IronResponseXss.ql
+++ b/rust/src/security/CWE-079/IronResponseXss.ql
@@ -61,43 +61,64 @@ private predicate isParsedFrom(Expr e, ParsedStringLiteral literal) {
}
/**
- * Holds if `modifier` is a content type that is parsed from string literals, and every parsed literal
- * that reaches it names a content type that is not markup. A content type that can also be HTML or XML,
- * for example on one branch of an `if`, is not safe.
+ * Holds if `tuple` is a tuple expression whose value the expression `e` holds: `e` is the tuple, or a
+ * local variable or expression that the tuple flows to.
*/
-private predicate isSafeContentType(Expr modifier) {
+private predicate holdsTuple(Expr e, TupleExpr tuple) {
+ exists(DataFlow::ExprNode tupleNode, DataFlow::ExprNode eNode |
+ tupleNode.asExpr() = tuple and
+ eNode.asExpr() = e and
+ DataFlow::localFlow(tupleNode, eNode)
+ )
+}
+
+/**
+ * Gets a modifier of the response that is built from `e`, the argument of `Response::with`: an element
+ * of the tuple that `e` holds, or of a tuple that is nested in it. Iron applies the modifiers of a
+ * nested tuple to the same response.
+ */
+private Expr getAModifier(Expr e) {
+ exists(TupleExpr tuple, Expr element | holdsTuple(e, tuple) and element = tuple.getAField() |
+ result = element and not holdsTuple(element, _)
+ or
+ result = getAModifier(element)
+ )
+}
+
+/**
+ * Holds if the response that is built from `argument` has an explicit content type that is not markup:
+ * a modifier is parsed from a string literal that does not name HTML or XML, and no modifier of the
+ * response is parsed from a literal that does. Iron applies the modifiers in order, so a `text/html`
+ * modifier after a `text/plain` one replaces it, and a response whose content type can be markup is
+ * not safe. This also covers a content type that is parsed from different literals on different
+ * branches of an `if`.
+ */
+private predicate hasSafeContentType(Expr argument) {
exists(ParsedStringLiteral safe |
- isParsedFrom(modifier, safe) and
+ isParsedFrom(getAModifier(argument), safe) and
not isMarkupContentType(safe)
) and
not exists(ParsedStringLiteral markup |
- isParsedFrom(modifier, markup) and
+ isParsedFrom(getAModifier(argument), markup) and
isMarkupContentType(markup)
)
}
/**
* An element of a modifier tuple passed to `iron::Response::with`, such as `body` in
- * `Response::with((status::Ok, body))`.
+ * `Response::with((status::Ok, body))`, or of a tuple that is nested in it.
*
- * Tuples that contain a content type modifier parsed from a string literal that does not name
- * HTML or XML set an explicit, safe `Content-Type` and are not considered sinks.
+ * A response whose modifiers include a content type that is parsed from a string literal that does not
+ * name HTML or XML, and none that does, has an explicit, safe `Content-Type` and is not considered a
+ * sink.
*/
class IronResponseModifierTupleElement extends DataFlow::Node {
IronResponseModifierTupleElement() {
- exists(Call call, TupleExpr modifiers, Expr argument |
+ exists(Call call, Expr argument |
call.getStaticTarget().getCanonicalPath() = "::with" and
argument = call.getPositionalArgument(0) and
- exists(DataFlow::ExprNode tupleNode, DataFlow::ExprNode argumentNode |
- tupleNode.asExpr() = modifiers and
- argumentNode.asExpr() = argument and
- DataFlow::localFlow(tupleNode, argumentNode)
- ) and
- this.asExpr() = modifiers.getAField() and
- not exists(Expr modifier |
- modifier = modifiers.getAField() and
- isSafeContentType(modifier)
- )
+ this.asExpr() = getAModifier(argument) and
+ not hasSafeContentType(argument)
)
}
}
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
index 44775b03..2e5e279b 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
@@ -8,14 +8,22 @@
| main.rs:65:23:65:50 | TupleExpr | html-injection sink |
| main.rs:73:23:73:44 | TupleExpr | html-injection sink |
| main.rs:86:23:86:50 | TupleExpr | html-injection sink |
-| main.rs:90:15:90:25 | bad_handler | remote source |
-| main.rs:91:15:91:47 | ...::new(...) | remote source |
-| main.rs:91:26:91:46 | bad_body_only_handler | remote source |
-| main.rs:92:15:92:37 | good_plain_text_handler | remote source |
-| main.rs:93:15:93:31 | good_json_handler | remote source |
-| main.rs:94:15:94:35 | good_constant_handler | remote source |
-| main.rs:95:15:95:36 | ...::handler | remote source |
-| main.rs:96:15:96:37 | bad_named_tuple_handler | remote source |
-| main.rs:97:15:97:35 | bad_html_mime_handler | remote source |
-| main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | remote source |
-| main.rs:99:15:99:36 | bad_mixed_mime_handler | remote source |
+| main.rs:93:23:93:58 | TupleExpr | html-injection sink |
+| main.rs:101:23:101:41 | TupleExpr | html-injection sink |
+| main.rs:110:23:110:57 | TupleExpr | html-injection sink |
+| main.rs:118:23:118:53 | TupleExpr | html-injection sink |
+| main.rs:122:15:122:25 | bad_handler | remote source |
+| main.rs:123:15:123:47 | ...::new(...) | remote source |
+| main.rs:123:26:123:46 | bad_body_only_handler | remote source |
+| main.rs:124:15:124:37 | good_plain_text_handler | remote source |
+| main.rs:125:15:125:31 | good_json_handler | remote source |
+| main.rs:126:15:126:35 | good_constant_handler | remote source |
+| main.rs:127:15:127:36 | ...::handler | remote source |
+| main.rs:128:15:128:37 | bad_named_tuple_handler | remote source |
+| main.rs:129:15:129:35 | bad_html_mime_handler | remote source |
+| main.rs:130:15:130:48 | bad_parsed_literal_in_body_handler | remote source |
+| main.rs:131:15:131:36 | bad_mixed_mime_handler | remote source |
+| main.rs:132:15:132:38 | bad_nested_tuple_handler | remote source |
+| main.rs:133:15:133:41 | bad_overriding_mime_handler | remote source |
+| main.rs:134:15:134:44 | good_nested_plain_text_handler | remote source |
+| main.rs:135:15:135:44 | bad_nested_named_tuple_handler | remote source |
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
index ff53f038..9c610c33 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
@@ -53,12 +53,42 @@ edges
| main.rs:78:28:78:68 | ...::must_use(...) | main.rs:78:9:78:16 | response | provenance | |
| main.rs:78:28:78:68 | MacroExpr | main.rs:78:28:78:68 | ...::format(...) | provenance | MaD:371 |
| main.rs:78:28:78:68 | { ... } | main.rs:78:28:78:68 | ...::must_use(...) | provenance | MaD:13380 |
-| main.rs:90:15:90:25 | bad_handler | main.rs:5:16:5:32 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:95:15:95:36 | ...::handler | main.rs:44:20:44:36 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:96:15:96:37 | bad_named_tuple_handler | main.rs:52:28:52:44 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:97:15:97:35 | bad_html_mime_handler | main.rs:60:26:60:42 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | main.rs:68:39:68:55 | ...: ... | provenance | Src:MaD:17584 |
-| main.rs:99:15:99:36 | bad_mixed_mime_handler | main.rs:76:27:76:43 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:89:29:89:45 | ...: ... | main.rs:90:15:90:21 | req.url | provenance | |
+| main.rs:90:9:90:11 | res | main.rs:91:28:91:68 | MacroExpr | provenance | |
+| main.rs:90:15:90:21 | req.url | main.rs:90:15:90:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:90:15:90:28 | ... .path() | main.rs:90:9:90:11 | res | provenance | |
+| main.rs:91:9:91:16 | response | main.rs:93:49:93:56 | response | provenance | |
+| main.rs:91:28:91:68 | ...::format(...) | main.rs:91:28:91:68 | { ... } | provenance | |
+| main.rs:91:28:91:68 | ...::must_use(...) | main.rs:91:9:91:16 | response | provenance | |
+| main.rs:91:28:91:68 | MacroExpr | main.rs:91:28:91:68 | ...::format(...) | provenance | MaD:371 |
+| main.rs:91:28:91:68 | { ... } | main.rs:91:28:91:68 | ...::must_use(...) | provenance | MaD:13380 |
+| main.rs:96:35:96:51 | ...: ... | main.rs:97:15:97:21 | req.url | provenance | |
+| main.rs:97:9:97:11 | res | main.rs:98:28:98:68 | MacroExpr | provenance | |
+| main.rs:97:15:97:21 | req.url | main.rs:97:15:97:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:97:15:97:28 | ... .path() | main.rs:97:9:97:11 | res | provenance | |
+| main.rs:98:9:98:16 | response | main.rs:100:30:100:37 | response | provenance | |
+| main.rs:98:28:98:68 | ...::format(...) | main.rs:98:28:98:68 | { ... } | provenance | |
+| main.rs:98:28:98:68 | ...::must_use(...) | main.rs:98:9:98:16 | response | provenance | |
+| main.rs:98:28:98:68 | MacroExpr | main.rs:98:28:98:68 | ...::format(...) | provenance | MaD:371 |
+| main.rs:98:28:98:68 | { ... } | main.rs:98:28:98:68 | ...::must_use(...) | provenance | MaD:13380 |
+| main.rs:104:32:104:48 | ...: ... | main.rs:105:15:105:21 | req.url | provenance | |
+| main.rs:105:9:105:11 | res | main.rs:106:28:106:68 | MacroExpr | provenance | |
+| main.rs:105:15:105:21 | req.url | main.rs:105:15:105:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:105:15:105:28 | ... .path() | main.rs:105:9:105:11 | res | provenance | |
+| main.rs:106:9:106:16 | response | main.rs:110:49:110:56 | response | provenance | |
+| main.rs:106:28:106:68 | ...::format(...) | main.rs:106:28:106:68 | { ... } | provenance | |
+| main.rs:106:28:106:68 | ...::must_use(...) | main.rs:106:9:106:16 | response | provenance | |
+| main.rs:106:28:106:68 | MacroExpr | main.rs:106:28:106:68 | ...::format(...) | provenance | MaD:371 |
+| main.rs:106:28:106:68 | { ... } | main.rs:106:28:106:68 | ...::must_use(...) | provenance | MaD:13380 |
+| main.rs:122:15:122:25 | bad_handler | main.rs:5:16:5:32 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:127:15:127:36 | ...::handler | main.rs:44:20:44:36 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:128:15:128:37 | bad_named_tuple_handler | main.rs:52:28:52:44 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:129:15:129:35 | bad_html_mime_handler | main.rs:60:26:60:42 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:130:15:130:48 | bad_parsed_literal_in_body_handler | main.rs:68:39:68:55 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:131:15:131:36 | bad_mixed_mime_handler | main.rs:76:27:76:43 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:132:15:132:38 | bad_nested_tuple_handler | main.rs:89:29:89:45 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:133:15:133:41 | bad_overriding_mime_handler | main.rs:104:32:104:48 | ...: ... | provenance | Src:MaD:17584 |
+| main.rs:135:15:135:44 | bad_nested_named_tuple_handler | main.rs:96:35:96:51 | ...: ... | provenance | Src:MaD:17584 |
nodes
| main.rs:5:16:5:32 | ...: ... | semmle.label | ...: ... |
| main.rs:6:9:6:11 | res | semmle.label | res |
@@ -120,17 +150,53 @@ nodes
| main.rs:78:28:78:68 | MacroExpr | semmle.label | MacroExpr |
| main.rs:78:28:78:68 | { ... } | semmle.label | { ... } |
| main.rs:86:42:86:49 | response | semmle.label | response |
-| main.rs:90:15:90:25 | bad_handler | semmle.label | bad_handler |
-| main.rs:95:15:95:36 | ...::handler | semmle.label | ...::handler |
-| main.rs:96:15:96:37 | bad_named_tuple_handler | semmle.label | bad_named_tuple_handler |
-| main.rs:97:15:97:35 | bad_html_mime_handler | semmle.label | bad_html_mime_handler |
-| main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | semmle.label | bad_parsed_literal_in_body_handler |
-| main.rs:99:15:99:36 | bad_mixed_mime_handler | semmle.label | bad_mixed_mime_handler |
+| main.rs:89:29:89:45 | ...: ... | semmle.label | ...: ... |
+| main.rs:90:9:90:11 | res | semmle.label | res |
+| main.rs:90:15:90:21 | req.url | semmle.label | req.url |
+| main.rs:90:15:90:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:91:9:91:16 | response | semmle.label | response |
+| main.rs:91:28:91:68 | ...::format(...) | semmle.label | ...::format(...) |
+| main.rs:91:28:91:68 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| main.rs:91:28:91:68 | MacroExpr | semmle.label | MacroExpr |
+| main.rs:91:28:91:68 | { ... } | semmle.label | { ... } |
+| main.rs:93:49:93:56 | response | semmle.label | response |
+| main.rs:96:35:96:51 | ...: ... | semmle.label | ...: ... |
+| main.rs:97:9:97:11 | res | semmle.label | res |
+| main.rs:97:15:97:21 | req.url | semmle.label | req.url |
+| main.rs:97:15:97:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:98:9:98:16 | response | semmle.label | response |
+| main.rs:98:28:98:68 | ...::format(...) | semmle.label | ...::format(...) |
+| main.rs:98:28:98:68 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| main.rs:98:28:98:68 | MacroExpr | semmle.label | MacroExpr |
+| main.rs:98:28:98:68 | { ... } | semmle.label | { ... } |
+| main.rs:100:30:100:37 | response | semmle.label | response |
+| main.rs:104:32:104:48 | ...: ... | semmle.label | ...: ... |
+| main.rs:105:9:105:11 | res | semmle.label | res |
+| main.rs:105:15:105:21 | req.url | semmle.label | req.url |
+| main.rs:105:15:105:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:106:9:106:16 | response | semmle.label | response |
+| main.rs:106:28:106:68 | ...::format(...) | semmle.label | ...::format(...) |
+| main.rs:106:28:106:68 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| main.rs:106:28:106:68 | MacroExpr | semmle.label | MacroExpr |
+| main.rs:106:28:106:68 | { ... } | semmle.label | { ... } |
+| main.rs:110:49:110:56 | response | semmle.label | response |
+| main.rs:122:15:122:25 | bad_handler | semmle.label | bad_handler |
+| main.rs:127:15:127:36 | ...::handler | semmle.label | ...::handler |
+| main.rs:128:15:128:37 | bad_named_tuple_handler | semmle.label | bad_named_tuple_handler |
+| main.rs:129:15:129:35 | bad_html_mime_handler | semmle.label | bad_html_mime_handler |
+| main.rs:130:15:130:48 | bad_parsed_literal_in_body_handler | semmle.label | bad_parsed_literal_in_body_handler |
+| main.rs:131:15:131:36 | bad_mixed_mime_handler | semmle.label | bad_mixed_mime_handler |
+| main.rs:132:15:132:38 | bad_nested_tuple_handler | semmle.label | bad_nested_tuple_handler |
+| main.rs:133:15:133:41 | bad_overriding_mime_handler | semmle.label | bad_overriding_mime_handler |
+| main.rs:135:15:135:44 | bad_nested_named_tuple_handler | semmle.label | bad_nested_named_tuple_handler |
subpaths
#select
-| main.rs:9:36:9:43 | response | main.rs:90:15:90:25 | bad_handler | main.rs:9:36:9:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:90:15:90:25 | bad_handler | user-provided value |
-| main.rs:48:40:48:47 | response | main.rs:95:15:95:36 | ...::handler | main.rs:48:40:48:47 | response | Cross-site scripting vulnerability due to a $@. | main.rs:95:15:95:36 | ...::handler | user-provided value |
-| main.rs:56:34:56:41 | response | main.rs:96:15:96:37 | bad_named_tuple_handler | main.rs:56:34:56:41 | response | Cross-site scripting vulnerability due to a $@. | main.rs:96:15:96:37 | bad_named_tuple_handler | user-provided value |
-| main.rs:65:42:65:49 | response | main.rs:97:15:97:35 | bad_html_mime_handler | main.rs:65:42:65:49 | response | Cross-site scripting vulnerability due to a $@. | main.rs:97:15:97:35 | bad_html_mime_handler | user-provided value |
-| main.rs:73:36:73:43 | response | main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | main.rs:73:36:73:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:98:15:98:48 | bad_parsed_literal_in_body_handler | user-provided value |
-| main.rs:86:42:86:49 | response | main.rs:99:15:99:36 | bad_mixed_mime_handler | main.rs:86:42:86:49 | response | Cross-site scripting vulnerability due to a $@. | main.rs:99:15:99:36 | bad_mixed_mime_handler | user-provided value |
+| main.rs:9:36:9:43 | response | main.rs:122:15:122:25 | bad_handler | main.rs:9:36:9:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:122:15:122:25 | bad_handler | user-provided value |
+| main.rs:48:40:48:47 | response | main.rs:127:15:127:36 | ...::handler | main.rs:48:40:48:47 | response | Cross-site scripting vulnerability due to a $@. | main.rs:127:15:127:36 | ...::handler | user-provided value |
+| main.rs:56:34:56:41 | response | main.rs:128:15:128:37 | bad_named_tuple_handler | main.rs:56:34:56:41 | response | Cross-site scripting vulnerability due to a $@. | main.rs:128:15:128:37 | bad_named_tuple_handler | user-provided value |
+| main.rs:65:42:65:49 | response | main.rs:129:15:129:35 | bad_html_mime_handler | main.rs:65:42:65:49 | response | Cross-site scripting vulnerability due to a $@. | main.rs:129:15:129:35 | bad_html_mime_handler | user-provided value |
+| main.rs:73:36:73:43 | response | main.rs:130:15:130:48 | bad_parsed_literal_in_body_handler | main.rs:73:36:73:43 | response | Cross-site scripting vulnerability due to a $@. | main.rs:130:15:130:48 | bad_parsed_literal_in_body_handler | user-provided value |
+| main.rs:86:42:86:49 | response | main.rs:131:15:131:36 | bad_mixed_mime_handler | main.rs:86:42:86:49 | response | Cross-site scripting vulnerability due to a $@. | main.rs:131:15:131:36 | bad_mixed_mime_handler | user-provided value |
+| main.rs:93:49:93:56 | response | main.rs:132:15:132:38 | bad_nested_tuple_handler | main.rs:93:49:93:56 | response | Cross-site scripting vulnerability due to a $@. | main.rs:132:15:132:38 | bad_nested_tuple_handler | user-provided value |
+| main.rs:100:30:100:37 | response | main.rs:135:15:135:44 | bad_nested_named_tuple_handler | main.rs:100:30:100:37 | response | Cross-site scripting vulnerability due to a $@. | main.rs:135:15:135:44 | bad_nested_named_tuple_handler | user-provided value |
+| 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 |
diff --git a/rust/test/security/CWE-079/IronResponseXss/XSS.expected b/rust/test/security/CWE-079/IronResponseXss/XSS.expected
index 91314305..9f35a8d3 100644
--- a/rust/test/security/CWE-079/IronResponseXss/XSS.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/XSS.expected
@@ -7,7 +7,7 @@ edges
| main.rs:16:31:16:48 | ...::must_use(...) | main.rs:16:23:16:49 | MacroExpr | provenance | Sink:MaD:17586 |
| main.rs:16:31:16:48 | MacroExpr | main.rs:16:31:16:48 | ...::format(...) | provenance | MaD:371 |
| main.rs:16:31:16:48 | { ... } | main.rs:16:31:16:48 | ...::must_use(...) | provenance | MaD:13380 |
-| main.rs:91:26:91:46 | bad_body_only_handler | main.rs:12:26:12:42 | ...: ... | provenance | Src:MaD:17585 |
+| main.rs:123:26:123:46 | bad_body_only_handler | main.rs:12:26:12:42 | ...: ... | provenance | Src:MaD:17585 |
nodes
| main.rs:12:26:12:42 | ...: ... | semmle.label | ...: ... |
| main.rs:13:9:13:11 | res | semmle.label | res |
@@ -18,7 +18,7 @@ nodes
| main.rs:16:31:16:48 | ...::must_use(...) | semmle.label | ...::must_use(...) |
| main.rs:16:31:16:48 | MacroExpr | semmle.label | MacroExpr |
| main.rs:16:31:16:48 | { ... } | semmle.label | { ... } |
-| main.rs:91:26:91:46 | bad_body_only_handler | semmle.label | bad_body_only_handler |
+| main.rs:123:26:123:46 | bad_body_only_handler | semmle.label | bad_body_only_handler |
subpaths
#select
-| main.rs:16:23:16:49 | MacroExpr | main.rs:91:26:91:46 | bad_body_only_handler | main.rs:16:23:16:49 | MacroExpr | Cross-site scripting vulnerability due to a $@. | main.rs:91:26:91:46 | bad_body_only_handler | user-provided value |
+| main.rs:16:23:16:49 | MacroExpr | main.rs:123:26:123:46 | bad_body_only_handler | main.rs:16:23:16:49 | MacroExpr | Cross-site scripting vulnerability due to a $@. | main.rs:123:26:123:46 | bad_body_only_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 037e07d4..c6918a07 100644
--- a/rust/test/security/CWE-079/IronResponseXss/main.rs
+++ b/rust/test/security/CWE-079/IronResponseXss/main.rs
@@ -86,6 +86,38 @@ fn bad_mixed_mime_handler(req: &mut Request) -> IronResult {
Ok(Response::with((status::Ok, mime, response)))
}
+fn bad_nested_tuple_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Assessing resource, {:?}!
", res);
+ // BAD: modifier tuples nest, and the body is in the inner tuple.
+ Ok(Response::with((status::Ok, (status::Ok, response))))
+}
+
+fn bad_nested_named_tuple_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Assessing resource, {:?}!
", res);
+ // BAD: the inner tuple is built first and nested later.
+ let inner = (status::Ok, response);
+ Ok(Response::with((status::Ok, inner)))
+}
+
+fn bad_overriding_mime_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Assessing resource, {:?}!
", res);
+ // BAD: the `text/html` modifier is applied after the `text/plain` one, so the body is served as HTML.
+ let plain: Mime = "text/plain".parse().unwrap();
+ let html: Mime = "text/html".parse().unwrap();
+ Ok(Response::with((status::Ok, plain, html, response)))
+}
+
+fn good_nested_plain_text_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Assessing resource, {:?}!
", res);
+ // GOOD: the `text/plain` content type is in the inner tuple and applies to the whole response.
+ let plain: Mime = "text/plain".parse().unwrap();
+ Ok(Response::with((status::Ok, (plain, response))))
+}
+
fn main() {
Iron::new(bad_handler).http("localhost:3000").unwrap();
Iron::new(Chain::new(bad_body_only_handler)).http("localhost:3001").unwrap();
@@ -97,4 +129,8 @@ fn main() {
Iron::new(bad_html_mime_handler).http("localhost:3007").unwrap();
Iron::new(bad_parsed_literal_in_body_handler).http("localhost:3008").unwrap();
Iron::new(bad_mixed_mime_handler).http("localhost:3009").unwrap();
+ Iron::new(bad_nested_tuple_handler).http("localhost:3010").unwrap();
+ Iron::new(bad_overriding_mime_handler).http("localhost:3011").unwrap();
+ Iron::new(good_nested_plain_text_handler).http("localhost:3012").unwrap();
+ Iron::new(bad_nested_named_tuple_handler).http("localhost:3013").unwrap();
}
From d6291b6ef12cecd86279fc15674681713b20545d Mon Sep 17 00:00:00 2001
From: Chad Bentz <1760475+felickz@users.noreply.github.com>
Date: Mon, 23 Nov 2026 12:48:51 -0500
Subject: [PATCH 5/5] Rust Iron XSS: document that a tuple field assigned later
is not tracked
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
---
rust/src/security/CWE-079/IronResponseXss.qhelp | 5 +++++
.../CWE-079/IronResponseXss/IronModels.expected | 2 ++
rust/test/security/CWE-079/IronResponseXss/main.rs | 11 +++++++++++
3 files changed, 18 insertions(+)
diff --git a/rust/src/security/CWE-079/IronResponseXss.qhelp b/rust/src/security/CWE-079/IronResponseXss.qhelp
index b277fd50..211cf4f8 100644
--- a/rust/src/security/CWE-079/IronResponseXss.qhelp
+++ b/rust/src/security/CWE-079/IronResponseXss.qhelp
@@ -51,6 +51,11 @@ recognized only when none of them names HTML or XML. Iron applies the modifiers
text/html modifier after a text/plain one replaces it, and the query does
not try to tell which of two content types wins.
+
+The sinks are the expressions that a modifier tuple is built from, so a tuple that is changed after it
+is built, for example by assigning a body to one of its fields (modifiers.1 = body;), is
+not tracked.
+
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
index 2e5e279b..94a28d4b 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
@@ -27,3 +27,5 @@
| main.rs:133:15:133:41 | bad_overriding_mime_handler | remote source |
| main.rs:134:15:134:44 | good_nested_plain_text_handler | remote source |
| main.rs:135:15:135:44 | bad_nested_named_tuple_handler | remote source |
+| main.rs:136:15:136:49 | missed_field_assigned_later_handler | remote source |
+| main.rs:146:23:146:31 | modifiers | html-injection sink |
diff --git a/rust/test/security/CWE-079/IronResponseXss/main.rs b/rust/test/security/CWE-079/IronResponseXss/main.rs
index c6918a07..3f57120b 100644
--- a/rust/test/security/CWE-079/IronResponseXss/main.rs
+++ b/rust/test/security/CWE-079/IronResponseXss/main.rs
@@ -133,4 +133,15 @@ fn main() {
Iron::new(bad_overriding_mime_handler).http("localhost:3011").unwrap();
Iron::new(good_nested_plain_text_handler).http("localhost:3012").unwrap();
Iron::new(bad_nested_named_tuple_handler).http("localhost:3013").unwrap();
+ Iron::new(missed_field_assigned_later_handler).http("localhost:3014").unwrap();
+}
+
+fn missed_field_assigned_later_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Assessing resource, {:?}!
", res);
+ // MISSED (known limitation): the body is assigned to a tuple field after the tuple is built, so the
+ // sink is the original `String::new()` expression and not the assigned value.
+ let mut modifiers = (status::Ok, String::new());
+ modifiers.1 = response;
+ Ok(Response::with(modifiers))
}