44 * The extensible relations have the following columns:
55 *
66 * - Sources:
7- * `crate; path; output; kind; provenance`
7+ * `path; output; kind; provenance`
88 * - Sinks:
9- * `crate; path; input; kind; provenance`
9+ * `path; input; kind; provenance`
1010 * - Summaries:
11- * `crate; path; input; output; kind; provenance`
11+ * `path; input; output; kind; provenance`
1212 *
1313 * The interpretation of a row is similar to API-graphs with a left-to-right
1414 * reading.
1515 *
16- * 1. The `crate` column selects a crate.
17- * 2. The `path` column selects a function with the given canonical path within
18- * the crate.
19- * 3. The `input` column specifies how data enters the element selected by the
20- * first 2 columns, and the `output` column specifies how data leaves the
21- * element selected by the first 2 columns. Both `input` and `output` are
16+ * 1. The `path` column selects a function with the given canonical path.
17+ * 2. The `input` column specifies how data enters the element selected by the
18+ * first column, and the `output` column specifies how data leaves the
19+ * element selected by the first column. Both `input` and `output` are
2220 * `.`-separated lists of "access path tokens" to resolve, starting at the
2321 * selected function.
2422 *
3432 * - `Field[t(i)]`: position `i` inside the variant/struct with canonical path `v`, for example
3533 * `Field[core::option::Option::Some(0)]`.
3634 * - `Field[i]`: the `i`th element of a tuple.
37- * 4 . The `kind` column is a tag that can be referenced from QL to determine to
35+ * 3 . The `kind` column is a tag that can be referenced from QL to determine to
3836 * which classes the interpreted elements should be added. For example, for
3937 * sources `"remote"` indicates a default remote flow source, and for summaries
4038 * `"taint"` indicates a default additional taint step and `"value"` indicates a
4139 * globally applicable value-preserving step.
42- * 5 . The `provenance` column is mainly used internally, and should be set to `"manual"` for
40+ * 4 . The `provenance` column is mainly used internally, and should be set to `"manual"` for
4341 * all custom models.
4442 */
4543
@@ -59,11 +57,26 @@ private import codeql.rust.elements.internal.CallExprBaseImpl::Impl as CallExprB
5957 * For more information on the `kind` parameter, see
6058 * https://github.com/github/codeql/blob/main/docs/codeql/reusables/threat-model-description.rst.
6159 */
60+ // TODO: Remove once all models have been moved to `sourceModelNew`.
6261extensible predicate sourceModel (
6362 string crate , string path , string output , string kind , string provenance ,
6463 QlBuiltins:: ExtensionId madId
6564) ;
6665
66+ /**
67+ * Holds if in a call to the function with canonical path `path`, the value referred
68+ * to by `output` is a flow source of the given `kind`.
69+ *
70+ * `output = "ReturnValue"` simply means the result of the call itself.
71+ *
72+ * For more information on the `kind` parameter, see
73+ * https://github.com/github/codeql/blob/main/docs/codeql/reusables/threat-model-description.rst.
74+ */
75+ // TODO: Rename to `sourceModel` once all models have been moved to this new format.
76+ extensible predicate sourceModelNew (
77+ string path , string output , string kind , string provenance , QlBuiltins:: ExtensionId madId
78+ ) ;
79+
6780/**
6881 * Holds if in a call to the function with canonical path `path`, defined in the
6982 * crate `crate`, the value referred to by `input` is a flow sink of the given
@@ -75,11 +88,27 @@ extensible predicate sourceModel(
7588 *
7689 * - `sql-injection`: a flow sink for SQL injection.
7790 */
91+ // TODO: Remove once all models have been moved to `sinkModelNew`.
7892extensible predicate sinkModel (
7993 string crate , string path , string input , string kind , string provenance ,
8094 QlBuiltins:: ExtensionId madId
8195) ;
8296
97+ /**
98+ * Holds if in a call to the function with canonical path `path`, the value referred
99+ * to by `input` is a flow sink of the given `kind`.
100+ *
101+ * For example, `input = Argument[0]` means the first argument of the call.
102+ *
103+ * The following kinds are supported:
104+ *
105+ * - `sql-injection`: a flow sink for SQL injection.
106+ */
107+ // TODO: Rename to `sinkModel` once all models have been moved to this new format.
108+ extensible predicate sinkModelNew (
109+ string path , string input , string kind , string provenance , QlBuiltins:: ExtensionId madId
110+ ) ;
111+
83112/**
84113 * Holds if in a call to the function with canonical path `path`, defined in the
85114 * crate `crate`, the value referred to by `input` can flow to the value referred
@@ -88,11 +117,25 @@ extensible predicate sinkModel(
88117 * `kind` should be either `value` or `taint`, for value-preserving or taint-preserving
89118 * steps, respectively.
90119 */
120+ // TODO: Remove once all models have been moved to `summaryModelNew`.
91121extensible predicate summaryModel (
92122 string crate , string path , string input , string output , string kind , string provenance ,
93123 QlBuiltins:: ExtensionId madId
94124) ;
95125
126+ /**
127+ * Holds if in a call to the function with canonical path `path`, the value referred
128+ * to by `input` can flow to the value referred to by `output`.
129+ *
130+ * `kind` should be either `value` or `taint`, for value-preserving or taint-preserving
131+ * steps, respectively.
132+ */
133+ // TODO: Rename to `summaryModel` once all models have been moved to this new format.
134+ extensible predicate summaryModelNew (
135+ string path , string input , string output , string kind , string provenance ,
136+ QlBuiltins:: ExtensionId madId
137+ ) ;
138+
96139/**
97140 * Holds if the given extension tuple `madId` should pretty-print as `model`.
98141 *
@@ -104,15 +147,30 @@ predicate interpretModelForTest(QlBuiltins::ExtensionId madId, string model) {
104147 model = "Source: " + crate + "; " + path + "; " + output + "; " + kind
105148 )
106149 or
150+ exists ( string path , string output , string kind |
151+ sourceModelNew ( path , kind , output , _, madId ) and
152+ model = "Source: " + path + "; " + output + "; " + kind
153+ )
154+ or
107155 exists ( string crate , string path , string input , string kind |
108156 sinkModel ( crate , path , kind , input , _, madId ) and
109157 model = "Sink: " + crate + "; " + path + "; " + input + "; " + kind
110158 )
111159 or
160+ exists ( string path , string input , string kind |
161+ sinkModelNew ( path , kind , input , _, madId ) and
162+ model = "Sink: " + path + "; " + input + "; " + kind
163+ )
164+ or
112165 exists ( string type , string path , string input , string output , string kind |
113166 summaryModel ( type , path , input , output , kind , _, madId ) and
114167 model = "Summary: " + type + "; " + path + "; " + input + "; " + output + "; " + kind
115168 )
169+ or
170+ exists ( string path , string input , string output , string kind |
171+ summaryModelNew ( path , input , output , kind , _, madId ) and
172+ model = "Summary: " + path + "; " + input + "; " + output + "; " + kind
173+ )
116174}
117175
118176private class SummarizedCallableFromModel extends SummarizedCallable:: Range {
@@ -145,6 +203,30 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range {
145203 }
146204}
147205
206+ private class SummarizedCallableFromModelNew extends SummarizedCallable:: Range {
207+ private string path ;
208+
209+ SummarizedCallableFromModelNew ( ) {
210+ summaryModelNew ( path , _, _, _, _, _) and
211+ this .getCanonicalPath ( ) = path
212+ }
213+
214+ override predicate propagatesFlow (
215+ string input , string output , boolean preservesValue , string model
216+ ) {
217+ exists ( string kind , QlBuiltins:: ExtensionId madId |
218+ summaryModelNew ( path , input , output , kind , _, madId ) and
219+ model = "MaD:" + madId .toString ( )
220+ |
221+ kind = "value" and
222+ preservesValue = true
223+ or
224+ kind = "taint" and
225+ preservesValue = false
226+ )
227+ }
228+ }
229+
148230private class FlowSourceFromModel extends FlowSource:: Range {
149231 private string crate ;
150232 private string path ;
@@ -162,6 +244,22 @@ private class FlowSourceFromModel extends FlowSource::Range {
162244 }
163245}
164246
247+ private class FlowSourceFromModelNew extends FlowSource:: Range {
248+ private string path ;
249+
250+ FlowSourceFromModelNew ( ) {
251+ sourceModelNew ( path , _, _, _, _) and
252+ this .callResolvesTo ( path )
253+ }
254+
255+ override predicate isSource ( string output , string kind , Provenance provenance , string model ) {
256+ exists ( QlBuiltins:: ExtensionId madId |
257+ sourceModelNew ( path , output , kind , provenance , madId ) and
258+ model = "MaD:" + madId .toString ( )
259+ )
260+ }
261+ }
262+
165263private class FlowSinkFromModel extends FlowSink:: Range {
166264 private string crate ;
167265 private string path ;
@@ -178,3 +276,19 @@ private class FlowSinkFromModel extends FlowSink::Range {
178276 )
179277 }
180278}
279+
280+ private class FlowSinkFromModelNew extends FlowSink:: Range {
281+ private string path ;
282+
283+ FlowSinkFromModelNew ( ) {
284+ sinkModelNew ( path , _, _, _, _) and
285+ this .callResolvesTo ( path )
286+ }
287+
288+ override predicate isSink ( string input , string kind , Provenance provenance , string model ) {
289+ exists ( QlBuiltins:: ExtensionId madId |
290+ sinkModelNew ( path , input , kind , provenance , madId ) and
291+ model = "MaD:" + madId .toString ( )
292+ )
293+ }
294+ }
0 commit comments