Skip to content

Commit 7891e64

Browse files
committed
add sanitizers to hardcoded query
1 parent 7a577dd commit 7891e64

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

javascript/ql/src/Security/CWE-321-HardCodedKey/jwtConstantKey.ql

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @kind path-problem
55
* @problem.severity error
66
* @precision high
7-
* @id javascript/jwt-hardcodedkey
7+
* @id javascript/jwt-hardcoded-key
88
* @tags security
99
* experimental
1010
* external/cwe/CWE-321
@@ -18,11 +18,19 @@ class JWTDecodeConfig extends TaintTracking::Configuration {
1818
JWTDecodeConfig() { this = "JWTConfig" }
1919

2020
override predicate isSource(DataFlow::Node source) {
21-
source.asExpr() instanceof ConstantString
21+
source.asExpr() instanceof ConstantString and
22+
// following prevent custom secret key generators that exist in source code
23+
not source.asExpr().mayHaveStringValue(["", " ", any(string s | s.length() = 1)])
24+
}
25+
26+
override predicate isSanitizer(DataFlow::Node node) {
27+
node.getFile()
28+
.getLocation()
29+
.hasLocationInfo(any(string s | s.matches(["%test%", "%demo%", "%example%", "%sample%"])),
30+
_, _, _, _)
2231
}
2332

2433
override predicate isSink(DataFlow::Node sink) {
25-
// any() or
2634
sink = API::moduleImport("jsonwebtoken").getMember(["sign", "verify"]).getParameter(1).asSink() or
2735
sink = API::moduleImport("jose").getMember("jwtVerify").getParameter(1).asSink() or
2836
sink = API::moduleImport("jwt-simple").getMember("decode").getParameter(1).asSink() or

0 commit comments

Comments
 (0)