@@ -16,76 +16,38 @@ import semmle.python.ApiGraphs
1616
1717predicate isUnsafeClientSideAzureStorageEncryptionViaAttributes ( Call call , AttrNode node ) {
1818 exists (
19- API:: Node n , API:: Node n2 , Attribute a , AssignStmt astmt , API:: Node uploadBlob ,
20- ControlFlowNode ctrlFlowNode , string s
19+ API:: Node n , ControlFlowNode startingNode , Attribute attr , ControlFlowNode ctrlFlowNode ,
20+ Attribute attrUploadBlob , ControlFlowNode ctrlFlowNodeUploadBlob , string s1 , string s2 ,
21+ string s3
2122 |
22- s in [ "key_encryption_key" , "key_resolver_function" ] and
23- n =
24- API:: moduleImport ( "azure" )
25- .getMember ( "storage" )
26- .getMember ( "blob" )
27- .getMember ( "BlobClient" )
28- .getReturn ( )
29- .getMember ( s ) and
30- n2 =
31- API:: moduleImport ( "azure" )
32- .getMember ( "storage" )
33- .getMember ( "blob" )
34- .getMember ( "BlobClient" )
35- .getReturn ( )
36- .getMember ( "upload_blob" ) and
37- n .getAValueReachableFromSource ( ) .asExpr ( ) = a and
38- astmt .getATarget ( ) = a and
39- a .getAFlowNode ( ) = node and
40- uploadBlob =
41- API:: moduleImport ( "azure" )
42- .getMember ( "storage" )
43- .getMember ( "blob" )
44- .getMember ( "BlobClient" )
45- .getReturn ( )
46- .getMember ( "upload_blob" ) and
47- uploadBlob .getACall ( ) .asExpr ( ) = call and
48- ctrlFlowNode = call .getAFlowNode ( ) and
49- node .strictlyReaches ( ctrlFlowNode ) and
50- node != ctrlFlowNode and
23+ call .getAChildNode ( ) = attrUploadBlob and
24+ node = ctrlFlowNode
25+ |
26+ s1 in [ "key_encryption_key" , "key_resolver_function" ] and
27+ s2 in [ "ContainerClient" , "BlobClient" , "BlobServiceClient" ] and
28+ s3 in [ "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
5137 not exists (
52- AssignStmt astmt2 , Attribute a2 , AttrNode encryptionVersionSet , StrConst uc ,
53- API:: Node encryptionVersion
38+ Attribute attrBarrier , ControlFlowNode ctrlFlowNodeBarrier , AssignStmt astmt2 , StrConst uc
5439 |
40+ startingNode .strictlyReaches ( ctrlFlowNodeBarrier ) and
41+ attrBarrier .getAFlowNode ( ) = ctrlFlowNodeBarrier and
42+ attrBarrier .getName ( ) = "encryption_version" and
5543 uc = astmt2 .getValue ( ) and
5644 uc .getText ( ) in [ "'2.0'" , "2.0" ] and
57- encryptionVersion =
58- API:: moduleImport ( "azure" )
59- .getMember ( "storage" )
60- .getMember ( "blob" )
61- .getMember ( "BlobClient" )
62- .getReturn ( )
63- .getMember ( "encryption_version" ) and
64- encryptionVersion .getAValueReachableFromSource ( ) .asExpr ( ) = a2 and
65- astmt2 .getATarget ( ) = a2 and
66- a2 .getAFlowNode ( ) = encryptionVersionSet and
67- encryptionVersionSet .strictlyReaches ( ctrlFlowNode )
68- )
69- )
70- }
71-
72- predicate isUnsafeClientSideAzureStorageEncryptionViaObjectCreation ( Call call , ControlFlowNode node ) {
73- exists ( API:: Node c , string s , Keyword k | k .getAFlowNode ( ) = node |
74- c .getACall ( ) .asExpr ( ) = call and
75- c = API:: moduleImport ( "azure" ) .getMember ( "storage" ) .getMember ( "blob" ) .getMember ( s ) and
76- s in [ "ContainerClient" , "BlobClient" , "BlobServiceClient" ] and
77- k .getArg ( ) = "key_encryption_key" and
78- k = call .getANamedArg ( ) and
79- not k .getValue ( ) instanceof None and
80- not exists ( Keyword k2 | k2 = call .getANamedArg ( ) |
81- k2 .getArg ( ) = "encryption_version" and
82- k2 .getValue ( ) .( StrConst ) .getText ( ) in [ "'2.0'" , "2.0" ]
45+ astmt2 .getATarget ( ) .getAChildNode * ( ) = attrBarrier and
46+ ctrlFlowNodeBarrier .strictlyReaches ( ctrlFlowNodeUploadBlob )
8347 )
8448 )
8549}
8650
8751from Call call , ControlFlowNode node
88- where
89- isUnsafeClientSideAzureStorageEncryptionViaAttributes ( call , node ) or
90- isUnsafeClientSideAzureStorageEncryptionViaObjectCreation ( call , node )
52+ where isUnsafeClientSideAzureStorageEncryptionViaAttributes ( call , node )
9153select node , "Unsafe usage of v1 version of Azure Storage client-side encryption."
0 commit comments