Skip to content

Commit eb4f168

Browse files
committed
Python: Clarify SensitiveAttributeAccess
The comment about imports was placed wrong. I also realized we didn't even have a single test-case for `this.(DataFlow::AttrRead).getAttributeNameExpr() = sensitiveLookupStringConst(classification)` so I added that (notice that this is only `getattr(foo, x)` and not `getattr(foo, "password")`)
1 parent 3819a36 commit eb4f168

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ private module SensitiveDataModeling {
153153
SensitiveDataClassification classification;
154154

155155
SensitiveAttributeAccess() {
156-
nameIndicatesSensitiveData(this.(DataFlow::AttrRead).getAttributeName(), classification)
157-
or
156+
// Things like `foo.<sensitive-name>` or `from <module> import <sensitive-name>`
158157
// I considered excluding any `from ... import something_sensitive`, but then realized that
159158
// we should flag up `form ... import password as ...` as a password
159+
nameIndicatesSensitiveData(this.(DataFlow::AttrRead).getAttributeName(), classification)
160+
or
161+
// Things like `getattr(foo, <reference-to-string>)`
160162
this.(DataFlow::AttrRead).getAttributeNameExpr() = sensitiveLookupStringConst(classification)
161163
}
162164

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ def encrypt_password(pwd):
2929
foo.secret # $ SensitiveDataSource=secret
3030
foo.username # $ SensitiveDataSource=id
3131

32+
getattr(foo, "password") # $ SensitiveDataSource=password
33+
x = "password"
34+
getattr(foo, x) # $ SensitiveDataSource=password
3235

3336
# based on variable/parameter names
3437
def my_func(password): # $ SensitiveDataSource=password

0 commit comments

Comments
 (0)