Skip to content

Commit 2da3943

Browse files
committed
feat(python): Update XSS Audit query and tests
1 parent 31aaec7 commit 2da3943

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

python/src/audit/CWE-079/XssFlaskAudit.ql

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515

1616
import python
17-
import DataFlow::PathGraph
1817
import semmle.python.Concepts
1918
import semmle.python.ApiGraphs
2019
import semmle.python.dataflow.new.DataFlow
@@ -33,17 +32,19 @@ class DynamicTemplate extends DataFlow::Node {
3332
}
3433
}
3534

36-
class Configuration extends TaintTracking::Configuration {
37-
Configuration() { this = "AuditXSSJinja2" }
35+
module Configuration implements DataFlow::ConfigSig {
36+
predicate isSource(DataFlow::Node source) { source instanceof ReflectedXss::Source }
3837

39-
override predicate isSource(DataFlow::Node source) { source instanceof ReflectedXss::Source }
38+
predicate isSink(DataFlow::Node sink) { sink instanceof DynamicTemplate }
4039

41-
override predicate isSink(DataFlow::Node sink) { sink instanceof DynamicTemplate }
42-
43-
override predicate isSanitizer(DataFlow::Node node) { node instanceof ReflectedXss::Sanitizer }
40+
predicate isBarrier(DataFlow::Node node) { node instanceof ReflectedXss::Sanitizer }
4441
}
4542

46-
from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
47-
where config.hasFlowPath(source, sink)
43+
module ConfigurationFlow = TaintTracking::Global<Configuration>;
44+
45+
import ConfigurationFlow::PathGraph //importing the path graph from the module
46+
47+
from ConfigurationFlow::PathNode source, ConfigurationFlow::PathNode sink
48+
where ConfigurationFlow::flowPath(source, sink)
4849
select sink.getNode(), source, sink, "Cross-site scripting vulnerability due to a $@.",
4950
source.getNode(), "user-provided value"

python/test/audit/CWE-079/XssFlaskAudit.expected

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
edges
2-
| app.py:1:26:1:32 | ControlFlowNode for ImportMember | app.py:1:26:1:32 | GSSA Variable request |
3-
| app.py:1:26:1:32 | GSSA Variable request | app.py:12:16:12:22 | ControlFlowNode for request |
4-
| app.py:12:16:12:22 | ControlFlowNode for request | app.py:12:16:12:27 | ControlFlowNode for Attribute |
5-
| app.py:12:16:12:27 | ControlFlowNode for Attribute | app.py:12:16:12:39 | ControlFlowNode for Subscript |
6-
| app.py:12:16:12:39 | ControlFlowNode for Subscript | app.py:14:51:14:58 | ControlFlowNode for username |
2+
| app.py:1:26:1:32 | ControlFlowNode for ImportMember | app.py:1:26:1:32 | ControlFlowNode for request |
3+
| app.py:1:26:1:32 | ControlFlowNode for request | app.py:12:16:12:22 | ControlFlowNode for request |
4+
| app.py:12:5:12:12 | ControlFlowNode for username | app.py:14:51:14:58 | ControlFlowNode for username |
5+
| app.py:12:16:12:22 | ControlFlowNode for request | app.py:12:5:12:12 | ControlFlowNode for username |
76
nodes
87
| app.py:1:26:1:32 | ControlFlowNode for ImportMember | semmle.label | ControlFlowNode for ImportMember |
9-
| app.py:1:26:1:32 | GSSA Variable request | semmle.label | GSSA Variable request |
8+
| app.py:1:26:1:32 | ControlFlowNode for request | semmle.label | ControlFlowNode for request |
9+
| app.py:12:5:12:12 | ControlFlowNode for username | semmle.label | ControlFlowNode for username |
1010
| app.py:12:16:12:22 | ControlFlowNode for request | semmle.label | ControlFlowNode for request |
11-
| app.py:12:16:12:27 | ControlFlowNode for Attribute | semmle.label | ControlFlowNode for Attribute |
12-
| app.py:12:16:12:39 | ControlFlowNode for Subscript | semmle.label | ControlFlowNode for Subscript |
1311
| app.py:14:51:14:58 | ControlFlowNode for username | semmle.label | ControlFlowNode for username |
1412
subpaths
1513
#select

0 commit comments

Comments
 (0)