Skip to content

Commit 231b077

Browse files
committed
Java: Ignore results in test directories.
1 parent fcaf5e7 commit 231b077

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

java/ql/src/experimental/Security/CWE/CWE-347/MissingJWTSignatureCheck.ql

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,21 @@ private class SigningKeyMethodAccess extends MethodAccess {
171171
}
172172
}
173173

174+
/**
175+
* Holds if the `MethodAccess` `ma` occurs in a test file. A test file is any file that
176+
* is a direct or indirect child of a directory named `test`, ignoring case.
177+
*/
178+
private predicate isInTestFile(MethodAccess ma) {
179+
exists(string lowerCasedAbsolutePath |
180+
lowerCasedAbsolutePath = ma.getLocation().getFile().getAbsolutePath().toLowerCase()
181+
|
182+
lowerCasedAbsolutePath.matches("%/test/%") and
183+
not lowerCasedAbsolutePath
184+
.matches("%/ql/test/experimental/query-tests/security/CWE-347/%".toLowerCase())
185+
)
186+
}
187+
174188
from JwtParserInsecureParseMethodAccess ma, JwtParserWithSigningKeyExpr parserExpr
175-
where ma.getQualifier() = parserExpr
189+
where ma.getQualifier() = parserExpr and not isInTestFile(ma)
176190
select ma, "A signing key is set $@, but the signature is not verified.",
177191
parserExpr.getSigningMethodAccess(), "here"

0 commit comments

Comments
 (0)