Apply getItem(_) and extend verifiesSignature readability

This commit is contained in:
jorgectf
2021-10-28 17:40:27 +02:00
parent ef4a27ff8c
commit a6c285ad32
3 changed files with 11 additions and 5 deletions

View File

@@ -42,7 +42,7 @@ private module Authlib {
override DataFlow::Node getAlgorithm() {
exists(KeyValuePair headerDict |
headerDict = this.getArg(0).asExpr().(Dict).getItems().getAnItem() and
headerDict = this.getArg(0).asExpr().(Dict).getItem(_) and
headerDict.getKey().(Str_).getS().matches("alg") and
result.asExpr() = headerDict.getValue()
)

View File

@@ -101,7 +101,7 @@ private module PyJWT {
predicate hasVerifySignatureSetToFalse() {
exists(KeyValuePair optionsDict, NameConstant falseName |
falseName.getId() = "False" and
optionsDict = this.getOptions().asExpr().(Dict).getItems().getAnItem() and
optionsDict = this.getOptions().asExpr().(Dict).getItem(_) and
optionsDict.getKey().(Str_).getS().matches("%verify%") and
falseName = optionsDict.getValue()
)

View File

@@ -88,12 +88,18 @@ private module PythonJose {
override predicate verifiesSignature() {
// jwt.decode(token, "key", "HS256")
not exists(this.getOptions())
this.hasNoOptions()
or
// jwt.decode(token, key, options={"verify_signature": False})
not exists(KeyValuePair optionsDict, NameConstant falseName |
not this.hasVerifySignatureSetToFalse()
}
predicate hasNoOptions() { not exists(this.getOptions()) }
predicate hasVerifySignatureSetToFalse() {
exists(KeyValuePair optionsDict, NameConstant falseName |
falseName.getId() = "False" and
optionsDict = this.getOptions().asExpr().(Dict).getItems().getAnItem() and
optionsDict = this.getOptions().asExpr().(Dict).getItem(_) and
optionsDict.getKey().(Str_).getS().matches("%verify%") and
falseName = optionsDict.getValue()
)