|
| 1 | +/** |
| 2 | + * Defines extensible predicates for contributing library models from data extensions. |
| 3 | + */ |
| 4 | + |
| 5 | +private import rust |
| 6 | +private import codeql.rust.dataflow.FlowSummary |
| 7 | + |
| 8 | +/** |
| 9 | + * Holds if in a call to the function with canonical path `path`, defined in the |
| 10 | + * crate `crate`, the value referred to by `output` is a flow source of the given |
| 11 | + * `kind`. |
| 12 | + * |
| 13 | + * `output = "ReturnValue"` simply means the result of the call itself. |
| 14 | + * |
| 15 | + * The following kinds are supported: |
| 16 | + * |
| 17 | + * - `remote`: a general remote flow source. |
| 18 | + */ |
| 19 | +extensible predicate sourceModel( |
| 20 | + string crate, string path, string output, string kind, string provenance, |
| 21 | + QlBuiltins::ExtensionId madId |
| 22 | +); |
| 23 | + |
| 24 | +/** |
| 25 | + * Holds if in a call to the function with canonical path `path`, defined in the |
| 26 | + * crate `crate`, the value referred to by `input` is a flow sink of the given |
| 27 | + * `kind`. |
| 28 | + * |
| 29 | + * For example, `input = Argument[0]` means the first argument of the call. |
| 30 | + * |
| 31 | + * The following kinds are supported: |
| 32 | + * |
| 33 | + * - `sql-injection`: a flow sink for SQL injection. |
| 34 | + */ |
| 35 | +extensible predicate sinkModel( |
| 36 | + string crate, string path, string input, string kind, string provenance, |
| 37 | + QlBuiltins::ExtensionId madId |
| 38 | +); |
| 39 | + |
| 40 | +/** |
| 41 | + * Holds if in a call to the function with canonical path `path`, defined in the |
| 42 | + * crate `crate`, the value referred to by `input` can flow to the value referred |
| 43 | + * to by `output`. |
| 44 | + * |
| 45 | + * `kind` should be either `value` or `taint`, for value-preserving or taint-preserving |
| 46 | + * steps, respectively. |
| 47 | + */ |
| 48 | +extensible predicate summaryModel( |
| 49 | + string crate, string path, string input, string output, string kind, string provenance, |
| 50 | + QlBuiltins::ExtensionId madId |
| 51 | +); |
| 52 | + |
| 53 | +/** |
| 54 | + * Holds if the given extension tuple `madId` should pretty-print as `model`. |
| 55 | + * |
| 56 | + * This predicate should only be used in tests. |
| 57 | + */ |
| 58 | +predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) { |
| 59 | + exists(string crate, string path, string output, string kind | |
| 60 | + sourceModel(crate, path, kind, output, _, madId) and |
| 61 | + model = "Source: " + crate + "; " + path + "; " + output + "; " + kind |
| 62 | + ) |
| 63 | + or |
| 64 | + exists(string crate, string path, string input, string kind | |
| 65 | + sinkModel(crate, path, kind, input, _, madId) and |
| 66 | + model = "Sink: " + crate + "; " + path + "; " + input + "; " + kind |
| 67 | + ) |
| 68 | + or |
| 69 | + exists(string type, string path, string input, string output, string kind | |
| 70 | + summaryModel(type, path, input, output, kind, _, madId) and |
| 71 | + model = "Summary: " + type + "; " + path + "; " + input + "; " + output + "; " + kind |
| 72 | + ) |
| 73 | +} |
| 74 | + |
| 75 | +private class SummarizedCallableFromModel extends SummarizedCallable::Range { |
| 76 | + private string crate; |
| 77 | + private string path; |
| 78 | + |
| 79 | + SummarizedCallableFromModel() { |
| 80 | + summaryModel(crate, path, _, _, _, _, _) and |
| 81 | + this = crate + "::_::" + path |
| 82 | + } |
| 83 | + |
| 84 | + override predicate propagatesFlow( |
| 85 | + string input, string output, boolean preservesValue, string model |
| 86 | + ) { |
| 87 | + exists(string kind, QlBuiltins::ExtensionId madId | |
| 88 | + summaryModel(crate, path, input, output, kind, _, madId) and |
| 89 | + model = "MaD:" + madId.toString() |
| 90 | + | |
| 91 | + kind = "value" and |
| 92 | + preservesValue = true |
| 93 | + or |
| 94 | + kind = "taint" and |
| 95 | + preservesValue = false |
| 96 | + ) |
| 97 | + } |
| 98 | +} |
0 commit comments