Skip to content

Commit d381ab1

Browse files
committed
JS: Migrate IncompleteHtmlAttributeSanitization
1 parent 2112ecc commit d381ab1

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@ import javascript
88
import semmle.javascript.security.IncompleteBlacklistSanitizer
99

1010
module IncompleteHtmlAttributeSanitization {
11+
private newtype TFlowState = TCharacter(string c) { c = ["\"", "'", "&"] }
12+
13+
/** A flow state to associate with a tracked value. */
14+
class FlowState extends TFlowState {
15+
/** Gets a string representation of this flow state. */
16+
string toString() { this = TCharacter(result) }
17+
}
18+
19+
/** Predicates for working with flow states. */
20+
module FlowState {
21+
/** Gets the flow state corresponding to `c`. */
22+
FlowState character(string c) { result = TCharacter(c) }
23+
}
24+
1125
/**
1226
* A data flow source for incomplete HTML sanitization vulnerabilities.
1327
*/

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99

1010
import javascript
1111
import IncompleteHtmlAttributeSanitizationCustomizations::IncompleteHtmlAttributeSanitization
12+
private import IncompleteHtmlAttributeSanitizationCustomizations::IncompleteHtmlAttributeSanitization as IncompleteHtmlAttributeSanitization
1213

13-
private module Label {
14+
deprecated private module Label {
1415
class Quote extends DataFlow::FlowLabel {
1516
Quote() { this = ["\"", "'"] }
1617
}
@@ -26,18 +27,18 @@ private module Label {
2627
* A taint-tracking configuration for reasoning about incomplete HTML sanitization vulnerabilities.
2728
*/
2829
module IncompleteHtmlAttributeSanitizationConfig implements DataFlow::StateConfigSig {
29-
class FlowState = DataFlow::FlowLabel;
30+
class FlowState = IncompleteHtmlAttributeSanitization::FlowState;
3031

31-
predicate isSource(DataFlow::Node source, DataFlow::FlowLabel label) {
32-
label = Label::characterToLabel(source.(Source).getAnUnsanitizedCharacter())
32+
predicate isSource(DataFlow::Node source, FlowState label) {
33+
label = FlowState::character(source.(Source).getAnUnsanitizedCharacter())
3334
}
3435

35-
predicate isSink(DataFlow::Node sink, DataFlow::FlowLabel label) {
36-
label = Label::characterToLabel(sink.(Sink).getADangerousCharacter())
36+
predicate isSink(DataFlow::Node sink, FlowState label) {
37+
label = FlowState::character(sink.(Sink).getADangerousCharacter())
3738
}
3839

39-
predicate isBarrier(DataFlow::Node node, DataFlow::FlowLabel lbl) {
40-
lbl = Label::characterToLabel(node.(StringReplaceCall).getAReplacedString())
40+
predicate isBarrier(DataFlow::Node node, FlowState lbl) {
41+
lbl = FlowState::character(node.(StringReplaceCall).getAReplacedString())
4142
}
4243

4344
predicate isBarrier(DataFlow::Node n) { n instanceof Sanitizer }

0 commit comments

Comments
 (0)