Skip to content

Commit e17b3d9

Browse files
committed
JS: pick up CryptographicKeys used in asmCrypto encrypt/decrypt calls
1 parent 6b2a92a commit e17b3d9

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

javascript/ql/lib/semmle/javascript/frameworks/CryptoLibraries.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private module AsmCrypto {
5151
DataFlow::Node input;
5252
CryptographicAlgorithm algorithm; // non-functional
5353
private string algorithmName;
54+
private string methodName;
5455

5556
Apply() {
5657
/*
@@ -66,7 +67,7 @@ private module AsmCrypto {
6667
exists(DataFlow::SourceNode asmCrypto |
6768
asmCrypto = DataFlow::globalVarRef("asmCrypto") and
6869
algorithm.matchesName(algorithmName) and
69-
this = asmCrypto.getAPropertyRead(algorithmName).getAMemberCall(_) and
70+
this = asmCrypto.getAPropertyRead(algorithmName).getAMemberCall(methodName) and
7071
input = this.getArgument(0)
7172
)
7273
}
@@ -79,6 +80,15 @@ private module AsmCrypto {
7980
isBlockEncryptionAlgorithm(this.getAlgorithm()) and
8081
result.matchesString(algorithmName)
8182
}
83+
84+
DataFlow::Node getKey() {
85+
methodName = ["encrypt", "decrypt"] and
86+
result = super.getArgument(1)
87+
}
88+
}
89+
90+
private class Key extends CryptographicKey {
91+
Key() { this = any(Apply apply).getKey() }
8292
}
8393
}
8494

javascript/ql/test/library-tests/CryptoLibraries/CryptographicKey.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
| tst.js:3:34:3:36 | key |
12
| tst.js:7:26:7:42 | keypair.secretKey |
23
| tst.js:21:42:21:51 | 'a secret' |
34
| tst.js:36:36:36:51 | 'secret key 123' |

0 commit comments

Comments
 (0)