Skip to content

Commit a6c285a

Browse files
committed
Apply getItem(_) and extend verifiesSignature readability
1 parent ef4a27f commit a6c285a

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

python/ql/src/experimental/semmle/python/libraries/Authlib.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private module Authlib {
4242

4343
override DataFlow::Node getAlgorithm() {
4444
exists(KeyValuePair headerDict |
45-
headerDict = this.getArg(0).asExpr().(Dict).getItems().getAnItem() and
45+
headerDict = this.getArg(0).asExpr().(Dict).getItem(_) and
4646
headerDict.getKey().(Str_).getS().matches("alg") and
4747
result.asExpr() = headerDict.getValue()
4848
)

python/ql/src/experimental/semmle/python/libraries/PyJWT.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private module PyJWT {
101101
predicate hasVerifySignatureSetToFalse() {
102102
exists(KeyValuePair optionsDict, NameConstant falseName |
103103
falseName.getId() = "False" and
104-
optionsDict = this.getOptions().asExpr().(Dict).getItems().getAnItem() and
104+
optionsDict = this.getOptions().asExpr().(Dict).getItem(_) and
105105
optionsDict.getKey().(Str_).getS().matches("%verify%") and
106106
falseName = optionsDict.getValue()
107107
)

python/ql/src/experimental/semmle/python/libraries/PythonJose.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,18 @@ private module PythonJose {
8888

8989
override predicate verifiesSignature() {
9090
// jwt.decode(token, "key", "HS256")
91-
not exists(this.getOptions())
91+
this.hasNoOptions()
9292
or
9393
// jwt.decode(token, key, options={"verify_signature": False})
94-
not exists(KeyValuePair optionsDict, NameConstant falseName |
94+
not this.hasVerifySignatureSetToFalse()
95+
}
96+
97+
predicate hasNoOptions() { not exists(this.getOptions()) }
98+
99+
predicate hasVerifySignatureSetToFalse() {
100+
exists(KeyValuePair optionsDict, NameConstant falseName |
95101
falseName.getId() = "False" and
96-
optionsDict = this.getOptions().asExpr().(Dict).getItems().getAnItem() and
102+
optionsDict = this.getOptions().asExpr().(Dict).getItem(_) and
97103
optionsDict.getKey().(Str_).getS().matches("%verify%") and
98104
falseName = optionsDict.getValue()
99105
)

0 commit comments

Comments
 (0)