|
12 | 12 | */
|
13 | 13 |
|
14 | 14 | import python
|
| 15 | +import semmle.python.dataflow.new.DataFlow |
15 | 16 | import semmle.python.ApiGraphs
|
16 | 17 |
|
17 | 18 | predicate isUnsafeClientSideAzureStorageEncryptionViaAttributes(Call call, AttrNode node) {
|
18 | 19 | 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 |
22 | 21 | |
|
23 |
| - call.getAChildNode() = attrUploadBlob and |
24 |
| - node = ctrlFlowNode |
| 22 | + call = uploadBlobCall.asExpr() and node = keyAttrWrite.asCfgNode() |
25 | 23 | |
|
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()) |
47 | 41 | )
|
48 | 42 | )
|
49 | 43 | }
|
|
0 commit comments