Skip to content

Commit f5fd0f8

Browse files
committed
Python: Model sensitive data based on parameter names
1 parent 925e67d commit f5fd0f8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

python/ql/src/semmle/python/dataflow/new/SensitiveDataSources.qll

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,15 @@ private module SensitiveDataModeling {
149149

150150
override SensitiveDataClassification getClassification() { result = classification }
151151
}
152+
153+
/** A parameter where the name indicates it will receive sensitive data. */
154+
class SensitiveParameter extends SensitiveDataSource::Range, DataFlow::ParameterNode {
155+
SensitiveDataClassification classification;
156+
157+
SensitiveParameter() {
158+
nameIndicatesSensitiveData(this.getParameter().getName(), classification)
159+
}
160+
161+
override SensitiveDataClassification getClassification() { result = classification }
162+
}
152163
}

python/ql/test/experimental/dataflow/sensitive-data/test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ def encrypt_password(pwd):
2929
foo.secret # $ SensitiveDataSource=secret
3030
foo.username # $ SensitiveDataSource=id
3131

32-
# plain variables
32+
# based on variable/parameter names
33+
def my_func(password): # $ SensitiveDataSource=password
34+
print(password) # $ SensitiveUse=password
35+
3336
password = some_function()
3437
print(password) # $ MISSING: SensitiveUse=password
3538

0 commit comments

Comments
 (0)