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