|
| 1 | +/** |
| 2 | + * Provides an extension point for for modeling sensitive data, such as secrets, certificates, or passwords. |
| 3 | + * Sensitive data is can be interesting to use as data-flow sources in security queries. |
| 4 | + */ |
| 5 | + |
| 6 | +private import python |
| 7 | +private import semmle.python.dataflow.new.DataFlow |
| 8 | +// Need to import since frameworks can extend `RemoteFlowSource::Range` |
| 9 | +private import semmle.python.Frameworks |
| 10 | +private import semmle.python.Concepts |
| 11 | +private import semmle.python.security.SensitiveData as OldSensitiveData |
| 12 | + |
| 13 | +/** |
| 14 | + * A data flow source of sensitive data, such as secrets, certificates, or passwords. |
| 15 | + * |
| 16 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 17 | + * extend `SensitiveDataSource::Range` instead. |
| 18 | + */ |
| 19 | +class SensitiveDataSource extends DataFlow::Node { |
| 20 | + SensitiveDataSource::Range range; |
| 21 | + |
| 22 | + SensitiveDataSource() { this = range } |
| 23 | + |
| 24 | + /** |
| 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 | + * |
| 29 | + * Gets the classification of the sensitive data. |
| 30 | + */ |
| 31 | + string getClassification() { result = range.getClassification() } |
| 32 | +} |
| 33 | + |
| 34 | +/** Provides a class for modeling new sources of sensitive data, such as secrets, certificates, or passwords. */ |
| 35 | +module SensitiveDataSource { |
| 36 | + /** |
| 37 | + * A data flow source of sensitive data, such as secrets, certificates, or passwords. |
| 38 | + * |
| 39 | + * Extend this class to model new APIs. If you want to refine existing API models, |
| 40 | + * extend `SensitiveDataSource` instead. |
| 41 | + */ |
| 42 | + abstract class Range extends DataFlow::Node { |
| 43 | + /** |
| 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 | + * |
| 48 | + * Gets the classification of the sensitive data. |
| 49 | + */ |
| 50 | + abstract string getClassification(); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +private class PortOfOldModeling extends SensitiveDataSource::Range { |
| 55 | + OldSensitiveData::SensitiveData::Source oldSensitiveSource; |
| 56 | + |
| 57 | + PortOfOldModeling() { this.asCfgNode() = oldSensitiveSource } |
| 58 | + |
| 59 | + override string getClassification() { |
| 60 | + exists(OldSensitiveData::SensitiveData classification | |
| 61 | + oldSensitiveSource.isSourceOf(classification) |
| 62 | + | |
| 63 | + classification = "sensitive.data." + result |
| 64 | + ) |
| 65 | + } |
| 66 | +} |
0 commit comments