@@ -220,6 +220,59 @@ For example, the **mysql** model that is included with the CodeQL JS analysis in
220220
221221 - ["mysql.Connection", "mysql", "Member[createConnection].ReturnValue"]
222222
223+ Example: Using fuzzy models to simplify modeling
224+ ------------------------------------------------
225+
226+ In this example, we'll show how to add the following SQL injection sink using a "fuzzy" model:
227+
228+ .. code-block :: ts
229+
230+ import * as mysql from 'mysql';
231+ const pool = mysql.createPool({...});
232+ pool.getConnection((err, conn) => {
233+ conn.query(q, (err, rows) => {...}); // <-- add 'q' as a SQL injection sink
234+ });
235+
236+ We can recognize this using a fuzzy model, as showin in the following extension:
237+
238+ .. code-block :: yaml
239+
240+ extensions :
241+ - addsTo :
242+ pack : codeql/javascript-all
243+ extensible : sinkModel
244+ data :
245+ - ["mysql", "Fuzzy.Member[query].Argument[0]", "sql-injection"]
246+
247+ - The first column, **"mysql" **, begins the search at at places where the `mysql ` package is imported.
248+ - **Fuzzy ** selects all objects that appear to originate from the `mysql ` package, such as the `pool `, `conn `, `err `, and `rows ` objects.
249+ - **Member[query] ** selects the **query ** member from any of those objects. In this case, the only such member is `conn.query `.
250+ In principle, this would also find expressions such as `pool.query ` and `err.query `, but in practice such expressions
251+ are not likely to occur, because the `pool ` and `err ` objects do not have a member named `query `.
252+ - **Argument[0] ** selects the first argument of a call to the selected member, that is, the `q ` argument to `conn.query `.
253+ - **sql-injection ** indicates that this is considered a sink for the SQL injection query.
254+
255+ For reference, a more detailed model might look like this, as described in the preceding examples:
256+
257+ .. code-block :: yaml
258+
259+ extensions :
260+ - addsTo :
261+ pack : codeql/javascript-all
262+ extensible : sinkModel
263+ data :
264+ - ["mysql.Connection", "Member[query].Argument[0]", "sql-injection"]
265+
266+ - addsTo :
267+ pack : codeql/javascript-all
268+ extensible : typeModel
269+ data :
270+ - ["mysql.Pool", "mysql", "Member[createPool].ReturnValue"]
271+ - ["mysql.Connection", "mysql.Pool", "Member[getConnection].Argument[0].Parameter[1]"]
272+
273+ The model using the **Fuzzy ** component is simpler, at the cost of being approximate.
274+ This technique is useful when modeling a large or complex library, where it is difficult to write a detailed model.
275+
223276Example: Adding flow through 'decodeURIComponent'
224277-------------------------------------------------
225278
@@ -431,6 +484,9 @@ The following components are supported:
431484- **MapValue ** selects a value of a map object.
432485- **Awaited ** selects the value of a promise.
433486- **Instance ** selects instances of a class.
487+ - **Fuzzy ** selects all values that are derived from the current value through a combination of the other operations described in this list.
488+ For example, this can be used to find all values the appear to originate from a particular package. This can be useful for finding method calls
489+ from a known package, but where the receiver type is not known or is difficult to model.
434490
435491The following components are called "call site filters". They select a subset of the previously-selected calls, if the call fits certain criteria:
436492
0 commit comments