Skip to content

Commit 7a17cd2

Browse files
committed
Python: Rewrite azure query to more idiomatic ql
1 parent 691ffcd commit 7a17cd2

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

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

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,32 @@
1212
*/
1313

1414
import python
15+
import semmle.python.dataflow.new.DataFlow
1516
import semmle.python.ApiGraphs
1617

1718
predicate isUnsafeClientSideAzureStorageEncryptionViaAttributes(Call call, AttrNode node) {
1819
exists(
19-
API::Node n, ControlFlowNode startingNode, Attribute attr, ControlFlowNode ctrlFlowNode,
20-
Attribute attrUploadBlob, ControlFlowNode ctrlFlowNodeUploadBlob, string s1, string s2,
21-
string s3
20+
API::Node client, DataFlow::AttrWrite keyAttrWrite, DataFlow::MethodCallNode uploadBlobCall
2221
|
23-
call.getAChildNode() = attrUploadBlob and
24-
node = ctrlFlowNode
22+
call = uploadBlobCall.asExpr() and node = keyAttrWrite.asCfgNode()
2523
|
26-
s1 in ["key_encryption_key", "key_resolver_function"] and
27-
s2 in ["ContainerClient", "BlobClient", "BlobServiceClient"] and
28-
s3 = "upload_blob" and
29-
n = API::moduleImport("azure").getMember("storage").getMember("blob").getMember(s2).getAMember() and
30-
startingNode = n.getACall().getReturn().getAValueReachableFromSource().asExpr().getAFlowNode() and
31-
startingNode.strictlyReaches(ctrlFlowNode) and
32-
attr.getAFlowNode() = ctrlFlowNode and
33-
attr.getName() = s1 and
34-
ctrlFlowNode.strictlyReaches(ctrlFlowNodeUploadBlob) and
35-
attrUploadBlob.getAFlowNode() = ctrlFlowNodeUploadBlob and
36-
attrUploadBlob.getName() = s3 and
37-
not exists(
38-
Attribute attrBarrier, ControlFlowNode ctrlFlowNodeBarrier, AssignStmt astmt2, StrConst uc
39-
|
40-
startingNode.strictlyReaches(ctrlFlowNodeBarrier) and
41-
attrBarrier.getAFlowNode() = ctrlFlowNodeBarrier and
42-
attrBarrier.getName() = "encryption_version" and
43-
uc = astmt2.getValue() and
44-
uc.getText() in ["'2.0'", "2.0"] and
45-
astmt2.getATarget().getAChildNode*() = attrBarrier and
46-
ctrlFlowNodeBarrier.strictlyReaches(ctrlFlowNodeUploadBlob)
24+
client =
25+
API::moduleImport("azure")
26+
.getMember("storage")
27+
.getMember("blob")
28+
.getMember(["ContainerClient", "BlobClient", "BlobServiceClient"])
29+
.getAMember()
30+
.getReturn() and
31+
keyAttrWrite
32+
.accesses(client.getAValueReachableFromSource(),
33+
["key_encryption_key", "key_resolver_function"]) and
34+
uploadBlobCall.calls(client.getAValueReachableFromSource(), "upload_blob") and
35+
DataFlow::localFlow(keyAttrWrite.getObject(), uploadBlobCall.getObject()) and
36+
not exists(DataFlow::AttrWrite encryptionVersionWrite |
37+
encryptionVersionWrite.accesses(client.getAValueReachableFromSource(), "encryption_version") and
38+
encryptionVersionWrite.getValue().asExpr().(StrConst).getText() in ["'2.0'", "2.0"] and
39+
DataFlow::localFlow(keyAttrWrite.getObject(), encryptionVersionWrite.getObject()) and
40+
DataFlow::localFlow(encryptionVersionWrite.getObject(), uploadBlobCall.getObject())
4741
)
4842
)
4943
}

0 commit comments

Comments
 (0)