Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcd9608

Browse files
committed
Python: Move StackTraceExposure to new dataflow API
1 parent f75e65c commit dcd9608

3 files changed

Lines changed: 29 additions & 5 deletions

File tree

python/ql/lib/semmle/python/security/dataflow/StackTraceExposureQuery.qll

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import semmle.python.dataflow.new.TaintTracking
1212
import StackTraceExposureCustomizations::StackTraceExposure
1313

1414
/**
15+
* DEPRECATED: Use `StackTraceExposureFlow` module instead.
16+
*
1517
* A taint-tracking configuration for detecting "stack trace exposure" vulnerabilities.
1618
*/
17-
class Configuration extends TaintTracking::Configuration {
19+
deprecated class Configuration extends TaintTracking::Configuration {
1820
Configuration() { this = "StackTraceExposure" }
1921

2022
override predicate isSource(DataFlow::Node source) { source instanceof Source }
@@ -36,3 +38,23 @@ class Configuration extends TaintTracking::Configuration {
3638
)
3739
}
3840
}
41+
42+
private module StackTraceExposureConfig implements DataFlow::ConfigSig {
43+
predicate isSource(DataFlow::Node source) { source instanceof Source }
44+
45+
predicate isSink(DataFlow::Node sink) { sink instanceof Sink }
46+
47+
predicate isBarrier(DataFlow::Node node) { node instanceof Sanitizer }
48+
49+
// A stack trace is accessible as the `__traceback__` attribute of a caught exception.
50+
// see https://docs.python.org/3/reference/datamodel.html#traceback-objects
51+
predicate isAdditionalFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
52+
exists(DataFlow::AttrRead attr | attr.getAttributeName() = "__traceback__" |
53+
nodeFrom = attr.getObject() and
54+
nodeTo = attr
55+
)
56+
}
57+
}
58+
59+
/** Global taint-tracking for detecting "stack trace exposure" vulnerabilities. */
60+
module StackTraceExposureFlow = TaintTracking::Global<StackTraceExposureConfig>;

python/ql/src/Security/CWE-209/StackTraceExposure.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
import python
1717
import semmle.python.security.dataflow.StackTraceExposureQuery
18-
import DataFlow::PathGraph
18+
import StackTraceExposureFlow::PathGraph
1919

20-
from Configuration config, DataFlow::PathNode source, DataFlow::PathNode sink
21-
where config.hasFlowPath(source, sink)
20+
from StackTraceExposureFlow::PathNode source, StackTraceExposureFlow::PathNode sink
21+
where StackTraceExposureFlow::flowPath(source, sink)
2222
select sink.getNode(), source, sink,
2323
"$@ flows to this location and may be exposed to an external user.", source.getNode(),
2424
"Stack trace information"

python/ql/test/query-tests/Security/CWE-209-StackTraceExposure/StackTraceExposure.expected

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
edges
22
| test.py:23:25:23:25 | SSA variable e | test.py:24:16:24:16 | ControlFlowNode for e |
3-
| test.py:31:25:31:25 | SSA variable e | test.py:32:16:32:30 | ControlFlowNode for Attribute |
3+
| test.py:31:25:31:25 | SSA variable e | test.py:32:16:32:16 | ControlFlowNode for e |
4+
| test.py:32:16:32:16 | ControlFlowNode for e | test.py:32:16:32:30 | ControlFlowNode for Attribute |
45
| test.py:49:9:49:11 | SSA variable err | test.py:50:29:50:31 | ControlFlowNode for err |
56
| test.py:49:15:49:36 | ControlFlowNode for Attribute() | test.py:49:9:49:11 | SSA variable err |
67
| test.py:50:29:50:31 | ControlFlowNode for err | test.py:50:16:50:32 | ControlFlowNode for format_error() |
@@ -12,6 +13,7 @@ nodes
1213
| test.py:23:25:23:25 | SSA variable e | semmle.label | SSA variable e |
1314
| test.py:24:16:24:16 | ControlFlowNode for e | semmle.label | ControlFlowNode for e |
1415
| test.py:31:25:31:25 | SSA variable e | semmle.label | SSA variable e |
16+
| test.py:32:16:32:16 | ControlFlowNode for e | semmle.label | ControlFlowNode for e |
1517
| test.py:32:16:32:30 | ControlFlowNode for Attribute | semmle.label | ControlFlowNode for Attribute |
1618
| test.py:49:9:49:11 | SSA variable err | semmle.label | SSA variable err |
1719
| test.py:49:15:49:36 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |

0 commit comments

Comments
 (0)