Skip to content

Commit 9c2525e

Browse files
chanel-yMathiasVP
andauthored
Apply suggestions from code review ty mathias <3
Co-authored-by: Mathias Vorreiter Pedersen <mathiasvp@github.com>
1 parent 67b0bf1 commit 9c2525e

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

powershell/ql/lib/semmle/code/powershell/security/cryptography/CryptographyModule.qll

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ class HashAlgorithmObjectCreation extends HashAlgorithm, CryptoAlgorithmObjectCr
7575
string algName;
7676

7777
HashAlgorithmObjectCreation() {
78-
(
79-
objectName = "system.security.cryptography." + algName or
80-
objectName = "system.security.cryptography." + algName + "cryptoserviceprovider"
81-
) and
78+
this.getObjectName() = "system.security.cryptography." + algName + ["", "cryptoserviceprovider"] and
8279
isHashingAlgorithm(algName)
8380
}
8481

@@ -90,10 +87,7 @@ class HashAlgorithmCreateCall extends HashAlgorithm, CryptoAlgorithmCreateCall {
9087

9188
HashAlgorithmCreateCall() {
9289
isHashingAlgorithm(algName) and
93-
(
94-
objectName = algName or
95-
objectName = "system.security.cryptography." + algName
96-
)
90+
this.getObjectName() = ["", "system.security.cryptography."] + algName
9791
}
9892

9993
override string getName() { result = algName }
@@ -103,10 +97,7 @@ class HashAlgorithmCreateFromNameCall extends HashAlgorithm, CryptoAlgorithmCrea
10397
string algName;
10498

10599
HashAlgorithmCreateFromNameCall() {
106-
(
107-
objectName = algName or
108-
objectName = "system.security.cryptography." + algName
109-
) and
100+
this.getObjectName() = ["", "system.security.cryptography."] + algName and
110101
isHashingAlgorithm(algName)
111102
}
112103

@@ -133,11 +124,7 @@ class SymmetricAlgorithmCreateCall extends SymmetricAlgorithm, CryptoAlgorithmCr
133124

134125
SymmetricAlgorithmCreateCall() {
135126
isSymmetricAlgorithm(algName) and
136-
(
137-
objectName = algName or
138-
objectName = "system.security.cryptography." + algName or
139-
objectName = "system.security.cryptography.symmetricalgorithm." + algName
140-
)
127+
this.getObjectName() = ["", "system.security.cryptography.", "system.security.cryptography.symmetricalgorithm."] + algName
141128
}
142129

143130
override string getName() { result = algName }
@@ -147,10 +134,7 @@ class SymmetricAlgorithmCreateArgCall extends SymmetricAlgorithm, CryptoAlgorith
147134
string algName;
148135

149136
SymmetricAlgorithmCreateArgCall() {
150-
algName = this.getObjectName() and
151-
isSymmetricAlgorithm(algName)
152-
or
153-
objectName = "system.security.cryptography." + algName and
137+
algName = ["", "system.security.cryptography."] + this.getObjectName() and
154138
isSymmetricAlgorithm(algName)
155139
}
156140

@@ -163,11 +147,7 @@ class SymmetricAlgorithmCreateFromNameCall extends SymmetricAlgorithm,
163147
string algName;
164148

165149
SymmetricAlgorithmCreateFromNameCall() {
166-
(
167-
objectName = algName or
168-
objectName = "system.security.cryptography." + algName or
169-
objectName = "system.security.cryptography.symmetricalgorithm." + algName
170-
) and
150+
this.getObjectName() = ["", "system.security.cryptography.", "system.security.cryptography.symmetricalgorithm."] + algName and
171151
isSymmetricAlgorithm(algName)
172152
}
173153

powershell/ql/src/queries/security/cwe-327/ApprovedCipherMode.ql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AesModeProperty extends MemberExpr {
2929
.getAnArgument()
3030
.getValue()
3131
.stringMatches("System.Security.Cryptography.AesManaged") or
32-
aesObjectCreation.(DataFlow::CallNode) =
32+
aesObjectCreation =
3333
API::getTopLevelMember("system")
3434
.getMember("security")
3535
.getMember("cryptography")
@@ -46,8 +46,10 @@ class AesModeProperty extends MemberExpr {
4646

4747
module Config implements DataFlow::ConfigSig {
4848
predicate isSource(DataFlow::Node source) {
49-
source instanceof BlockMode and
50-
not source.(BlockMode).getBlockModeName() = ["cbc", "cts", "xts"]
49+
exists(BlockMode blockMode |
50+
source = blockMode and
51+
not blockMode.getBlockModeName() = ["cbc", "cts", "xts"]
52+
)
5153
}
5254

5355
predicate isSink(DataFlow::Node sink) {

0 commit comments

Comments
 (0)