Skip to content

Commit 79bef11

Browse files
committed
Python: Use "new" SensitiveDataHeuristics
1 parent ffad65b commit 79bef11

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ private import semmle.python.dataflow.new.DataFlow
99
private import semmle.python.Frameworks
1010
private import semmle.python.Concepts
1111
private import semmle.python.security.SensitiveData as OldSensitiveData
12+
private import semmle.python.security.internal.SensitiveDataHeuristics as SensitiveDataHeuristics
13+
14+
// We export these explicitly, so we don't also export the `HeuristicNames` module.
15+
class SensitiveDataClassification = SensitiveDataHeuristics::SensitiveDataClassification;
16+
17+
module SensitiveDataClassification = SensitiveDataHeuristics::SensitiveDataClassification;
1218

1319
/**
1420
* A data flow source of sensitive data, such as secrets, certificates, or passwords.
@@ -22,13 +28,9 @@ class SensitiveDataSource extends DataFlow::Node {
2228
SensitiveDataSource() { this = range }
2329

2430
/**
25-
* INTERNAL: Do not use.
26-
*
27-
* This will be rewritten to have better types soon, and therefore should only be used internally until then.
28-
*
2931
* Gets the classification of the sensitive data.
3032
*/
31-
string getClassification() { result = range.getClassification() }
33+
SensitiveDataClassification getClassification() { result = range.getClassification() }
3234
}
3335

3436
/** Provides a class for modeling new sources of sensitive data, such as secrets, certificates, or passwords. */
@@ -41,22 +43,19 @@ module SensitiveDataSource {
4143
*/
4244
abstract class Range extends DataFlow::Node {
4345
/**
44-
* INTERNAL: Do not use.
45-
*
46-
* This will be rewritten to have better types soon, and therefore should only be used internally until then.
47-
*
4846
* Gets the classification of the sensitive data.
4947
*/
50-
abstract string getClassification();
48+
abstract SensitiveDataClassification getClassification();
5149
}
5250
}
5351

52+
// TODO: rewrite this to not rely on the old points-to implementation
5453
private class PortOfOldModeling extends SensitiveDataSource::Range {
5554
OldSensitiveData::SensitiveData::Source oldSensitiveSource;
5655

5756
PortOfOldModeling() { this.asCfgNode() = oldSensitiveSource }
5857

59-
override string getClassification() {
58+
override SensitiveDataClassification getClassification() {
6059
exists(OldSensitiveData::SensitiveData classification |
6160
oldSensitiveSource.isSourceOf(classification)
6261
|

python/ql/src/semmle/python/security/dataflow/WeakSensitiveDataHashingCustomizations.qll

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ module NormalHashFunction {
5252
* A source of sensitive data, considered as a flow source.
5353
*/
5454
class SensitiveDataSourceAsSource extends Source, SensitiveDataSource {
55-
override string getClassification() { result = SensitiveDataSource.super.getClassification() }
55+
override SensitiveDataClassification getClassification() {
56+
result = SensitiveDataSource.super.getClassification()
57+
}
5658
}
5759

5860
/** The input to a hashing operation using a weak algorithm, considered as a flow sink. */
@@ -120,12 +122,12 @@ module ComputationallyExpensiveHashFunction {
120122
*/
121123
class PasswordSourceAsSource extends Source, SensitiveDataSource {
122124
PasswordSourceAsSource() {
123-
// TODO: once https://github.com/github/codeql/pull/5739 has been merged,
124-
// don't use hardcoded value anymore
125-
SensitiveDataSource.super.getClassification() = "password"
125+
SensitiveDataSource.super.getClassification() = SensitiveDataClassification::password()
126126
}
127127

128-
override string getClassification() { result = SensitiveDataSource.super.getClassification() }
128+
override SensitiveDataClassification getClassification() {
129+
result = SensitiveDataSource.super.getClassification()
130+
}
129131
}
130132

131133
/**

0 commit comments

Comments
 (0)