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

Skip to content

Commit d7b4e0c

Browse files
committed
JS: Port ExceptionXss
1 parent cf5450d commit d7b4e0c

3 files changed

Lines changed: 145 additions & 126 deletions

File tree

javascript/ql/lib/semmle/javascript/security/dataflow/ExceptionXssQuery.qll

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,41 @@ private DataFlow::Node getExceptionTarget(DataFlow::Node pred) {
126126

127127
/**
128128
* A taint-tracking configuration for reasoning about XSS with possible exceptional flow.
129-
* Flow labels are used to ensure that we only report taint-flow that has been thrown in
129+
* Flow states are used to ensure that we only report taint-flow that has been thrown in
130130
* an exception.
131131
*/
132-
class Configuration extends TaintTracking::Configuration {
132+
module ExceptionXssConfig implements DataFlow::StateConfigSig {
133+
class FlowState = DataFlow::FlowLabel;
134+
135+
predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
136+
source.(Source).getAFlowLabel() = label
137+
}
138+
139+
predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
140+
sink instanceof XssShared::Sink and not label instanceof NotYetThrown
141+
}
142+
143+
predicate isBarrier(DataFlow::Node node) { node instanceof XssShared::Sanitizer }
144+
145+
predicate isAdditionalFlowStep(
146+
DataFlow::Node pred, DataFlow::FlowLabel inlbl, DataFlow::Node succ, DataFlow::FlowLabel outlbl
147+
) {
148+
inlbl instanceof NotYetThrown and
149+
(outlbl.isTaint() or outlbl instanceof NotYetThrown) and
150+
canThrowSensitiveInformation(pred) and
151+
succ = getExceptionTarget(pred)
152+
}
153+
}
154+
155+
/**
156+
* Taint-tracking for reasoning about XSS with possible exceptional flow.
157+
*/
158+
module ExceptionXssFlow = TaintTracking::GlobalWithState<ExceptionXssConfig>;
159+
160+
/**
161+
* DEPRECATED. Use the `ExceptionXssFlow` module instead.
162+
*/
163+
deprecated class Configuration extends TaintTracking::Configuration {
133164
Configuration() { this = "ExceptionXss" }
134165

135166
override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
@@ -145,12 +176,10 @@ class Configuration extends TaintTracking::Configuration {
145176
override predicate isAdditionalFlowStep(
146177
DataFlow::Node pred, DataFlow::Node succ, DataFlow::FlowLabel inlbl, DataFlow::FlowLabel outlbl
147178
) {
148-
inlbl instanceof NotYetThrown and
149-
(outlbl.isTaint() or outlbl instanceof NotYetThrown) and
150-
canThrowSensitiveInformation(pred) and
151-
succ = getExceptionTarget(pred)
179+
ExceptionXssConfig::isAdditionalFlowStep(pred, inlbl, succ, outlbl)
152180
or
153181
// All the usual taint-flow steps apply on data-flow before it has been thrown in an exception.
182+
// Note: this step is not needed in StateConfigSig module since flow states inherit taint steps.
154183
this.isAdditionalFlowStep(pred, succ) and
155184
inlbl instanceof NotYetThrown and
156185
outlbl instanceof NotYetThrown

javascript/ql/src/Security/CWE-079/ExceptionXss.ql

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

1515
import javascript
1616
import semmle.javascript.security.dataflow.ExceptionXssQuery
17-
import DataFlow::PathGraph
17+
import DataFlow::DeduplicatePathGraph<ExceptionXssFlow::PathNode, ExceptionXssFlow::PathGraph>
1818

19-
from Configuration cfg, DataFlow::PathNode source, DataFlow::PathNode sink
20-
where cfg.hasFlowPath(source, sink)
19+
from PathNode source, PathNode sink
20+
where ExceptionXssFlow::flowPath(source.getAnOriginalPathNode(), sink.getAnOriginalPathNode())
2121
select sink.getNode(), source, sink,
2222
"$@ is reinterpreted as HTML without escaping meta-characters.", source.getNode(),
2323
source.getNode().(Source).getDescription()

0 commit comments

Comments
 (0)