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
@@ -50,6 +48,8 @@ private import codeql.rust.dataflow.FlowSink
5048private import codeql.rust.elements.internal.CallExprBaseImpl:: Impl as CallExprBaseImpl
5149
5250/**
51+ * DEPRECATED: Do not use.
52+ *
5353 * Holds if in a call to the function with canonical path `path`, defined in the
5454 * crate `crate`, the value referred to by `output` is a flow source of the given
5555 * `kind`.
@@ -59,12 +59,27 @@ private import codeql.rust.elements.internal.CallExprBaseImpl::Impl as CallExprB
5959 * For more information on the `kind` parameter, see
6060 * https://github.com/github/codeql/blob/main/docs/codeql/reusables/threat-model-description.rst.
6161 */
62- extensible predicate sourceModel (
62+ extensible predicate sourceModelDeprecated (
6363 string crate , string path , string output , string kind , string provenance ,
6464 QlBuiltins:: ExtensionId madId
6565) ;
6666
6767/**
68+ * Holds if in a call to the function with canonical path `path`, the value referred
69+ * to by `output` is a flow source of the given `kind`.
70+ *
71+ * `output = "ReturnValue"` simply means the result of the call itself.
72+ *
73+ * For more information on the `kind` parameter, see
74+ * https://github.com/github/codeql/blob/main/docs/codeql/reusables/threat-model-description.rst.
75+ */
76+ extensible predicate sourceModel (
77+ string path , string output , string kind , string provenance , QlBuiltins:: ExtensionId madId
78+ ) ;
79+
80+ /**
81+ * DEPRECATED: Do not use.
82+ *
6883 * Holds if in a call to the function with canonical path `path`, defined in the
6984 * crate `crate`, the value referred to by `input` is a flow sink of the given
7085 * `kind`.
@@ -75,52 +90,95 @@ extensible predicate sourceModel(
7590 *
7691 * - `sql-injection`: a flow sink for SQL injection.
7792 */
78- extensible predicate sinkModel (
93+ extensible predicate sinkModelDeprecated (
7994 string crate , string path , string input , string kind , string provenance ,
8095 QlBuiltins:: ExtensionId madId
8196) ;
8297
8398/**
99+ * Holds if in a call to the function with canonical path `path`, the value referred
100+ * to by `input` is a flow sink of the given `kind`.
101+ *
102+ * For example, `input = Argument[0]` means the first argument of the call.
103+ *
104+ * The following kinds are supported:
105+ *
106+ * - `sql-injection`: a flow sink for SQL injection.
107+ */
108+ extensible predicate sinkModel (
109+ string path , string input , string kind , string provenance , QlBuiltins:: ExtensionId madId
110+ ) ;
111+
112+ /**
113+ * DEPRECATED: Do not use.
114+ *
84115 * Holds if in a call to the function with canonical path `path`, defined in the
85116 * crate `crate`, the value referred to by `input` can flow to the value referred
86117 * to by `output`.
87118 *
88119 * `kind` should be either `value` or `taint`, for value-preserving or taint-preserving
89120 * steps, respectively.
90121 */
91- extensible predicate summaryModel (
122+ extensible predicate summaryModelDeprecated (
92123 string crate , string path , string input , string output , string kind , string provenance ,
93124 QlBuiltins:: ExtensionId madId
94125) ;
95126
127+ /**
128+ * Holds if in a call to the function with canonical path `path`, the value referred
129+ * to by `input` can flow to the value referred to by `output`.
130+ *
131+ * `kind` should be either `value` or `taint`, for value-preserving or taint-preserving
132+ * steps, respectively.
133+ */
134+ extensible predicate summaryModel (
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 *
99142 * This predicate should only be used in tests.
100143 */
101144predicate interpretModelForTest ( QlBuiltins:: ExtensionId madId , string model ) {
102145 exists ( string crate , string path , string output , string kind |
103- sourceModel ( crate , path , kind , output , _, madId ) and
146+ sourceModelDeprecated ( crate , path , output , kind , _, madId ) and
104147 model = "Source: " + crate + "; " + path + "; " + output + "; " + kind
105148 )
106149 or
150+ exists ( string path , string output , string kind |
151+ sourceModel ( path , output , kind , _, madId ) and
152+ model = "Source: " + path + "; " + output + "; " + kind
153+ )
154+ or
107155 exists ( string crate , string path , string input , string kind |
108- sinkModel ( crate , path , kind , input , _, madId ) and
156+ sinkModelDeprecated ( crate , path , input , kind , _, madId ) and
109157 model = "Sink: " + crate + "; " + path + "; " + input + "; " + kind
110158 )
111159 or
160+ exists ( string path , string input , string kind |
161+ sinkModel ( path , input , kind , _, madId ) and
162+ model = "Sink: " + path + "; " + input + "; " + kind
163+ )
164+ or
112165 exists ( string type , string path , string input , string output , string kind |
113- summaryModel ( type , path , input , output , kind , _, madId ) and
166+ summaryModelDeprecated ( 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+ summaryModel ( path , input , output , kind , _, madId ) and
172+ model = "Summary: " + path + "; " + input + "; " + output + "; " + kind
173+ )
116174}
117175
118- private class SummarizedCallableFromModel extends SummarizedCallable:: Range {
176+ private class SummarizedCallableFromModelDeprecated extends SummarizedCallable:: Range {
119177 private string crate ;
120178 private string path ;
121179
122- SummarizedCallableFromModel ( ) {
123- summaryModel ( crate , path , _, _, _, _, _) and
180+ SummarizedCallableFromModelDeprecated ( ) {
181+ summaryModelDeprecated ( crate , path , _, _, _, _, _) and
124182 exists ( CallExprBase call , Resolvable r |
125183 call .getStaticTarget ( ) = this and
126184 r = CallExprBaseImpl:: getCallResolvable ( call ) and
@@ -133,7 +191,7 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range {
133191 string input , string output , boolean preservesValue , string model
134192 ) {
135193 exists ( string kind , QlBuiltins:: ExtensionId madId |
136- summaryModel ( crate , path , input , output , kind , _, madId ) and
194+ summaryModelDeprecated ( crate , path , input , output , kind , _, madId ) and
137195 model = "MaD:" + madId .toString ( )
138196 |
139197 kind = "value" and
@@ -145,35 +203,91 @@ private class SummarizedCallableFromModel extends SummarizedCallable::Range {
145203 }
146204}
147205
148- private class FlowSourceFromModel extends FlowSource:: Range {
206+ private class SummarizedCallableFromModel extends SummarizedCallable:: Range {
207+ private string path ;
208+
209+ SummarizedCallableFromModel ( ) {
210+ summaryModel ( 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+ summaryModel ( 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+
230+ private class FlowSourceFromModelDeprecated extends FlowSource:: Range {
149231 private string crate ;
150232 private string path ;
151233
152- FlowSourceFromModel ( ) {
153- sourceModel ( crate , path , _, _, _, _) and
234+ FlowSourceFromModelDeprecated ( ) {
235+ sourceModelDeprecated ( crate , path , _, _, _, _) and
154236 this .callResolvesTo ( crate , path )
155237 }
156238
157239 override predicate isSource ( string output , string kind , Provenance provenance , string model ) {
158240 exists ( QlBuiltins:: ExtensionId madId |
159- sourceModel ( crate , path , output , kind , provenance , madId ) and
241+ sourceModelDeprecated ( crate , path , output , kind , provenance , madId ) and
160242 model = "MaD:" + madId .toString ( )
161243 )
162244 }
163245}
164246
165- private class FlowSinkFromModel extends FlowSink:: Range {
247+ private class FlowSourceFromModel extends FlowSource:: Range {
248+ private string path ;
249+
250+ FlowSourceFromModel ( ) {
251+ sourceModel ( 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+ sourceModel ( path , output , kind , provenance , madId ) and
258+ model = "MaD:" + madId .toString ( )
259+ )
260+ }
261+ }
262+
263+ private class FlowSinkFromModelDeprecated extends FlowSink:: Range {
166264 private string crate ;
167265 private string path ;
168266
169- FlowSinkFromModel ( ) {
170- sinkModel ( crate , path , _, _, _, _) and
267+ FlowSinkFromModelDeprecated ( ) {
268+ sinkModelDeprecated ( crate , path , _, _, _, _) and
171269 this .callResolvesTo ( crate , path )
172270 }
173271
174272 override predicate isSink ( string input , string kind , Provenance provenance , string model ) {
175273 exists ( QlBuiltins:: ExtensionId madId |
176- sinkModel ( crate , path , input , kind , provenance , madId ) and
274+ sinkModelDeprecated ( crate , path , input , kind , provenance , madId ) and
275+ model = "MaD:" + madId .toString ( )
276+ )
277+ }
278+ }
279+
280+ private class FlowSinkFromModel extends FlowSink:: Range {
281+ private string path ;
282+
283+ FlowSinkFromModel ( ) {
284+ sinkModel ( 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+ sinkModel ( path , input , kind , provenance , madId ) and
177291 model = "MaD:" + madId .toString ( )
178292 )
179293 }
0 commit comments