Skip to content

Commit 8d3bd9d

Browse files
committed
move the ExceptionXss sources into the Customizations file
1 parent 25708c5 commit 8d3bd9d

File tree

3 files changed

+80
-63
lines changed

3 files changed

+80
-63
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* Provides default sources, sinks and sanitizers for reasoning about
3+
* cross-site scripting vulnerabilities where the taint-flow passes through a thrown
4+
* exception.
5+
*/
6+
7+
import javascript
8+
import semmle.javascript.security.dataflow.RemoteFlowSources
9+
10+
module ExceptionXss {
11+
private import Xss::Shared as Shared
12+
13+
/** A data flow source for XSS caused by interpreting exception or error text as HTML. */
14+
abstract class Source extends DataFlow::Node {
15+
/**
16+
* Gets a flow label to associate with this source.
17+
*
18+
* For sources that should pass through a `throw/catch` before reaching the sink, use the
19+
* `NotYetThrown` labe. Otherwise use `taint` (the default).
20+
*/
21+
DataFlow::FlowLabel getAFlowLabel() { result.isTaint() }
22+
23+
/**
24+
* Gets a human-readable description of what type of error this refers to.
25+
*
26+
* The result should be capitalized and usable in the context of a noun.
27+
*/
28+
string getDescription() { result = "Error text" }
29+
}
30+
31+
/**
32+
* A FlowLabel representing tainted data that has not been thrown in an exception.
33+
* In the js/xss-through-exception query data-flow can only reach a sink after
34+
* the data has been thrown as an exception, and data that has not been thrown
35+
* as an exception therefore has this flow label, and only this flow label, associated with it.
36+
*/
37+
abstract class NotYetThrown extends DataFlow::FlowLabel {
38+
NotYetThrown() { this = "NotYetThrown" }
39+
}
40+
41+
private class XssSourceAsSource extends Source {
42+
XssSourceAsSource() { this instanceof Shared::Source }
43+
44+
override DataFlow::FlowLabel getAFlowLabel() { result instanceof NotYetThrown }
45+
46+
override string getDescription() { result = "Exception text" }
47+
}
48+
49+
/**
50+
* An error produced by validating using `ajv`.
51+
*
52+
* Such an error can contain property names from the input if the
53+
* underlying schema uses `additionalProperties` or `propertyPatterns`.
54+
*
55+
* For example, an input of form `{"<img src=x onerror=alert(1)>": 45}` might produce the error
56+
* `data/<img src=x onerror=alert(1)> should be string`.
57+
*/
58+
private class JsonSchemaValidationError extends Source {
59+
JsonSchemaValidationError() {
60+
this = any(JsonSchema::Ajv::Instance i).getAValidationError().getAnImmediateUse()
61+
or
62+
this = any(JsonSchema::Joi::JoiValidationErrorRead r).getAValidationResultAccess(_)
63+
}
64+
65+
override string getDescription() { result = "JSON schema validation error" }
66+
}
67+
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import javascript
88
import DomBasedXssCustomizations::DomBasedXss as DomBasedXssCustom
99
import ReflectedXssCustomizations::ReflectedXss as ReflectedXssCustom
10-
import Xss as Xss
11-
import Xss::ExceptionXss
10+
import ExceptionXssCustomizations::ExceptionXss
1211
private import semmle.javascript.dataflow.InferredTypes
12+
import Xss::Shared as XssShared
1313

1414
/**
1515
* Gets the name of a method that does not leak taint from its arguments if an exception is thrown by the method.
@@ -56,7 +56,7 @@ private predicate isNullOrUndefined(InferredType t) {
5656
*/
5757
predicate canThrowSensitiveInformation(DataFlow::Node node) {
5858
not isUnlikelyToThrowSensitiveInformation(node) and
59-
not node instanceof Xss::Shared::Sink and // removes duplicates from js/xss.
59+
not node instanceof XssShared::Sink and // removes duplicates from js/xss.
6060
(
6161
// in the case of reflective calls the below ensures that both InvokeNodes have no known callee.
6262
forex(DataFlow::InvokeNode call | call.getAnArgument() = node | not exists(call.getACallee()))
@@ -71,7 +71,7 @@ predicate canThrowSensitiveInformation(DataFlow::Node node) {
7171
}
7272

7373
// Materialize flow labels
74-
private class ConcreteNotYetThrown extends Xss::ExceptionXss::NotYetThrown {
74+
private class ConcreteNotYetThrown extends NotYetThrown {
7575
ConcreteNotYetThrown() { this = this }
7676
}
7777

@@ -133,14 +133,14 @@ class Configuration extends TaintTracking::Configuration {
133133
Configuration() { this = "ExceptionXss" }
134134

135135
override predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
136-
source.(Xss::ExceptionXss::Source).getAFlowLabel() = label
136+
source.(Source).getAFlowLabel() = label
137137
}
138138

139139
override predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
140-
sink instanceof Xss::Shared::Sink and not label instanceof NotYetThrown
140+
sink instanceof XssShared::Sink and not label instanceof NotYetThrown
141141
}
142142

143-
override predicate isSanitizer(DataFlow::Node node) { node instanceof Xss::Shared::Sanitizer }
143+
override predicate isSanitizer(DataFlow::Node node) { node instanceof XssShared::Sanitizer }
144144

145145
override predicate isAdditionalFlowStep(
146146
DataFlow::Node pred, DataFlow::Node succ, DataFlow::FlowLabel inlbl, DataFlow::FlowLabel outlbl

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

Lines changed: 6 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -178,60 +178,10 @@ deprecated module XssThroughDom {
178178
import XssThroughDomCustomizations::XssThroughDom
179179
}
180180

181-
/** Provides classes for customizing the `ExceptionXss` query. */
182-
module ExceptionXss {
183-
/** A data flow source for XSS caused by interpreting exception or error text as HTML. */
184-
abstract class Source extends DataFlow::Node {
185-
/**
186-
* Gets a flow label to associate with this source.
187-
*
188-
* For sources that should pass through a `throw/catch` before reaching the sink, use the
189-
* `NotYetThrown` labe. Otherwise use `taint` (the default).
190-
*/
191-
DataFlow::FlowLabel getAFlowLabel() { result.isTaint() }
192-
193-
/**
194-
* Gets a human-readable description of what type of error this refers to.
195-
*
196-
* The result should be capitalized and usable in the context of a noun.
197-
*/
198-
string getDescription() { result = "Error text" }
199-
}
200-
201-
/**
202-
* A FlowLabel representing tainted data that has not been thrown in an exception.
203-
* In the js/xss-through-exception query data-flow can only reach a sink after
204-
* the data has been thrown as an exception, and data that has not been thrown
205-
* as an exception therefore has this flow label, and only this flow label, associated with it.
206-
*/
207-
abstract class NotYetThrown extends DataFlow::FlowLabel {
208-
NotYetThrown() { this = "NotYetThrown" }
209-
}
210-
211-
private class XssSourceAsSource extends Source {
212-
XssSourceAsSource() { this instanceof Shared::Source }
213-
214-
override DataFlow::FlowLabel getAFlowLabel() { result instanceof NotYetThrown }
215-
216-
override string getDescription() { result = "Exception text" }
217-
}
218-
219-
/**
220-
* An error produced by validating using `ajv`.
221-
*
222-
* Such an error can contain property names from the input if the
223-
* underlying schema uses `additionalProperties` or `propertyPatterns`.
224-
*
225-
* For example, an input of form `{"<img src=x onerror=alert(1)>": 45}` might produce the error
226-
* `data/<img src=x onerror=alert(1)> should be string`.
227-
*/
228-
private class JsonSchemaValidationError extends Source {
229-
JsonSchemaValidationError() {
230-
this = any(JsonSchema::Ajv::Instance i).getAValidationError().getAnImmediateUse()
231-
or
232-
this = any(JsonSchema::Joi::JoiValidationErrorRead r).getAValidationResultAccess(_)
233-
}
234-
235-
override string getDescription() { result = "JSON schema validation error" }
236-
}
181+
/**
182+
* DEPRECATED: Use the `ExceptionXssCustomizations.qll` file instead.
183+
* Provides classes for customizing the `ExceptionXss` query.
184+
*/
185+
deprecated module ExceptionXss {
186+
import ExceptionXssCustomizations::ExceptionXss
237187
}

0 commit comments

Comments
 (0)