From d8e6109594473732000dd144a57e2039a9097d2f Mon Sep 17 00:00:00 2001
From: Chad Bentz <1760475+felickz@users.noreply.github.com>
Date: Tue, 24 Nov 2026 16:26:49 -0500
Subject: [PATCH 1/2] 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/src/common/IronFallback.qll | 106 +++++++++++
.../security/CWE-079/IronResponseXss.qhelp | 20 ++
rust/src/security/CWE-079/IronResponseXss.ql | 51 ++++-
.../IronResponseXss/GlobCalls.expected | 67 +++++++
.../CWE-079/IronResponseXss/GlobCalls.ql | 13 ++
.../IronResponseXss/IronModels.expected | 1 +
.../IronResponseXss/IronResponseXss.expected | 178 ++++++++++++++++++
.../CWE-079/IronResponseXss/glob_prelude.rs | 116 ++++++++++++
.../security/CWE-079/IronResponseXss/main.rs | 8 +
.../IronResponseXss/other_framework.rs | 12 ++
10 files changed, 568 insertions(+), 4 deletions(-)
create mode 100644 rust/src/common/IronFallback.qll
create mode 100644 rust/test/security/CWE-079/IronResponseXss/GlobCalls.expected
create mode 100644 rust/test/security/CWE-079/IronResponseXss/GlobCalls.ql
create mode 100644 rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs
create mode 100644 rust/test/security/CWE-079/IronResponseXss/other_framework.rs
diff --git a/rust/src/common/IronFallback.qll b/rust/src/common/IronFallback.qll
new file mode 100644
index 00000000..9c16c4ed
--- /dev/null
+++ b/rust/src/common/IronFallback.qll
@@ -0,0 +1,106 @@
+/**
+ * Provides a fallback that recognizes the `iron` crate by the names it uses, for databases in which
+ * the calls into it cannot be resolved.
+ *
+ * A database that is built without compiling the code, as a code scanning default setup does
+ * (`buildMode: none`), can leave every call that goes through a glob import of `iron::prelude` without
+ * a target, such as `Iron::new`, `Response::with` and the methods of the request. The data extension
+ * rows for Iron match canonical paths, and so do the sinks that are written as calls to a canonical
+ * path, so none of them applies to such code. The classes and predicates here match the same API by
+ * name, in files that use `iron`, and for calls that have no target.
+ */
+
+import rust
+private import codeql.rust.dataflow.DataFlow
+
+/** Gets the identifier of the first segment of `path`, such as `iron` for `iron::prelude`. */
+private string getRootSegment(Path path) {
+ not exists(path.getQualifier()) and result = path.getSegment().getIdentifier().getText()
+ or
+ result = getRootSegment(path.getQualifier())
+}
+
+/** Holds if `file` uses the `iron` crate, with a `use` item or an `extern crate` item. */
+predicate isIronFile(File file) {
+ exists(Use use |
+ use.getLocation().getFile() = file and
+ getRootSegment(use.getUseTree().getPath()) = "iron"
+ )
+ or
+ exists(ExternCrate crate |
+ crate.getLocation().getFile() = file and
+ crate.getIdentifier().getText() = "iron"
+ )
+}
+
+/** Holds if `typeRepr` is a type that is called `Request`, or a reference to one. */
+private predicate isRequestType(TypeRepr typeRepr) {
+ typeRepr.(PathTypeRepr).getPath().getSegment().getIdentifier().getText() = "Request"
+ or
+ isRequestType(typeRepr.(RefTypeRepr).getTypeRepr())
+}
+
+/**
+ * A parameter of type `Request`, `&Request` or `&mut Request` of a function or closure in a file that
+ * uses `iron`: the shape of an Iron handler or middleware, whether or not the type can be resolved.
+ */
+class IronRequestParameter extends DataFlow::Node {
+ IronRequestParameter() {
+ exists(Param param |
+ param = this.asParameter() and
+ isIronFile(param.getLocation().getFile()) and
+ isRequestType(param.getTypeRepr())
+ )
+ }
+}
+
+/** The fields of an Iron request that hold data that the client controls. */
+private predicate isRequestField(string name) { name = ["url", "headers", "body", "extensions"] }
+
+/** Holds if the method called `name` only tells a property of its receiver, not its content. */
+private predicate isNonRevealingMethod(string name) {
+ name =
+ [
+ "len", "is_empty", "capacity", "count", "contains", "starts_with", "ends_with", "is_some",
+ "is_none", "is_ok", "is_err"
+ ]
+}
+
+/**
+ * Holds if the flow goes from `pred` to `succ` in a file that uses `iron`, where the data flow library
+ * cannot know it because the type of `pred` is not known: `succ` is the read of a field of the
+ * request that does not resolve to a field, or the result of a method that has no target, called on
+ * `pred`. A method with `escape` or `encode` in its name is taken to encode the value, the way the
+ * standard queries take a call of a function with such a name, so it does not pass the value on.
+ */
+predicate ironUnresolvedStep(DataFlow::Node pred, DataFlow::Node succ) {
+ exists(FieldExpr field |
+ isIronFile(field.getLocation().getFile()) and
+ isRequestField(field.getIdentifier().getText()) and
+ not exists(field.getStructField()) and
+ pred.asExpr() = field.getContainer() and
+ succ.asExpr() = field
+ )
+ or
+ exists(MethodCallExpr call |
+ isIronFile(call.getLocation().getFile()) and
+ not exists(call.getStaticTarget()) and
+ not isNonRevealingMethod(call.getIdentifier().getText()) and
+ not call.getIdentifier().getText().regexpMatch(".*(escape|encode).*") and
+ pred.asExpr() = call.getReceiver() and
+ succ.asExpr() = call
+ )
+}
+
+/**
+ * Holds if `call` is a call of `Response::with` in a file that uses `iron`, and the call has no target.
+ * The call may name the type with a longer path, such as `iron::Response::with`.
+ */
+predicate isUnresolvedIronResponseWith(Call call) {
+ isIronFile(call.getLocation().getFile()) and
+ not exists(call.getStaticTarget()) and
+ exists(Path path | path = call.(CallExpr).getFunction().(PathExpr).getPath() |
+ path.getSegment().getIdentifier().getText() = "with" and
+ path.getQualifier().getSegment().getIdentifier().getText() = "Response"
+ )
+}
diff --git a/rust/src/security/CWE-079/IronResponseXss.qhelp b/rust/src/security/CWE-079/IronResponseXss.qhelp
index 211cf4f8..9ce83b97 100644
--- a/rust/src/security/CWE-079/IronResponseXss.qhelp
+++ b/rust/src/security/CWE-079/IronResponseXss.qhelp
@@ -18,6 +18,17 @@ whose modifiers include a content type parsed from a string literal that does no
XML, such as "text/plain".parse::<Mime>().unwrap(), and none that does, is not
reported.
+
+A database that is built without compiling the code can leave the calls into Iron without a target,
+when the names come from a glob import such as use iron::prelude::*. In a file that
+uses iron, the query also recognizes these calls by name. A function or closure with a
+parameter of type Request, &Request or &mut Request is
+a source, the url, headers, body and extensions
+fields of the request and the methods that are called on it are followed, and a call of
+Response::with that has no target is a sink. For such a call, a body that is passed on its
+own, as in Response::with(body), is a sink as well, because a body that is set on its own
+has no content type.
+
@@ -56,6 +67,15 @@ The sinks are the expressions that a modifier tuple is built from, so a tuple th
is built, for example by assigning a body to one of its fields (modifiers.1 = body;), is
not tracked.
+
+When the calls have no target, the query goes by names and only looks at files that use
+iron. It follows the result of every method that is called on the request and has no
+target, except for a few that only tell a property of the value, such as len and
+is_empty, and for names that contain escape or encode, which are
+taken to encode the value. A method that encodes the value under another name 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.
+
diff --git a/rust/src/security/CWE-079/IronResponseXss.ql b/rust/src/security/CWE-079/IronResponseXss.ql
index 78a8ca6d..14a919a6 100644
--- a/rust/src/security/CWE-079/IronResponseXss.ql
+++ b/rust/src/security/CWE-079/IronResponseXss.ql
@@ -19,6 +19,7 @@ import rust
import codeql.rust.dataflow.DataFlow
import codeql.rust.dataflow.TaintTracking
import codeql.rust.security.XssExtensions
+import common.IronFallback
/**
* A string literal that is parsed, such as the `"text/plain"` of
@@ -108,6 +109,9 @@ private predicate hasSafeContentType(Expr argument) {
* An element of a modifier tuple passed to `iron::Response::with`, such as `body` in
* `Response::with((status::Ok, body))`, or of a tuple that is nested in it.
*
+ * A call of `Response::with` that cannot be resolved is matched by its name in a file that uses `iron`
+ * (see `common.IronFallback`).
+ *
* 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.
@@ -115,7 +119,11 @@ private predicate hasSafeContentType(Expr argument) {
class IronResponseModifierTupleElement extends DataFlow::Node {
IronResponseModifierTupleElement() {
exists(Call call, Expr argument |
- call.getStaticTarget().getCanonicalPath() = "::with" and
+ (
+ call.getStaticTarget().getCanonicalPath() = "::with"
+ or
+ isUnresolvedIronResponseWith(call)
+ ) and
argument = call.getPositionalArgument(0) and
this.asExpr() = getAModifier(argument) and
not hasSafeContentType(argument)
@@ -123,13 +131,38 @@ class IronResponseModifierTupleElement extends DataFlow::Node {
}
}
+/**
+ * The argument of a call of `Response::with` that has no target, when it is a body on its own and not a
+ * tuple of modifiers. A call that can be resolved is covered by the data extension row for the same
+ * function, which the standard cross-site scripting query uses, and a body that is set on its own has no
+ * content type.
+ */
+class IronUnresolvedResponseBody extends DataFlow::Node {
+ IronUnresolvedResponseBody() {
+ exists(Call call, Expr argument |
+ isUnresolvedIronResponseWith(call) and
+ argument = call.getPositionalArgument(0) and
+ not holdsTuple(argument, _) and
+ this.asExpr() = argument
+ )
+ }
+}
+
module IronResponseXssConfig implements DataFlow::ConfigSig {
- predicate isSource(DataFlow::Node node) { node instanceof Xss::Source }
+ predicate isSource(DataFlow::Node node) {
+ node instanceof Xss::Source or node instanceof IronRequestParameter
+ }
- predicate isSink(DataFlow::Node node) { node instanceof IronResponseModifierTupleElement }
+ predicate isSink(DataFlow::Node node) {
+ node instanceof IronResponseModifierTupleElement or node instanceof IronUnresolvedResponseBody
+ }
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof Xss::Barrier }
+ predicate isAdditionalFlowStep(DataFlow::Node pred, DataFlow::Node succ) {
+ ironUnresolvedStep(pred, succ)
+ }
+
predicate observeDiffInformedIncrementalMode() { any() }
}
@@ -138,6 +171,16 @@ module IronResponseXssFlow = TaintTracking::Global;
import IronResponseXssFlow::PathGraph
from IronResponseXssFlow::PathNode sourceNode, IronResponseXssFlow::PathNode sinkNode
-where IronResponseXssFlow::flowPath(sourceNode, sinkNode)
+where
+ IronResponseXssFlow::flowPath(sourceNode, sinkNode) and
+ // A handler that the data extension rows already make a source is reported through that source.
+ not (
+ sourceNode.getNode() instanceof IronRequestParameter and
+ not sourceNode.getNode() instanceof Xss::Source and
+ exists(IronResponseXssFlow::PathNode modelled |
+ IronResponseXssFlow::flowPath(modelled, sinkNode) and
+ modelled.getNode() instanceof Xss::Source
+ )
+ )
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/GlobCalls.expected b/rust/test/security/CWE-079/IronResponseXss/GlobCalls.expected
new file mode 100644
index 00000000..cc9ae4fd
--- /dev/null
+++ b/rust/test/security/CWE-079/IronResponseXss/GlobCalls.expected
@@ -0,0 +1,67 @@
+| 10 | ... .path() |
+| 13 | ...::with(...) |
+| 17 | ... .path() |
+| 19 | ...::with(...) |
+| 23 | ... .path() |
+| 27 | ...::with(...) |
+| 31 | ... .path() |
+| 34 | ...::with(...) |
+| 38 | ... .query() |
+| 38 | ... .unwrap_or(...) |
+| 41 | ...::with(...) |
+| 45 | ... .path() |
+| 46 | path.join(...) |
+| 49 | ...::with(...) |
+| 54 | ...::with(...) |
+| 58 | ... .path() |
+| 59 | res.len() |
+| 61 | ...::with(...) |
+| 65 | ... .path() |
+| 69 | ...::with(...) |
+| 75 | ...::with(...) |
+| 79 | ... .escape_default() |
+| 79 | ... .join(...) |
+| 79 | ... .path() |
+| 79 | ... .to_string() |
+| 83 | ...::with(...) |
+| 89 | ... .path() |
+| 93 | clean(...) |
+| 94 | ...::with(...) |
+| 98 | ... .http(...) |
+| 98 | ... .unwrap() |
+| 98 | ...::new(...) |
+| 99 | ... .http(...) |
+| 99 | ... .unwrap() |
+| 99 | ...::new(...) |
+| 100 | ... .http(...) |
+| 100 | ... .unwrap() |
+| 100 | ...::new(...) |
+| 101 | ... .http(...) |
+| 101 | ... .unwrap() |
+| 101 | ...::new(...) |
+| 102 | ... .http(...) |
+| 102 | ... .unwrap() |
+| 102 | ...::new(...) |
+| 103 | ... .http(...) |
+| 103 | ... .unwrap() |
+| 103 | ...::new(...) |
+| 104 | ... .http(...) |
+| 104 | ... .unwrap() |
+| 104 | ...::new(...) |
+| 105 | ... .http(...) |
+| 105 | ... .unwrap() |
+| 105 | ...::new(...) |
+| 106 | ... .http(...) |
+| 106 | ... .unwrap() |
+| 106 | ...::new(...) |
+| 107 | ... .http(...) |
+| 107 | ... .unwrap() |
+| 107 | ...::new(...) |
+| 108 | ... .http(...) |
+| 108 | ... .unwrap() |
+| 108 | ...::new(...) |
+| 109 | ... .http(...) |
+| 109 | ... .unwrap() |
+| 109 | ...::new(...) |
+| 111 | ... .path() |
+| 112 | ...::with(...) |
diff --git a/rust/test/security/CWE-079/IronResponseXss/GlobCalls.ql b/rust/test/security/CWE-079/IronResponseXss/GlobCalls.ql
new file mode 100644
index 00000000..c7f081d2
--- /dev/null
+++ b/rust/test/security/CWE-079/IronResponseXss/GlobCalls.ql
@@ -0,0 +1,13 @@
+/**
+ * Lists the calls of `glob_prelude.rs` that have no target. The queries recognize Iron by its names
+ * because of them: if the extraction resolves these calls some day, this test changes and the file no
+ * longer exercises the fallback.
+ */
+
+import rust
+
+from Call call
+where
+ call.getLocation().getFile().getBaseName() = "glob_prelude.rs" and
+ not exists(call.getStaticTarget())
+select call.getLocation().getStartLine(), call.toString()
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
index 94a28d4b..35240a4e 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
@@ -29,3 +29,4 @@
| 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 |
+| main.rs:154:23:154:44 | TupleExpr | html-injection sink |
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
index 9c610c33..63101271 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
@@ -1,4 +1,76 @@
edges
+| glob_prelude.rs:9:16:9:32 | ...: ... | glob_prelude.rs:10:15:10:17 | req | provenance | |
+| glob_prelude.rs:10:9:10:11 | res | glob_prelude.rs:11:28:11:55 | MacroExpr | provenance | |
+| glob_prelude.rs:10:15:10:17 | req | glob_prelude.rs:10:15:10:21 | req.url | provenance | Config |
+| glob_prelude.rs:10:15:10:21 | req.url | glob_prelude.rs:10:15:10:28 | ... .path() | provenance | Config |
+| glob_prelude.rs:10:15:10:28 | ... .path() | glob_prelude.rs:10:9:10:11 | res | provenance | |
+| glob_prelude.rs:11:9:11:16 | response | glob_prelude.rs:13:36:13:43 | response | provenance | |
+| glob_prelude.rs:11:28:11:55 | ...::format(...) | glob_prelude.rs:11:28:11:55 | { ... } | provenance | |
+| glob_prelude.rs:11:28:11:55 | ...::must_use(...) | glob_prelude.rs:11:9:11:16 | response | provenance | |
+| glob_prelude.rs:11:28:11:55 | MacroExpr | glob_prelude.rs:11:28:11:55 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:11:28:11:55 | { ... } | glob_prelude.rs:11:28:11:55 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:16:26:16:42 | ...: ... | glob_prelude.rs:17:15:17:17 | req | provenance | |
+| glob_prelude.rs:17:9:17:11 | res | glob_prelude.rs:19:31:19:48 | MacroExpr | provenance | |
+| glob_prelude.rs:17:15:17:17 | req | glob_prelude.rs:17:15:17:21 | req.url | provenance | Config |
+| glob_prelude.rs:17:15:17:21 | req.url | glob_prelude.rs:17:15:17:28 | ... .path() | provenance | Config |
+| glob_prelude.rs:17:15:17:28 | ... .path() | glob_prelude.rs:17:9:17:11 | res | provenance | |
+| glob_prelude.rs:19:31:19:48 | ...::format(...) | glob_prelude.rs:19:31:19:48 | { ... } | provenance | |
+| glob_prelude.rs:19:31:19:48 | ...::must_use(...) | glob_prelude.rs:19:23:19:49 | MacroExpr | provenance | |
+| glob_prelude.rs:19:31:19:48 | MacroExpr | glob_prelude.rs:19:31:19:48 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:19:31:19:48 | { ... } | glob_prelude.rs:19:31:19:48 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:22:28:22:44 | ...: ... | glob_prelude.rs:23:15:23:17 | req | provenance | |
+| glob_prelude.rs:23:9:23:11 | res | glob_prelude.rs:24:28:24:47 | MacroExpr | provenance | |
+| glob_prelude.rs:23:15:23:17 | req | glob_prelude.rs:23:15:23:21 | req.url | provenance | Config |
+| glob_prelude.rs:23:15:23:21 | req.url | glob_prelude.rs:23:15:23:28 | ... .path() | provenance | Config |
+| glob_prelude.rs:23:15:23:28 | ... .path() | glob_prelude.rs:23:9:23:11 | res | provenance | |
+| glob_prelude.rs:24:9:24:16 | response | glob_prelude.rs:26:34:26:41 | response | provenance | |
+| glob_prelude.rs:24:28:24:47 | ...::format(...) | glob_prelude.rs:24:28:24:47 | { ... } | provenance | |
+| glob_prelude.rs:24:28:24:47 | ...::must_use(...) | glob_prelude.rs:24:9:24:16 | response | provenance | |
+| glob_prelude.rs:24:28:24:47 | MacroExpr | glob_prelude.rs:24:28:24:47 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:24:28:24:47 | { ... } | glob_prelude.rs:24:28:24:47 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:30:29:30:45 | ...: ... | glob_prelude.rs:31:15:31:17 | req | provenance | |
+| glob_prelude.rs:31:9:31:11 | res | glob_prelude.rs:32:28:32:47 | MacroExpr | provenance | |
+| glob_prelude.rs:31:15:31:17 | req | glob_prelude.rs:31:15:31:21 | req.url | provenance | Config |
+| glob_prelude.rs:31:15:31:21 | req.url | glob_prelude.rs:31:15:31:28 | ... .path() | provenance | Config |
+| glob_prelude.rs:31:15:31:28 | ... .path() | glob_prelude.rs:31:9:31:11 | res | provenance | |
+| glob_prelude.rs:32:9:32:16 | response | glob_prelude.rs:34:49:34:56 | response | provenance | |
+| glob_prelude.rs:32:28:32:47 | ...::format(...) | glob_prelude.rs:32:28:32:47 | { ... } | provenance | |
+| glob_prelude.rs:32:28:32:47 | ...::must_use(...) | glob_prelude.rs:32:9:32:16 | response | provenance | |
+| glob_prelude.rs:32:28:32:47 | MacroExpr | glob_prelude.rs:32:28:32:47 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:32:28:32:47 | { ... } | glob_prelude.rs:32:28:32:47 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:37:22:37:38 | ...: ... | glob_prelude.rs:38:17:38:19 | req | provenance | |
+| glob_prelude.rs:38:9:38:13 | query | glob_prelude.rs:39:28:39:45 | MacroExpr | provenance | |
+| glob_prelude.rs:38:17:38:19 | req | glob_prelude.rs:38:17:38:23 | req.url | provenance | Config |
+| glob_prelude.rs:38:17:38:23 | req.url | glob_prelude.rs:38:17:38:31 | ... .query() | provenance | Config |
+| glob_prelude.rs:38:17:38:31 | ... .query() | glob_prelude.rs:38:17:38:45 | ... .unwrap_or(...) | provenance | Config |
+| glob_prelude.rs:38:17:38:45 | ... .unwrap_or(...) | glob_prelude.rs:38:9:38:13 | query | provenance | |
+| glob_prelude.rs:39:9:39:16 | response | glob_prelude.rs:41:36:41:43 | response | provenance | |
+| glob_prelude.rs:39:28:39:45 | ...::format(...) | glob_prelude.rs:39:28:39:45 | { ... } | provenance | |
+| glob_prelude.rs:39:28:39:45 | ...::must_use(...) | glob_prelude.rs:39:9:39:16 | response | provenance | |
+| glob_prelude.rs:39:28:39:45 | MacroExpr | glob_prelude.rs:39:28:39:45 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:39:28:39:45 | { ... } | glob_prelude.rs:39:28:39:45 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:44:25:44:41 | ...: ... | glob_prelude.rs:45:16:45:18 | req | provenance | |
+| glob_prelude.rs:45:9:45:12 | path | glob_prelude.rs:46:16:46:19 | path | provenance | |
+| glob_prelude.rs:45:16:45:18 | req | glob_prelude.rs:45:16:45:22 | req.url | provenance | Config |
+| glob_prelude.rs:45:16:45:22 | req.url | glob_prelude.rs:45:16:45:29 | ... .path() | provenance | Config |
+| glob_prelude.rs:45:16:45:29 | ... .path() | glob_prelude.rs:45:9:45:12 | path | provenance | |
+| glob_prelude.rs:46:9:46:12 | path | glob_prelude.rs:47:28:47:46 | MacroExpr | provenance | |
+| glob_prelude.rs:46:16:46:19 | path | glob_prelude.rs:46:16:46:29 | path.join(...) | provenance | Config |
+| glob_prelude.rs:46:16:46:29 | path.join(...) | glob_prelude.rs:46:9:46:12 | path | provenance | |
+| glob_prelude.rs:47:9:47:16 | response | glob_prelude.rs:49:36:49:43 | response | provenance | |
+| glob_prelude.rs:47:28:47:46 | ...::format(...) | glob_prelude.rs:47:28:47:46 | { ... } | provenance | |
+| glob_prelude.rs:47:28:47:46 | ...::must_use(...) | glob_prelude.rs:47:9:47:16 | response | provenance | |
+| glob_prelude.rs:47:28:47:46 | MacroExpr | glob_prelude.rs:47:28:47:46 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:47:28:47:46 | { ... } | glob_prelude.rs:47:28:47:46 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:109:16:109:32 | ...: ... | glob_prelude.rs:111:20:111:22 | req | provenance | |
+| glob_prelude.rs:111:13:111:16 | name | glob_prelude.rs:112:48:112:68 | MacroExpr | provenance | |
+| glob_prelude.rs:111:20:111:22 | req | glob_prelude.rs:111:20:111:26 | req.url | provenance | Config |
+| glob_prelude.rs:111:20:111:26 | req.url | glob_prelude.rs:111:20:111:33 | ... .path() | provenance | Config |
+| glob_prelude.rs:111:20:111:33 | ... .path() | glob_prelude.rs:111:13:111:16 | name | provenance | |
+| glob_prelude.rs:112:48:112:68 | ...::format(...) | glob_prelude.rs:112:48:112:68 | { ... } | provenance | |
+| glob_prelude.rs:112:48:112:68 | ...::must_use(...) | glob_prelude.rs:112:40:112:69 | MacroExpr | provenance | |
+| glob_prelude.rs:112:48:112:68 | MacroExpr | glob_prelude.rs:112:48:112:68 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:112:48:112:68 | { ... } | glob_prelude.rs:112:48:112:68 | ...::must_use(...) | provenance | MaD:13380 |
| main.rs:5:16:5:32 | ...: ... | main.rs:6:15:6:21 | req.url | provenance | |
| main.rs:6:9:6:11 | res | main.rs:8:28:8:68 | MacroExpr | provenance | |
| main.rs:6:15:6:21 | req.url | main.rs:6:15:6:28 | ... .path() | provenance | MaD:17587 |
@@ -89,7 +161,95 @@ edges
| 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 |
+| main.rs:149:29:149:45 | ...: ... | main.rs:150:15:150:21 | req.url | provenance | |
+| main.rs:150:9:150:11 | res | main.rs:151:28:151:55 | MacroExpr | provenance | |
+| main.rs:150:15:150:21 | req.url | main.rs:150:15:150:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:150:15:150:28 | ... .path() | main.rs:150:9:150:11 | res | provenance | |
+| main.rs:151:9:151:16 | response | main.rs:154:36:154:43 | response | provenance | |
+| main.rs:151:28:151:55 | ...::format(...) | main.rs:151:28:151:55 | { ... } | provenance | |
+| main.rs:151:28:151:55 | ...::must_use(...) | main.rs:151:9:151:16 | response | provenance | |
+| main.rs:151:28:151:55 | MacroExpr | main.rs:151:28:151:55 | ...::format(...) | provenance | MaD:371 |
+| main.rs:151:28:151:55 | { ... } | main.rs:151:28:151:55 | ...::must_use(...) | provenance | MaD:13380 |
nodes
+| glob_prelude.rs:9:16:9:32 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:10:9:10:11 | res | semmle.label | res |
+| glob_prelude.rs:10:15:10:17 | req | semmle.label | req |
+| glob_prelude.rs:10:15:10:21 | req.url | semmle.label | req.url |
+| glob_prelude.rs:10:15:10:28 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:11:9:11:16 | response | semmle.label | response |
+| glob_prelude.rs:11:28:11:55 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:11:28:11:55 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:11:28:11:55 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:11:28:11:55 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:13:36:13:43 | response | semmle.label | response |
+| glob_prelude.rs:16:26:16:42 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:17:9:17:11 | res | semmle.label | res |
+| glob_prelude.rs:17:15:17:17 | req | semmle.label | req |
+| glob_prelude.rs:17:15:17:21 | req.url | semmle.label | req.url |
+| glob_prelude.rs:17:15:17:28 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:19:23:19:49 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:19:31:19:48 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:19:31:19:48 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:19:31:19:48 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:19:31:19:48 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:22:28:22:44 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:23:9:23:11 | res | semmle.label | res |
+| glob_prelude.rs:23:15:23:17 | req | semmle.label | req |
+| glob_prelude.rs:23:15:23:21 | req.url | semmle.label | req.url |
+| glob_prelude.rs:23:15:23:28 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:24:9:24:16 | response | semmle.label | response |
+| glob_prelude.rs:24:28:24:47 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:24:28:24:47 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:24:28:24:47 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:24:28:24:47 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:26:34:26:41 | response | semmle.label | response |
+| glob_prelude.rs:30:29:30:45 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:31:9:31:11 | res | semmle.label | res |
+| glob_prelude.rs:31:15:31:17 | req | semmle.label | req |
+| glob_prelude.rs:31:15:31:21 | req.url | semmle.label | req.url |
+| glob_prelude.rs:31:15:31:28 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:32:9:32:16 | response | semmle.label | response |
+| glob_prelude.rs:32:28:32:47 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:32:28:32:47 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:32:28:32:47 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:32:28:32:47 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:34:49:34:56 | response | semmle.label | response |
+| glob_prelude.rs:37:22:37:38 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:38:9:38:13 | query | semmle.label | query |
+| glob_prelude.rs:38:17:38:19 | req | semmle.label | req |
+| glob_prelude.rs:38:17:38:23 | req.url | semmle.label | req.url |
+| glob_prelude.rs:38:17:38:31 | ... .query() | semmle.label | ... .query() |
+| glob_prelude.rs:38:17:38:45 | ... .unwrap_or(...) | semmle.label | ... .unwrap_or(...) |
+| glob_prelude.rs:39:9:39:16 | response | semmle.label | response |
+| glob_prelude.rs:39:28:39:45 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:39:28:39:45 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:39:28:39:45 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:39:28:39:45 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:41:36:41:43 | response | semmle.label | response |
+| glob_prelude.rs:44:25:44:41 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:45:9:45:12 | path | semmle.label | path |
+| glob_prelude.rs:45:16:45:18 | req | semmle.label | req |
+| glob_prelude.rs:45:16:45:22 | req.url | semmle.label | req.url |
+| glob_prelude.rs:45:16:45:29 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:46:9:46:12 | path | semmle.label | path |
+| glob_prelude.rs:46:16:46:19 | path | semmle.label | path |
+| glob_prelude.rs:46:16:46:29 | path.join(...) | semmle.label | path.join(...) |
+| glob_prelude.rs:47:9:47:16 | response | semmle.label | response |
+| glob_prelude.rs:47:28:47:46 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:47:28:47:46 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:47:28:47:46 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:47:28:47:46 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:49:36:49:43 | response | semmle.label | response |
+| glob_prelude.rs:109:16:109:32 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:111:13:111:16 | name | semmle.label | name |
+| glob_prelude.rs:111:20:111:22 | req | semmle.label | req |
+| glob_prelude.rs:111:20:111:26 | req.url | semmle.label | req.url |
+| glob_prelude.rs:111:20:111:33 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:112:40:112:69 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:112:48:112:68 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:112:48:112:68 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:112:48:112:68 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:112:48:112:68 | { ... } | semmle.label | { ... } |
| main.rs:5:16:5:32 | ...: ... | semmle.label | ...: ... |
| main.rs:6:9:6:11 | res | semmle.label | res |
| main.rs:6:15:6:21 | req.url | semmle.label | req.url |
@@ -189,8 +349,25 @@ nodes
| 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 |
+| main.rs:149:29:149:45 | ...: ... | semmle.label | ...: ... |
+| main.rs:150:9:150:11 | res | semmle.label | res |
+| main.rs:150:15:150:21 | req.url | semmle.label | req.url |
+| main.rs:150:15:150:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:151:9:151:16 | response | semmle.label | response |
+| main.rs:151:28:151:55 | ...::format(...) | semmle.label | ...::format(...) |
+| main.rs:151:28:151:55 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| main.rs:151:28:151:55 | MacroExpr | semmle.label | MacroExpr |
+| main.rs:151:28:151:55 | { ... } | semmle.label | { ... } |
+| main.rs:154:36:154:43 | response | semmle.label | response |
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 |
+| glob_prelude.rs:19:23:19:49 | MacroExpr | glob_prelude.rs:16:26:16:42 | ...: ... | glob_prelude.rs:19:23:19:49 | MacroExpr | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:16:26:16:42 | ...: ... | user-provided value |
+| glob_prelude.rs:26:34:26:41 | response | glob_prelude.rs:22:28:22:44 | ...: ... | glob_prelude.rs:26:34:26:41 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:22:28:22:44 | ...: ... | user-provided value |
+| glob_prelude.rs:34:49:34:56 | response | glob_prelude.rs:30:29:30:45 | ...: ... | glob_prelude.rs:34:49:34:56 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:30:29:30:45 | ...: ... | user-provided value |
+| glob_prelude.rs:41:36:41:43 | response | glob_prelude.rs:37:22:37:38 | ...: ... | glob_prelude.rs:41:36:41:43 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:37:22:37:38 | ...: ... | user-provided value |
+| glob_prelude.rs:49:36:49:43 | response | glob_prelude.rs:44:25:44:41 | ...: ... | glob_prelude.rs:49:36:49:43 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:44:25:44:41 | ...: ... | user-provided value |
+| glob_prelude.rs:112:40:112:69 | MacroExpr | glob_prelude.rs:109:16:109:32 | ...: ... | glob_prelude.rs:112:40:112:69 | MacroExpr | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:109:16:109:32 | ...: ... | 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 |
@@ -200,3 +377,4 @@ subpaths
| 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 |
+| 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 |
diff --git a/rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs b/rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs
new file mode 100644
index 00000000..4b060a6e
--- /dev/null
+++ b/rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs
@@ -0,0 +1,116 @@
+use iron::prelude::*;
+use iron::status;
+
+// Every call into `iron` here goes through the glob import of the prelude, and nothing in this file
+// imports the same names explicitly. The extraction of such code leaves the calls without a target
+// (see `GlobCalls.ql`), so the data extension rows and the calls that match canonical paths do not
+// apply and the queries have to recognize the API by its names.
+
+fn bad_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Hello, {:?}!
", res);
+ // BAD: the request path is formatted into markup and returned without a content type.
+ Ok(Response::with((status::Ok, response)))
+}
+
+fn bad_body_only_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ // BAD: a body modifier on its own is also served without a `Content-Type`.
+ Ok(Response::with(format!("{:?}
", res)))
+}
+
+fn bad_named_tuple_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("{:?}
", res);
+ // BAD: the tuple is built first and passed to `Response::with` later.
+ let modifiers = (status::Ok, response);
+ Ok(Response::with(modifiers))
+}
+
+fn bad_nested_tuple_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("{:?}
", res);
+ // BAD: modifier tuples nest, and the body is in the inner tuple.
+ Ok(Response::with((status::Ok, (status::Ok, response))))
+}
+
+fn bad_query_handler(req: &mut Request) -> IronResult {
+ let query = req.url.query().unwrap_or("");
+ let response = format!("{}
", query);
+ // BAD: the query string is a user-controlled source as well.
+ Ok(Response::with((status::Ok, response)))
+}
+
+fn bad_shadowed_handler(req: &mut Request) -> IronResult {
+ let path = req.url.path();
+ let path = path.join("/");
+ let response = format!("{}
", path);
+ // BAD: the value goes through another method that has no target.
+ Ok(Response::with((status::Ok, response)))
+}
+
+fn good_constant_handler(_req: &mut Request) -> IronResult {
+ // GOOD: no user input in the body.
+ Ok(Response::with((status::Ok, "Hello
")))
+}
+
+fn good_length_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("{}", res.len());
+ // GOOD: only the length of the path is written.
+ Ok(Response::with((status::Ok, response)))
+}
+
+fn good_plain_text_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("{:?}
", res);
+ // GOOD: an explicit `text/plain` content type is set.
+ let plain: iron::mime::Mime = "text/plain".parse().unwrap();
+ Ok(Response::with((status::Ok, plain, response)))
+}
+
+fn good_other_request_handler(request: &str) -> IronResult {
+ let response = format!("{}
", request);
+ // GOOD: the parameter is not an Iron request, so it is not a source.
+ Ok(Response::with((status::Ok, response)))
+}
+
+fn good_encoded_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path().join("/").escape_default().to_string();
+ let response = format!("{}
", res);
+ // GOOD: the value goes through a method with `escape` in its name, which is taken to encode it, the
+ // way the standard queries take a call of a function with such a name.
+ Ok(Response::with((status::Ok, response)))
+}
+
+use sanitizer::clean;
+
+fn good_sanitized_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("{:?}
", res);
+ // GOOD: a function sanitizes the body. The call has no target, and the analysis does not follow
+ // data through a call that it cannot resolve.
+ let sanitized = clean(&response);
+ Ok(Response::with((status::Ok, sanitized)))
+}
+
+pub fn main() {
+ Iron::new(bad_handler).http("localhost:3000").unwrap();
+ Iron::new(bad_body_only_handler).http("localhost:3001").unwrap();
+ Iron::new(bad_named_tuple_handler).http("localhost:3002").unwrap();
+ Iron::new(bad_nested_tuple_handler).http("localhost:3003").unwrap();
+ Iron::new(bad_query_handler).http("localhost:3004").unwrap();
+ Iron::new(bad_shadowed_handler).http("localhost:3005").unwrap();
+ Iron::new(good_constant_handler).http("localhost:3006").unwrap();
+ Iron::new(good_length_handler).http("localhost:3007").unwrap();
+ Iron::new(good_plain_text_handler).http("localhost:3008").unwrap();
+ Iron::new(good_encoded_handler).http("localhost:3010").unwrap();
+ Iron::new(good_sanitized_handler).http("localhost:3011").unwrap();
+ Iron::new(|req: &mut Request| {
+ // BAD: a closure handler, with the request in its parameter.
+ let name = req.url.path();
+ Ok(Response::with((status::Ok, format!("{:?}
", name))))
+ })
+ .http("localhost:3009")
+ .unwrap();
+}
diff --git a/rust/test/security/CWE-079/IronResponseXss/main.rs b/rust/test/security/CWE-079/IronResponseXss/main.rs
index 3f57120b..d9fd0be1 100644
--- a/rust/test/security/CWE-079/IronResponseXss/main.rs
+++ b/rust/test/security/CWE-079/IronResponseXss/main.rs
@@ -145,3 +145,11 @@ fn missed_field_assigned_later_handler(req: &mut Request) -> IronResult IronResult {
+ let res = req.url.path();
+ let response = format!("Hello, {:?}!
", res);
+ // BAD: no call of `Iron::new` or `Chain::new` in this file passes the handler on (a router, for
+ // example, registers it), and a function that takes a request is a handler all the same.
+ Ok(Response::with((status::Ok, response)))
+}
diff --git a/rust/test/security/CWE-079/IronResponseXss/other_framework.rs b/rust/test/security/CWE-079/IronResponseXss/other_framework.rs
new file mode 100644
index 00000000..db0f21dd
--- /dev/null
+++ b/rust/test/security/CWE-079/IronResponseXss/other_framework.rs
@@ -0,0 +1,12 @@
+use web_framework::prelude::*;
+
+// Not an Iron program: the file does not use `iron`, and the crate that it imports from is not a
+// dependency, so every call below has no target as well. The names are the same as in Iron, and the
+// file must not be treated as one.
+
+fn handler(req: &mut Request) -> Response {
+ let res = req.url.path();
+ let response = format!("{:?}
", res);
+ // GOOD for this query: the file does not use `iron`.
+ Response::with((200, response))
+}
From b88b9f6313e9327836dc0b6fe8dbf182d5dc1098 Mon Sep 17 00:00:00 2001
From: Chad Bentz <1760475+felickz@users.noreply.github.com>
Date: Wed, 25 Nov 2026 13:22:56 -0500
Subject: [PATCH 2/2] 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
---
rust/src/common/IronFallback.qll | 16 ++-
.../security/CWE-079/IronResponseXss.qhelp | 12 +-
rust/src/security/CWE-079/IronResponseXss.ql | 27 ++++-
.../IronResponseXss/GlobCalls.expected | 55 +++++----
.../IronResponseXss/IronModels.expected | 1 +
.../IronResponseXss/IronResponseXss.expected | 107 ++++++++++++++----
.../CWE-079/IronResponseXss/glob_prelude.rs | 15 ++-
.../security/CWE-079/IronResponseXss/main.rs | 8 ++
8 files changed, 185 insertions(+), 56 deletions(-)
diff --git a/rust/src/common/IronFallback.qll b/rust/src/common/IronFallback.qll
index 9c16c4ed..d3f79fff 100644
--- a/rust/src/common/IronFallback.qll
+++ b/rust/src/common/IronFallback.qll
@@ -66,12 +66,22 @@ private predicate isNonRevealingMethod(string name) {
]
}
+/**
+ * Holds if the method called `name` says that it escapes or encodes for HTML, such as `escape_html` or
+ * `html_escape`. A name that only says `escape_default` or `encode`, or that undoes the encoding
+ * (`unescape_html`), does not make a value safe for HTML.
+ */
+bindingset[name]
+private predicate isHtmlEncodingMethod(string name) {
+ name.toLowerCase().regexpMatch("(escape|encode)_?html\\w*|html_?(escape|encode)\\w*")
+}
+
/**
* Holds if the flow goes from `pred` to `succ` in a file that uses `iron`, where the data flow library
* cannot know it because the type of `pred` is not known: `succ` is the read of a field of the
* request that does not resolve to a field, or the result of a method that has no target, called on
- * `pred`. A method with `escape` or `encode` in its name is taken to encode the value, the way the
- * standard queries take a call of a function with such a name, so it does not pass the value on.
+ * `pred`. A method that says that it encodes for HTML (`escape_html`) is taken to do so, so it does not
+ * pass the value on.
*/
predicate ironUnresolvedStep(DataFlow::Node pred, DataFlow::Node succ) {
exists(FieldExpr field |
@@ -86,7 +96,7 @@ predicate ironUnresolvedStep(DataFlow::Node pred, DataFlow::Node succ) {
isIronFile(call.getLocation().getFile()) and
not exists(call.getStaticTarget()) and
not isNonRevealingMethod(call.getIdentifier().getText()) and
- not call.getIdentifier().getText().regexpMatch(".*(escape|encode).*") and
+ not isHtmlEncodingMethod(call.getIdentifier().getText()) and
pred.asExpr() = call.getReceiver() and
succ.asExpr() = call
)
diff --git a/rust/src/security/CWE-079/IronResponseXss.qhelp b/rust/src/security/CWE-079/IronResponseXss.qhelp
index 9ce83b97..01e1cbe7 100644
--- a/rust/src/security/CWE-079/IronResponseXss.qhelp
+++ b/rust/src/security/CWE-079/IronResponseXss.qhelp
@@ -71,10 +71,14 @@ not tracked.
When the calls have no target, the query goes by names and only looks at files that use
iron. It follows the result of every method that is called on the request and has no
target, except for a few that only tell a property of the value, such as len and
-is_empty, and for names that contain escape or encode, which are
-taken to encode the value. A method that encodes the value under another name 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.
+is_empty, and for names that say that they escape or encode for HTML, such as
+escape_html, which are taken to do so. A method that encodes the value under another name
+(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.
diff --git a/rust/src/security/CWE-079/IronResponseXss.ql b/rust/src/security/CWE-079/IronResponseXss.ql
index 14a919a6..3cccdb66 100644
--- a/rust/src/security/CWE-079/IronResponseXss.ql
+++ b/rust/src/security/CWE-079/IronResponseXss.ql
@@ -148,13 +148,32 @@ 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).
+ */
+class IronResolvedResponseBody extends DataFlow::Node {
+ IronResolvedResponseBody() {
+ exists(Call call, Expr argument |
+ call.getStaticTarget().getCanonicalPath() = "::with" and
+ argument = call.getPositionalArgument(0) and
+ not holdsTuple(argument, _) and
+ this.asExpr() = argument
+ )
+ }
+}
+
module IronResponseXssConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) {
node instanceof Xss::Source or node instanceof IronRequestParameter
}
predicate isSink(DataFlow::Node node) {
- node instanceof IronResponseModifierTupleElement or node instanceof IronUnresolvedResponseBody
+ node instanceof IronResponseModifierTupleElement or
+ node instanceof IronUnresolvedResponseBody or
+ node instanceof IronResolvedResponseBody
}
predicate isBarrier(DataFlow::Node barrier) { barrier instanceof Xss::Barrier }
@@ -181,6 +200,12 @@ where
IronResponseXssFlow::flowPath(modelled, sinkNode) and
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.
+ not (
+ sinkNode.getNode() instanceof IronResolvedResponseBody and
+ sourceNode.getNode() instanceof Xss::Source
)
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/GlobCalls.expected b/rust/test/security/CWE-079/IronResponseXss/GlobCalls.expected
index cc9ae4fd..fe1ab507 100644
--- a/rust/test/security/CWE-079/IronResponseXss/GlobCalls.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/GlobCalls.expected
@@ -23,28 +23,14 @@
| 79 | ... .join(...) |
| 79 | ... .path() |
| 79 | ... .to_string() |
-| 83 | ...::with(...) |
-| 89 | ... .path() |
-| 93 | clean(...) |
-| 94 | ...::with(...) |
-| 98 | ... .http(...) |
-| 98 | ... .unwrap() |
-| 98 | ...::new(...) |
-| 99 | ... .http(...) |
-| 99 | ... .unwrap() |
-| 99 | ...::new(...) |
-| 100 | ... .http(...) |
-| 100 | ... .unwrap() |
-| 100 | ...::new(...) |
-| 101 | ... .http(...) |
-| 101 | ... .unwrap() |
-| 101 | ...::new(...) |
-| 102 | ... .http(...) |
-| 102 | ... .unwrap() |
-| 102 | ...::new(...) |
-| 103 | ... .http(...) |
-| 103 | ... .unwrap() |
-| 103 | ...::new(...) |
+| 82 | ...::with(...) |
+| 86 | ... .escape_html() |
+| 86 | ... .join(...) |
+| 86 | ... .path() |
+| 89 | ...::with(...) |
+| 95 | ... .path() |
+| 99 | clean(...) |
+| 100 | ...::with(...) |
| 104 | ... .http(...) |
| 104 | ... .unwrap() |
| 104 | ...::new(...) |
@@ -63,5 +49,26 @@
| 109 | ... .http(...) |
| 109 | ... .unwrap() |
| 109 | ...::new(...) |
-| 111 | ... .path() |
-| 112 | ...::with(...) |
+| 110 | ... .http(...) |
+| 110 | ... .unwrap() |
+| 110 | ...::new(...) |
+| 111 | ... .http(...) |
+| 111 | ... .unwrap() |
+| 111 | ...::new(...) |
+| 112 | ... .http(...) |
+| 112 | ... .unwrap() |
+| 112 | ...::new(...) |
+| 113 | ... .http(...) |
+| 113 | ... .unwrap() |
+| 113 | ...::new(...) |
+| 114 | ... .http(...) |
+| 114 | ... .unwrap() |
+| 114 | ...::new(...) |
+| 115 | ... .http(...) |
+| 115 | ... .unwrap() |
+| 115 | ...::new(...) |
+| 116 | ... .http(...) |
+| 116 | ... .unwrap() |
+| 116 | ...::new(...) |
+| 118 | ... .path() |
+| 119 | ...::with(...) |
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
index 35240a4e..cdb18e3c 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronModels.expected
@@ -30,3 +30,4 @@
| main.rs:136:15:136:49 | missed_field_assigned_later_handler | remote source |
| 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 |
diff --git a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
index 63101271..0e18d72a 100644
--- a/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
+++ b/rust/test/security/CWE-079/IronResponseXss/IronResponseXss.expected
@@ -62,15 +62,28 @@ edges
| glob_prelude.rs:47:28:47:46 | ...::must_use(...) | glob_prelude.rs:47:9:47:16 | response | provenance | |
| glob_prelude.rs:47:28:47:46 | MacroExpr | glob_prelude.rs:47:28:47:46 | ...::format(...) | provenance | MaD:371 |
| glob_prelude.rs:47:28:47:46 | { ... } | glob_prelude.rs:47:28:47:46 | ...::must_use(...) | provenance | MaD:13380 |
-| glob_prelude.rs:109:16:109:32 | ...: ... | glob_prelude.rs:111:20:111:22 | req | provenance | |
-| glob_prelude.rs:111:13:111:16 | name | glob_prelude.rs:112:48:112:68 | MacroExpr | provenance | |
-| glob_prelude.rs:111:20:111:22 | req | glob_prelude.rs:111:20:111:26 | req.url | provenance | Config |
-| glob_prelude.rs:111:20:111:26 | req.url | glob_prelude.rs:111:20:111:33 | ... .path() | provenance | Config |
-| glob_prelude.rs:111:20:111:33 | ... .path() | glob_prelude.rs:111:13:111:16 | name | provenance | |
-| glob_prelude.rs:112:48:112:68 | ...::format(...) | glob_prelude.rs:112:48:112:68 | { ... } | provenance | |
-| glob_prelude.rs:112:48:112:68 | ...::must_use(...) | glob_prelude.rs:112:40:112:69 | MacroExpr | provenance | |
-| glob_prelude.rs:112:48:112:68 | MacroExpr | glob_prelude.rs:112:48:112:68 | ...::format(...) | provenance | MaD:371 |
-| glob_prelude.rs:112:48:112:68 | { ... } | glob_prelude.rs:112:48:112:68 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:78:31:78:47 | ...: ... | glob_prelude.rs:79:15:79:17 | req | provenance | |
+| glob_prelude.rs:79:9:79:11 | res | glob_prelude.rs:80:28:80:45 | MacroExpr | provenance | |
+| glob_prelude.rs:79:15:79:17 | req | glob_prelude.rs:79:15:79:21 | req.url | provenance | Config |
+| glob_prelude.rs:79:15:79:21 | req.url | glob_prelude.rs:79:15:79:28 | ... .path() | provenance | Config |
+| glob_prelude.rs:79:15:79:28 | ... .path() | glob_prelude.rs:79:15:79:38 | ... .join(...) | provenance | Config |
+| glob_prelude.rs:79:15:79:38 | ... .join(...) | glob_prelude.rs:79:15:79:55 | ... .escape_default() | provenance | Config |
+| glob_prelude.rs:79:15:79:55 | ... .escape_default() | glob_prelude.rs:79:15:79:67 | ... .to_string() | provenance | Config |
+| glob_prelude.rs:79:15:79:67 | ... .to_string() | glob_prelude.rs:79:9:79:11 | res | provenance | |
+| glob_prelude.rs:80:9:80:16 | response | glob_prelude.rs:82:36:82:43 | response | provenance | |
+| glob_prelude.rs:80:28:80:45 | ...::format(...) | glob_prelude.rs:80:28:80:45 | { ... } | provenance | |
+| glob_prelude.rs:80:28:80:45 | ...::must_use(...) | glob_prelude.rs:80:9:80:16 | response | provenance | |
+| glob_prelude.rs:80:28:80:45 | MacroExpr | glob_prelude.rs:80:28:80:45 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:80:28:80:45 | { ... } | glob_prelude.rs:80:28:80:45 | ...::must_use(...) | provenance | MaD:13380 |
+| glob_prelude.rs:116:16:116:32 | ...: ... | glob_prelude.rs:118:20:118:22 | req | provenance | |
+| glob_prelude.rs:118:13:118:16 | name | glob_prelude.rs:119:48:119:68 | MacroExpr | provenance | |
+| glob_prelude.rs:118:20:118:22 | req | glob_prelude.rs:118:20:118:26 | req.url | provenance | Config |
+| glob_prelude.rs:118:20:118:26 | req.url | glob_prelude.rs:118:20:118:33 | ... .path() | provenance | Config |
+| glob_prelude.rs:118:20:118:33 | ... .path() | glob_prelude.rs:118:13:118:16 | name | provenance | |
+| glob_prelude.rs:119:48:119:68 | ...::format(...) | glob_prelude.rs:119:48:119:68 | { ... } | provenance | |
+| glob_prelude.rs:119:48:119:68 | ...::must_use(...) | glob_prelude.rs:119:40:119:69 | MacroExpr | provenance | |
+| glob_prelude.rs:119:48:119:68 | MacroExpr | glob_prelude.rs:119:48:119:68 | ...::format(...) | provenance | MaD:371 |
+| glob_prelude.rs:119:48:119:68 | { ... } | glob_prelude.rs:119:48:119:68 | ...::must_use(...) | provenance | MaD:13380 |
| main.rs:5:16:5:32 | ...: ... | main.rs:6:15:6:21 | req.url | provenance | |
| main.rs:6:9:6:11 | res | main.rs:8:28:8:68 | MacroExpr | provenance | |
| main.rs:6:15:6:21 | req.url | main.rs:6:15:6:28 | ... .path() | provenance | MaD:17587 |
@@ -80,6 +93,14 @@ edges
| main.rs:8:28:8:68 | ...::must_use(...) | main.rs:8:9:8:16 | response | provenance | |
| main.rs:8:28:8:68 | MacroExpr | main.rs:8:28:8:68 | ...::format(...) | provenance | MaD:371 |
| main.rs:8:28:8:68 | { ... } | main.rs:8:28:8:68 | ...::must_use(...) | provenance | MaD:13380 |
+| 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 | |
+| 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:44:20:44:36 | ...: ... | main.rs:45:19:45:25 | req.url | provenance | |
| main.rs:45:13:45:15 | res | main.rs:46:32:46:72 | MacroExpr | provenance | |
| main.rs:45:19:45:25 | req.url | main.rs:45:19:45:32 | ... .path() | provenance | MaD:17587 |
@@ -153,6 +174,7 @@ edges
| 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:123:26:123:46 | bad_body_only_handler | main.rs:12:26:12:42 | ...: ... | provenance | Src:MaD:17585 |
| 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 |
@@ -170,6 +192,15 @@ edges
| main.rs:151:28:151:55 | ...::must_use(...) | main.rs:151:9:151:16 | response | provenance | |
| main.rs:151:28:151:55 | MacroExpr | main.rs:151:28:151:55 | ...::format(...) | provenance | MaD:371 |
| main.rs:151:28:151:55 | { ... } | main.rs:151:28:151:55 | ...::must_use(...) | provenance | MaD:13380 |
+| main.rs:157:39:157:55 | ...: ... | main.rs:158:15:158:21 | req.url | provenance | |
+| main.rs:158:9:158:11 | res | main.rs:159:28:159:55 | MacroExpr | provenance | |
+| main.rs:158:15:158:21 | req.url | main.rs:158:15:158:28 | ... .path() | provenance | MaD:17587 |
+| main.rs:158:15:158:28 | ... .path() | main.rs:158:9:158:11 | res | provenance | |
+| main.rs:159:9:159:16 | response | main.rs:162:23:162:30 | response | provenance | |
+| main.rs:159:28:159:55 | ...::format(...) | main.rs:159:28:159:55 | { ... } | provenance | |
+| 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 |
nodes
| glob_prelude.rs:9:16:9:32 | ...: ... | semmle.label | ...: ... |
| glob_prelude.rs:10:9:10:11 | res | semmle.label | res |
@@ -240,16 +271,30 @@ nodes
| glob_prelude.rs:47:28:47:46 | MacroExpr | semmle.label | MacroExpr |
| glob_prelude.rs:47:28:47:46 | { ... } | semmle.label | { ... } |
| glob_prelude.rs:49:36:49:43 | response | semmle.label | response |
-| glob_prelude.rs:109:16:109:32 | ...: ... | semmle.label | ...: ... |
-| glob_prelude.rs:111:13:111:16 | name | semmle.label | name |
-| glob_prelude.rs:111:20:111:22 | req | semmle.label | req |
-| glob_prelude.rs:111:20:111:26 | req.url | semmle.label | req.url |
-| glob_prelude.rs:111:20:111:33 | ... .path() | semmle.label | ... .path() |
-| glob_prelude.rs:112:40:112:69 | MacroExpr | semmle.label | MacroExpr |
-| glob_prelude.rs:112:48:112:68 | ...::format(...) | semmle.label | ...::format(...) |
-| glob_prelude.rs:112:48:112:68 | ...::must_use(...) | semmle.label | ...::must_use(...) |
-| glob_prelude.rs:112:48:112:68 | MacroExpr | semmle.label | MacroExpr |
-| glob_prelude.rs:112:48:112:68 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:78:31:78:47 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:79:9:79:11 | res | semmle.label | res |
+| glob_prelude.rs:79:15:79:17 | req | semmle.label | req |
+| glob_prelude.rs:79:15:79:21 | req.url | semmle.label | req.url |
+| glob_prelude.rs:79:15:79:28 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:79:15:79:38 | ... .join(...) | semmle.label | ... .join(...) |
+| glob_prelude.rs:79:15:79:55 | ... .escape_default() | semmle.label | ... .escape_default() |
+| glob_prelude.rs:79:15:79:67 | ... .to_string() | semmle.label | ... .to_string() |
+| glob_prelude.rs:80:9:80:16 | response | semmle.label | response |
+| glob_prelude.rs:80:28:80:45 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:80:28:80:45 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:80:28:80:45 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:80:28:80:45 | { ... } | semmle.label | { ... } |
+| glob_prelude.rs:82:36:82:43 | response | semmle.label | response |
+| glob_prelude.rs:116:16:116:32 | ...: ... | semmle.label | ...: ... |
+| glob_prelude.rs:118:13:118:16 | name | semmle.label | name |
+| glob_prelude.rs:118:20:118:22 | req | semmle.label | req |
+| glob_prelude.rs:118:20:118:26 | req.url | semmle.label | req.url |
+| glob_prelude.rs:118:20:118:33 | ... .path() | semmle.label | ... .path() |
+| glob_prelude.rs:119:40:119:69 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:119:48:119:68 | ...::format(...) | semmle.label | ...::format(...) |
+| glob_prelude.rs:119:48:119:68 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| glob_prelude.rs:119:48:119:68 | MacroExpr | semmle.label | MacroExpr |
+| glob_prelude.rs:119:48:119:68 | { ... } | semmle.label | { ... } |
| main.rs:5:16:5:32 | ...: ... | semmle.label | ...: ... |
| main.rs:6:9:6:11 | res | semmle.label | res |
| main.rs:6:15:6:21 | req.url | semmle.label | req.url |
@@ -260,6 +305,15 @@ nodes
| main.rs:8:28:8:68 | MacroExpr | semmle.label | MacroExpr |
| main.rs:8:28:8:68 | { ... } | semmle.label | { ... } |
| main.rs:9:36:9:43 | response | semmle.label | response |
+| 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:44:20:44:36 | ...: ... | semmle.label | ...: ... |
| main.rs:45:13:45:15 | res | semmle.label | res |
| main.rs:45:19:45:25 | req.url | semmle.label | req.url |
@@ -341,6 +395,7 @@ nodes
| 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:123:26:123:46 | bad_body_only_handler | semmle.label | bad_body_only_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 |
@@ -359,6 +414,16 @@ nodes
| main.rs:151:28:151:55 | MacroExpr | semmle.label | MacroExpr |
| main.rs:151:28:151:55 | { ... } | semmle.label | { ... } |
| main.rs:154:36:154:43 | response | semmle.label | response |
+| main.rs:157:39:157:55 | ...: ... | semmle.label | ...: ... |
+| main.rs:158:9:158:11 | res | semmle.label | res |
+| main.rs:158:15:158:21 | req.url | semmle.label | req.url |
+| main.rs:158:15:158:28 | ... .path() | semmle.label | ... .path() |
+| main.rs:159:9:159:16 | response | semmle.label | response |
+| main.rs:159:28:159:55 | ...::format(...) | semmle.label | ...::format(...) |
+| main.rs:159:28:159:55 | ...::must_use(...) | semmle.label | ...::must_use(...) |
+| 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 |
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 |
@@ -367,7 +432,8 @@ subpaths
| glob_prelude.rs:34:49:34:56 | response | glob_prelude.rs:30:29:30:45 | ...: ... | glob_prelude.rs:34:49:34:56 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:30:29:30:45 | ...: ... | user-provided value |
| glob_prelude.rs:41:36:41:43 | response | glob_prelude.rs:37:22:37:38 | ...: ... | glob_prelude.rs:41:36:41:43 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:37:22:37:38 | ...: ... | user-provided value |
| glob_prelude.rs:49:36:49:43 | response | glob_prelude.rs:44:25:44:41 | ...: ... | glob_prelude.rs:49:36:49:43 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:44:25:44:41 | ...: ... | user-provided value |
-| glob_prelude.rs:112:40:112:69 | MacroExpr | glob_prelude.rs:109:16:109:32 | ...: ... | glob_prelude.rs:112:40:112:69 | MacroExpr | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:109:16:109:32 | ...: ... | user-provided value |
+| glob_prelude.rs:82:36:82:43 | response | glob_prelude.rs:78:31:78:47 | ...: ... | glob_prelude.rs:82:36:82:43 | response | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:78:31:78:47 | ...: ... | user-provided value |
+| glob_prelude.rs:119:40:119:69 | MacroExpr | glob_prelude.rs:116:16:116:32 | ...: ... | glob_prelude.rs:119:40:119:69 | MacroExpr | Cross-site scripting vulnerability due to a $@. | glob_prelude.rs:116:16:116:32 | ...: ... | 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 |
@@ -378,3 +444,4 @@ subpaths
| 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 |
| 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 |
diff --git a/rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs b/rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs
index 4b060a6e..02f40a5a 100644
--- a/rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs
+++ b/rust/test/security/CWE-079/IronResponseXss/glob_prelude.rs
@@ -75,11 +75,17 @@ fn good_other_request_handler(request: &str) -> IronResult {
Ok(Response::with((status::Ok, response)))
}
-fn good_encoded_handler(req: &mut Request) -> IronResult {
+fn bad_escape_default_handler(req: &mut Request) -> IronResult {
let res = req.url.path().join("/").escape_default().to_string();
let response = format!("{}
", res);
- // GOOD: the value goes through a method with `escape` in its name, which is taken to encode it, the
- // way the standard queries take a call of a function with such a name.
+ // BAD: `escape_default` keeps `<` and `>`, so it does not make the value safe for HTML.
+ Ok(Response::with((status::Ok, response)))
+}
+
+fn good_html_escaped_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path().join("/").escape_html();
+ let response = format!("{}
", res);
+ // GOOD: the method says that it escapes for HTML, and it is taken to do so.
Ok(Response::with((status::Ok, response)))
}
@@ -104,7 +110,8 @@ pub fn main() {
Iron::new(good_constant_handler).http("localhost:3006").unwrap();
Iron::new(good_length_handler).http("localhost:3007").unwrap();
Iron::new(good_plain_text_handler).http("localhost:3008").unwrap();
- Iron::new(good_encoded_handler).http("localhost:3010").unwrap();
+ Iron::new(bad_escape_default_handler).http("localhost:3010").unwrap();
+ Iron::new(good_html_escaped_handler).http("localhost:3012").unwrap();
Iron::new(good_sanitized_handler).http("localhost:3011").unwrap();
Iron::new(|req: &mut Request| {
// BAD: a closure handler, with the request in its parameter.
diff --git a/rust/test/security/CWE-079/IronResponseXss/main.rs b/rust/test/security/CWE-079/IronResponseXss/main.rs
index d9fd0be1..8b9f1aad 100644
--- a/rust/test/security/CWE-079/IronResponseXss/main.rs
+++ b/rust/test/security/CWE-079/IronResponseXss/main.rs
@@ -153,3 +153,11 @@ fn bad_unregistered_handler(req: &mut Request) -> IronResult {
// example, registers it), and a function that takes a request is a handler all the same.
Ok(Response::with((status::Ok, response)))
}
+
+fn bad_unregistered_body_only_handler(req: &mut Request) -> IronResult {
+ let res = req.url.path();
+ let response = format!("Hello, {:?}!
", res);
+ // BAD: a body on its own, from a handler that nothing registers in this file. The call resolves, but
+ // the standard query has no source for the handler, so this query reports it.
+ Ok(Response::with(response))
+}