|
| 1 | +/** |
| 2 | + * Provides abstract classes representing generic concepts such as file system |
| 3 | + * access or system command execution, for which individual framework libraries |
| 4 | + * provide concrete subclasses. |
| 5 | + */ |
| 6 | + |
| 7 | +private import codeql.rust.dataflow.DataFlow |
| 8 | +private import codeql.threatmodels.ThreatModels |
| 9 | + |
| 10 | +/** |
| 11 | + * A data flow source for a specific threat-model. |
| 12 | + * |
| 13 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 14 | + * extend `ThreatModelSource::Range` instead. |
| 15 | + */ |
| 16 | +final class ThreatModelSource = ThreatModelSource::Range; |
| 17 | + |
| 18 | +/** |
| 19 | + * Provides a class for modeling new sources for specific threat-models. |
| 20 | + */ |
| 21 | +module ThreatModelSource { |
| 22 | + /** |
| 23 | + * A data flow source, for a specific threat-model. |
| 24 | + */ |
| 25 | + abstract class Range extends DataFlow::Node { |
| 26 | + /** |
| 27 | + * Gets a string that represents the source kind with respect to threat modeling. |
| 28 | + * |
| 29 | + * See |
| 30 | + * - https://github.com/github/codeql/blob/main/docs/codeql/reusables/threat-model-description.rst |
| 31 | + * - https://github.com/github/codeql/blob/main/shared/threat-models/ext/threat-model-grouping.model.yml |
| 32 | + */ |
| 33 | + abstract string getThreatModel(); |
| 34 | + |
| 35 | + /** |
| 36 | + * Gets a string that describes the type of this threat-model source. |
| 37 | + */ |
| 38 | + abstract string getSourceType(); |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * A data flow source that is enabled in the current threat model configuration. |
| 44 | + */ |
| 45 | +class ActiveThreatModelSource extends ThreatModelSource { |
| 46 | + ActiveThreatModelSource() { currentThreatModel(this.getThreatModel()) } |
| 47 | +} |
| 48 | + |
| 49 | +/** |
| 50 | + * A data-flow node that constructs a SQL statement. |
| 51 | + * |
| 52 | + * Often, it is worthy of an alert if a SQL statement is constructed such that |
| 53 | + * executing it would be a security risk. |
| 54 | + * |
| 55 | + * If it is important that the SQL statement is executed, use `SqlExecution`. |
| 56 | + * |
| 57 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 58 | + * extend `SqlConstruction::Range` instead. |
| 59 | + */ |
| 60 | +final class SqlConstruction = SqlConstruction::Range; |
| 61 | + |
| 62 | +/** |
| 63 | + * Provides a class for modeling new SQL execution APIs. |
| 64 | + */ |
| 65 | +module SqlConstruction { |
| 66 | + /** |
| 67 | + * A data-flow node that constructs a SQL statement. |
| 68 | + */ |
| 69 | + abstract class Range extends DataFlow::Node { |
| 70 | + /** |
| 71 | + * Gets the argument that specifies the SQL statements to be constructed. |
| 72 | + */ |
| 73 | + abstract DataFlow::Node getSql(); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * A data-flow node that executes SQL statements. |
| 79 | + * |
| 80 | + * If the context of interest is such that merely constructing a SQL statement |
| 81 | + * would be valuable to report, consider using `SqlConstruction`. |
| 82 | + * |
| 83 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 84 | + * extend `SqlExecution::Range` instead. |
| 85 | + */ |
| 86 | +final class SqlExecution = SqlExecution::Range; |
| 87 | + |
| 88 | +/** |
| 89 | + * Provides a class for modeling new SQL execution APIs. |
| 90 | + */ |
| 91 | +module SqlExecution { |
| 92 | + /** |
| 93 | + * A data-flow node that executes SQL statements. |
| 94 | + */ |
| 95 | + abstract class Range extends DataFlow::Node { |
| 96 | + /** |
| 97 | + * Gets the argument that specifies the SQL statements to be executed. |
| 98 | + */ |
| 99 | + abstract DataFlow::Node getSql(); |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +/** |
| 104 | + * A data-flow node that performs SQL sanitization. |
| 105 | + */ |
| 106 | +final class SqlSanitization = SqlSanitization::Range; |
| 107 | + |
| 108 | +/** |
| 109 | + * Provides a class for modeling new SQL sanitization APIs. |
| 110 | + */ |
| 111 | +module SqlSanitization { |
| 112 | + /** |
| 113 | + * A data-flow node that performs SQL sanitization. |
| 114 | + */ |
| 115 | + abstract class Range extends DataFlow::Node { } |
| 116 | +} |
0 commit comments