Skip to content

Commit f7f8868

Browse files
committed
use strings in isTypeofGard
1 parent df95562 commit f7f8868

File tree

9 files changed

+27
-30
lines changed

9 files changed

+27
-30
lines changed

javascript/ql/src/Security/CWE-915/PrototypePollutingFunction.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,18 @@ class InstanceOfGuard extends DataFlow::LabeledBarrierGuardNode, DataFlow::Value
396396
class TypeofGuard extends DataFlow::LabeledBarrierGuardNode, DataFlow::ValueNode {
397397
override EqualityTest astNode;
398398
Expr operand;
399-
InferredType type;
399+
TypeofTag tag;
400400

401-
TypeofGuard() { TaintTracking::isTypeofGuard(astNode, operand, type) }
401+
TypeofGuard() { TaintTracking::isTypeofGuard(astNode, operand, tag) }
402402

403403
override predicate blocks(boolean outcome, Expr e, DataFlow::FlowLabel label) {
404404
e = operand and
405405
outcome = astNode.getPolarity() and
406406
(
407-
type = TTObject() and
407+
tag = "object" and
408408
label = "constructor"
409409
or
410-
type = TTFunction() and
410+
tag = "function" and
411411
label = "__proto__"
412412
)
413413
or
@@ -416,10 +416,10 @@ class TypeofGuard extends DataFlow::LabeledBarrierGuardNode, DataFlow::ValueNode
416416
(
417417
// If something is not an object, sanitize object, as both must end
418418
// in non-function prototype object.
419-
type = TTObject() and
419+
tag = "object" and
420420
label instanceof UnsafePropLabel
421421
or
422-
type = TTFunction() and
422+
tag = "function" and
423423
label = "constructor"
424424
)
425425
}

javascript/ql/src/semmle/javascript/DefensiveProgramming.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,15 @@ module DefensiveExpressionTest {
326326
*/
327327
private class TypeofTest extends EqualityTest {
328328
Expr operand;
329-
InferredType type;
329+
TypeofTag tag;
330330

331-
TypeofTest() { TaintTracking::isTypeofGuard(this, operand, type) }
331+
TypeofTest() { TaintTracking::isTypeofGuard(this, operand, tag) }
332332

333333
boolean getTheTestResult() {
334334
exists(boolean testResult |
335-
testResult = true and operand.analyze().getTheType() = type
335+
testResult = true and operand.analyze().getTheType().getTypeofTag() = tag
336336
or
337-
testResult = false and not operand.analyze().getAType() = type
337+
testResult = false and not operand.analyze().getAType().getTypeofTag() = tag
338338
|
339339
if getPolarity() = true then result = testResult else result = testResult.booleanNot()
340340
)
@@ -348,7 +348,7 @@ module DefensiveExpressionTest {
348348
/**
349349
* Gets the `typeof` tag that is tested.
350350
*/
351-
TypeofTag getTag() { result = type.getTypeofTag() }
351+
TypeofTag getTag() { result = tag }
352352
}
353353

354354
/**

javascript/ql/src/semmle/javascript/dataflow/TaintTracking.qll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ module TaintTracking {
899899
Expr x;
900900
override EqualityTest astNode;
901901

902-
TypeOfUndefinedSanitizer() { isTypeofGuard(astNode, x, TTUndefined()) }
902+
TypeOfUndefinedSanitizer() { isTypeofGuard(astNode, x, "undefined") }
903903

904904
override predicate sanitizes(boolean outcome, Expr e) {
905905
outcome = astNode.getPolarity() and
@@ -910,13 +910,13 @@ module TaintTracking {
910910
}
911911

912912
/**
913-
* Holds if `test` is a guard that checks if `operand` is typeof `type`.
913+
* Holds if `test` is a guard that checks if `operand` is typeof `tag`.
914914
*
915915
* See `TypeOfUndefinedSanitizer` for example usage.
916916
*/
917-
predicate isTypeofGuard(EqualityTest test, Expr operand, InferredType type) {
917+
predicate isTypeofGuard(EqualityTest test, Expr operand, TypeofTag tag) {
918918
exists(Expr str, TypeofExpr typeof | test.hasOperands(str, typeof) |
919-
str.mayHaveStringValue(type.getTypeofTag()) and
919+
str.mayHaveStringValue(tag) and
920920
typeof.getOperand() = operand
921921
)
922922
}

javascript/ql/src/semmle/javascript/security/TaintedObject.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ module TaintedObject {
103103
boolean polarity;
104104

105105
TypeTestGuard() {
106-
exists(InferredType type | TaintTracking::isTypeofGuard(astNode, operand, type) |
106+
exists(TypeofTag tag | TaintTracking::isTypeofGuard(astNode, operand, tag) |
107107
// typeof x === "object" sanitizes `x` when it evaluates to false
108-
type = TTObject() and
108+
tag = "object" and
109109
polarity = astNode.getPolarity().booleanNot()
110110
or
111111
// typeof x === "string" sanitizes `x` when it evaluates to true
112-
type != TTObject() and
112+
tag != "object" and
113113
polarity = astNode.getPolarity()
114114
)
115115
}

javascript/ql/src/semmle/javascript/security/dataflow/PrototypePollutingAssignment.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ module PrototypePollutingAssignment {
168168
boolean polarity;
169169

170170
TypeofCheck() {
171-
exists(InferredType type | TaintTracking::isTypeofGuard(astNode, operand, type) |
172-
type = TTObject() and polarity = astNode.getPolarity().booleanNot()
171+
exists(TypeofTag value | TaintTracking::isTypeofGuard(astNode, operand, value) |
172+
value = "object" and polarity = astNode.getPolarity().booleanNot()
173173
or
174-
type != TTObject() and polarity = astNode.getPolarity()
174+
value != "object" and polarity = astNode.getPolarity()
175175
)
176176
}
177177

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeJQueryPluginCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module UnsafeJQueryPlugin {
134134
SyntacticConstants::isUndefined(undef)
135135
)
136136
or
137-
TaintTracking::isTypeofGuard(test, read.asExpr(), TTUndefined())
137+
TaintTracking::isTypeofGuard(test, read.asExpr(), "undefined")
138138
)
139139
or
140140
polarity = true and

javascript/ql/src/semmle/javascript/security/dataflow/UnsafeShellCommandConstructionCustomizations.qll

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,7 @@ module UnsafeShellCommandConstruction {
199199
Expr x;
200200
override EqualityTest astNode;
201201

202-
TypeOfSanitizer() {
203-
TaintTracking::isTypeofGuard(astNode, x,
204-
any(InferredType t | t = TTNumber() or t = TTBoolean()))
205-
}
202+
TypeOfSanitizer() { TaintTracking::isTypeofGuard(astNode, x, ["number", "boolean"]) }
206203

207204
override predicate sanitizes(boolean outcome, Expr e) {
208205
outcome = astNode.getPolarity() and

javascript/ql/src/semmle/javascript/security/dataflow/UnvalidatedDynamicMethodCallCustomizations.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module UnvalidatedDynamicMethodCall {
100100
override EqualityTest astNode;
101101
Expr operand;
102102

103-
FunctionCheck() { TaintTracking::isTypeofGuard(astNode, operand, TTFunction()) }
103+
FunctionCheck() { TaintTracking::isTypeofGuard(astNode, operand, "function") }
104104

105105
override predicate sanitizes(boolean outcome, Expr e, DataFlow::FlowLabel label) {
106106
outcome = astNode.getPolarity() and

javascript/ql/src/semmle/javascript/security/dataflow/XssThroughDom.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ module XssThroughDom {
108108
boolean polarity;
109109

110110
TypeTestGuard() {
111-
exists(InferredType type | TaintTracking::isTypeofGuard(astNode, operand, type) |
111+
exists(TypeofTag tag | TaintTracking::isTypeofGuard(astNode, operand, tag) |
112112
// typeof x === "string" sanitizes `x` when it evaluates to false
113-
type = TTString() and
113+
tag = "string" and
114114
polarity = astNode.getPolarity().booleanNot()
115115
or
116116
// typeof x === "object" sanitizes `x` when it evaluates to true
117-
type != TTString() and
117+
tag != "string" and
118118
polarity = astNode.getPolarity()
119119
)
120120
}

0 commit comments

Comments
 (0)