Skip to content

Commit b0309dd

Browse files
committed
Python: Limit SensitiveDataSources to prevent _some_ cross-talk
1 parent f64e58a commit b0309dd

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,16 @@ private module SensitiveDataModeling {
7676
}
7777

7878
/**
79-
* Gets a reference to a string constant that, if used as the key in a lookup,
80-
* indicates the presence of sensitive data with `classification`.
81-
*/
82-
private DataFlow::LocalSourceNode sensitiveLookupStringConst(
83-
DataFlow::TypeTracker t, SensitiveDataClassification classification
84-
) {
85-
t.start() and
86-
nameIndicatesSensitiveData(result.asExpr().(StrConst).getText(), classification)
87-
or
88-
exists(DataFlow::TypeTracker t2 |
89-
result = sensitiveLookupStringConst(t2, classification).track(t2, t)
90-
)
91-
}
92-
93-
/**
94-
* Gets a reference to a string constant that, if used as the key in a lookup,
95-
* indicates the presence of sensitive data with `classification`.
79+
* Gets a reference (in local scope) to a string constant that, if used as the key in
80+
* a lookup, indicates the presence of sensitive data with `classification`.
9681
*/
9782
DataFlow::Node sensitiveLookupStringConst(SensitiveDataClassification classification) {
98-
sensitiveLookupStringConst(DataFlow::TypeTracker::end(), classification).flowsTo(result)
83+
// Note: If this is implemented with type-tracking, we will get cross-talk as
84+
// illustrated in python/ql/test/experimental/dataflow/sensitive-data/test.py
85+
exists(DataFlow::LocalSourceNode source |
86+
nameIndicatesSensitiveData(source.asExpr().(StrConst).getText(), classification) and
87+
source.flowsTo(result)
88+
)
9989
}
10090

10191
/** A function call that is considered a source of sensitive data. */

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ def my_func(password): # $ SensitiveDataSource=password
9090
def get_config(key):
9191
# Treating this as a SensitiveDataSource is questionable, since that will result in
9292
# _all_ calls to `get_config` being treated as giving sensitive data
93-
return _configuration[key] # $ SensitiveDataSource=password
93+
return _configuration[key]
9494

9595
foo = get_config("mysql_password")
96-
print(foo) # $ SensitiveUse=password
96+
print(foo) # $ MISSING: SensitiveUse=password
9797

9898
bar = get_config("sleep_timer")
99-
print(bar) # $ SPURIOUS: SensitiveUse=password
99+
print(bar)
100100

101101
# Case 2: Providing function as argument
102102

0 commit comments

Comments
 (0)