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

Skip to content

Commit 9029dba

Browse files
committed
refactor isAdditionalTaintStep to a utility predicate in InsecureRandomness
1 parent 9189f23 commit 9029dba

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,7 @@ module InsecureRandomness {
3636
}
3737

3838
override predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
39-
// Assume that all operations on tainted values preserve taint: crypto is hard
40-
succ.asExpr().(BinaryExpr).getAnOperand() = pred.asExpr()
41-
or
42-
succ.asExpr().(UnaryExpr).getOperand() = pred.asExpr()
43-
or
44-
exists(DataFlow::MethodCallNode mc |
45-
mc = DataFlow::globalVarRef("Math").getAMemberCall(_) and
46-
pred = mc.getAnArgument() and
47-
succ = mc
48-
)
39+
InsecureRandomness::isAdditionalTaintStep(pred, succ)
4940
}
5041
}
5142
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,20 @@ module InsecureRandomness {
7878
class CryptoKeySink extends Sink {
7979
CryptoKeySink() { this instanceof CryptographicKey }
8080
}
81+
82+
/**
83+
* Holds if the step `pred` -> `succ` is an additional taint-step for random values that are not cryptographically secure.
84+
*/
85+
predicate isAdditionalTaintStep(DataFlow::Node pred, DataFlow::Node succ) {
86+
// Assume that all operations on tainted values preserve taint: crypto is hard
87+
succ.asExpr().(BinaryExpr).getAnOperand() = pred.asExpr()
88+
or
89+
succ.asExpr().(UnaryExpr).getOperand() = pred.asExpr()
90+
or
91+
exists(DataFlow::MethodCallNode mc |
92+
mc = DataFlow::globalVarRef("Math").getAMemberCall(_) and
93+
pred = mc.getAnArgument() and
94+
succ = mc
95+
)
96+
}
8197
}

0 commit comments

Comments
 (0)