Skip to content

Commit d5791e2

Browse files
Addressing feedback from the PR
1 parent ac05577 commit d5791e2

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

java/ql/src/experimental/Security/CWE/CWE-327/Azure/UnsafeUsageOfClientSideEncryptionVersion.ql

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import java
14+
import semmle.code.java.dataflow.DataFlow
1415

1516
/**
1617
* Holds if the call `call` is an object creation for a class `EncryptedBlobClientBuilder`
@@ -46,16 +47,37 @@ predicate isCreatingAzureClientSideEncryptionObjectNewVersion(Call call, Class c
4647
)
4748
}
4849

50+
/**
51+
* A config that tracks `EncryptedBlobClientBuilder.version` argument initialization.
52+
*/
53+
private class EncryptedBlobClientBuilderEncryptionVersionConfig extends DataFlow::Configuration {
54+
EncryptedBlobClientBuilderEncryptionVersionConfig() {
55+
this = "EncryptedBlobClientBuilderEncryptionVersionConfig"
56+
}
57+
58+
override predicate isSource(DataFlow::Node source) {
59+
exists(FieldRead fr, Field f | fr = source.asExpr() |
60+
f.getAnAccess() = fr and
61+
f.hasQualifiedName("com.azure.storage.blob.specialized.cryptography", "EncryptionVersion",
62+
"V2")
63+
)
64+
}
65+
66+
override predicate isSink(DataFlow::Node sink) {
67+
isCreatingAzureClientSideEncryptionObjectNewVersion(_, _, sink.asExpr())
68+
}
69+
}
70+
4971
/**
5072
* Holds if the call `call` is an object creation for a class `EncryptedBlobClientBuilder`
5173
* that takes `versionArg` as the argument for the version, and the version number is safe
5274
*/
5375
predicate isCreatingSafeAzureClientSideEncryptionObject(Call call, Class c, Expr versionArg) {
5476
isCreatingAzureClientSideEncryptionObjectNewVersion(call, c, versionArg) and
55-
exists(FieldRead fr, Field f |
56-
fr = versionArg and
57-
f.getAnAccess() = fr and
58-
f.hasQualifiedName("com.azure.storage.blob.specialized.cryptography", "EncryptionVersion", "V2")
77+
exists(EncryptedBlobClientBuilderEncryptionVersionConfig config, DataFlow::Node sink |
78+
sink.asExpr() = versionArg
79+
|
80+
config.hasFlow(_, sink)
5981
)
6082
}
6183

python/ql/src/experimental/Security/CWE-327/Azure/UnsafeUsageOfClientSideEncryptionVersion.ql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
import python
14+
import semmle.python.ApiGraphs
1415

1516
predicate isUnsafeClientSideAzureStorageEncryptionViaAttributes(Call call, AttrNode node) {
1617
exists(ControlFlowNode ctrlFlowNode, AssignStmt astmt, Attribute a |
@@ -33,8 +34,10 @@ predicate isUnsafeClientSideAzureStorageEncryptionViaAttributes(Call call, AttrN
3334
}
3435

3536
predicate isUnsafeClientSideAzureStorageEncryptionViaObjectCreation(Call call, ControlFlowNode node) {
36-
exists(Keyword k | k.getAFlowNode() = node |
37-
call.getFunc().(Name).getId() in ["ContainerClient", "BlobClient", "BlobServiceClient"] and
37+
exists(API::Node c, string s, Keyword k | k.getAFlowNode() = node |
38+
c.getACall().asExpr() = call and
39+
c = API::moduleImport("azure").getMember("storage").getMember("blob").getMember(s) and
40+
s in ["ContainerClient", "BlobClient", "BlobServiceClient"] and
3841
k.getArg() = "key_encryption_key" and
3942
k = call.getANamedArg() and
4043
not k.getValue() instanceof None and

0 commit comments

Comments
 (0)