Skip to content

Commit 691ffcd

Browse files
committed
Python: Add tests of py/azure-storage/unsafe-client-side-encryption-in-use
Notice that it doesn't find the potentially unsafe version, or the vuln that spans calls.
1 parent 4ba1740 commit 691ffcd

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.py:8:5:8:34 | ControlFlowNode for Attribute | Unsafe usage of v1 version of Azure Storage client-side encryption. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
experimental/Security/CWE-327/Azure/UnsafeUsageOfClientSideEncryptionVersion.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from azure.storage.blob import BlobServiceClient
2+
3+
4+
def unsafe():
5+
# does not set encryption_version to 2.0, default is unsafe
6+
blob_client = BlobServiceClient.get_blob_client(...)
7+
blob_client.require_encryption = True
8+
blob_client.key_encryption_key = ...
9+
with open("decryptedcontentfile.txt", "rb") as stream:
10+
blob_client.upload_blob(stream) # BAD
11+
12+
13+
def potentially_unsafe(use_new_version=False):
14+
blob_client = BlobServiceClient.get_blob_client(...)
15+
blob_client.require_encryption = True
16+
blob_client.key_encryption_key = ...
17+
18+
if use_new_version:
19+
blob_client.encryption_version = '2.0'
20+
21+
with open("decryptedcontentfile.txt", "rb") as stream:
22+
blob_client.upload_blob(stream) # BAD
23+
24+
25+
def safe():
26+
blob_client = BlobServiceClient.get_blob_client(...)
27+
blob_client.require_encryption = True
28+
blob_client.key_encryption_key = ...
29+
# GOOD: Must use `encryption_version` set to `2.0`
30+
blob_client.encryption_version = '2.0'
31+
with open("decryptedcontentfile.txt", "rb") as stream:
32+
blob_client.upload_blob(stream) # OK
33+
34+
35+
def get_unsafe_blob_client():
36+
blob_client = BlobServiceClient.get_blob_client(...)
37+
blob_client.require_encryption = True
38+
blob_client.key_encryption_key = ...
39+
return blob_client
40+
41+
42+
def unsafe_with_calls():
43+
bc = get_unsafe_blob_client()
44+
with open("decryptedcontentfile.txt", "rb") as stream:
45+
bc.upload_blob(stream) # BAD
46+
47+
48+
def get_safe_blob_client():
49+
blob_client = BlobServiceClient.get_blob_client(...)
50+
blob_client.require_encryption = True
51+
blob_client.key_encryption_key = ...
52+
blob_client.encryption_version = '2.0'
53+
return blob_client
54+
55+
56+
def safe_with_calls():
57+
bc = get_safe_blob_client()
58+
with open("decryptedcontentfile.txt", "rb") as stream:
59+
bc.upload_blob(stream) # OK

0 commit comments

Comments
 (0)