|
| 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 | +class ThreatModelSource extends DataFlow::Node instanceof ThreatModelSource::Range { |
| 17 | + /** |
| 18 | + * Gets a string that represents the source kind with respect to threat modeling. |
| 19 | + * |
| 20 | + * See |
| 21 | + * - https://github.com/github/codeql/blob/main/docs/codeql/reusables/threat-model-description.rst |
| 22 | + * - https://github.com/github/codeql/blob/main/shared/threat-models/ext/threat-model-grouping.model.yml |
| 23 | + */ |
| 24 | + string getThreatModel() { result = super.getThreatModel() } |
| 25 | + |
| 26 | + /** |
| 27 | + * Gets a string that describes the type of this threat-model source. |
| 28 | + */ |
| 29 | + string getSourceType() { result = super.getSourceType() } |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Provides a class for modeling new sources for specific threat-models. |
| 34 | + */ |
| 35 | +module ThreatModelSource { |
| 36 | + /** |
| 37 | + * A data flow source, for a specific threat-model. |
| 38 | + */ |
| 39 | + abstract class Range extends DataFlow::Node { |
| 40 | + /** |
| 41 | + * Gets a string that represents the source kind with respect to threat modeling. |
| 42 | + */ |
| 43 | + abstract string getThreatModel(); |
| 44 | + |
| 45 | + /** |
| 46 | + * Gets a string that describes the type of this threat-model source. |
| 47 | + */ |
| 48 | + abstract string getSourceType(); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +/** |
| 53 | + * A data flow source that is enabled in the current threat model configuration. |
| 54 | + */ |
| 55 | +class ActiveThreatModelSource extends ThreatModelSource { |
| 56 | + ActiveThreatModelSource() { |
| 57 | + currentThreatModel(this.getThreatModel()) |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +/** |
| 62 | + * A data-flow node that constructs a SQL statement. |
| 63 | + * |
| 64 | + * Often, it is worthy of an alert if a SQL statement is constructed such that |
| 65 | + * executing it would be a security risk. |
| 66 | + * |
| 67 | + * If it is important that the SQL statement is executed, use `SqlExecution`. |
| 68 | + * |
| 69 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 70 | + * extend `SqlConstruction::Range` instead. |
| 71 | + */ |
| 72 | +class SqlConstruction extends DataFlow::Node instanceof SqlConstruction::Range { |
| 73 | + /** |
| 74 | + * Gets the argument that specifies the SQL statements to be constructed. |
| 75 | + */ |
| 76 | + DataFlow::Node getSql() { result = super.getSql() } |
| 77 | +} |
| 78 | + |
| 79 | +/** |
| 80 | + * Provides a class for modeling new SQL execution APIs. |
| 81 | + */ |
| 82 | +module SqlConstruction { |
| 83 | + /** |
| 84 | + * A data-flow node that constructs a SQL statement. |
| 85 | + */ |
| 86 | + abstract class Range extends DataFlow::Node { |
| 87 | + /** |
| 88 | + * Gets the argument that specifies the SQL statements to be constructed. |
| 89 | + */ |
| 90 | + abstract DataFlow::Node getSql(); |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +/** |
| 95 | + * A data-flow node that executes SQL statements. |
| 96 | + * |
| 97 | + * If the context of interest is such that merely constructing a SQL statement |
| 98 | + * would be valuable to report, consider using `SqlConstruction`. |
| 99 | + * |
| 100 | + * Extend this class to refine existing API models. If you want to model new APIs, |
| 101 | + * extend `SqlExecution::Range` instead. |
| 102 | + */ |
| 103 | +class SqlExecution extends DataFlow::Node instanceof SqlExecution::Range { |
| 104 | + /** |
| 105 | + * Gets the argument that specifies the SQL statements to be executed. |
| 106 | + */ |
| 107 | + DataFlow::Node getSql() { result = super.getSql() } |
| 108 | +} |
| 109 | + |
| 110 | +/** |
| 111 | + * Provides a class for modeling new SQL execution APIs. |
| 112 | + */ |
| 113 | +module SqlExecution { |
| 114 | + /** |
| 115 | + * A data-flow node that executes SQL statements. |
| 116 | + */ |
| 117 | + abstract class Range extends DataFlow::Node { |
| 118 | + /** |
| 119 | + * Gets the argument that specifies the SQL statements to be executed. |
| 120 | + */ |
| 121 | + abstract DataFlow::Node getSql(); |
| 122 | + } |
| 123 | +} |
| 124 | + |
| 125 | +/** |
| 126 | + * A data-flow node that performs SQL sanitization. |
| 127 | + */ |
| 128 | +class SqlSanitization extends DataFlow::Node instanceof SqlSanitization::Range { } |
| 129 | + |
| 130 | +/** |
| 131 | + * Provides a class for modeling new SQL sanitization APIs. |
| 132 | + */ |
| 133 | +module SqlSanitization { |
| 134 | + /** |
| 135 | + * A data-flow node that performs SQL sanitization. |
| 136 | + */ |
| 137 | + abstract class Range extends DataFlow::Node { } |
| 138 | +} |
0 commit comments