Skip to content

Commit 13ee597

Browse files
committed
JS: Add some proper documentation to SummarizedCallable
1 parent 988fa9c commit 13ee597

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

javascript/ql/lib/semmle/javascript/dataflow/FlowSummary.qll

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,49 @@ private import semmle.javascript.dataflow.internal.FlowSummaryPrivate
66
private import semmle.javascript.dataflow.internal.sharedlib.DataFlowImplCommon as DataFlowImplCommon
77
private import semmle.javascript.dataflow.internal.DataFlowPrivate
88

9-
/** A callable with a flow summary, identified by a unique string. */
9+
/**
10+
* A model for a function that can propagate data flow.
11+
*
12+
* This class makes it possible to model flow through functions, using the same mechanism as
13+
* `summaryModel` as described in the [library customization docs](https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript).
14+
*
15+
* Extend this class to define summary models directly in CodeQL.
16+
* Data extensions and `summaryModel` are usually preferred; but there are a few cases where direct use of this class may be needed:
17+
*
18+
* - The relevant call sites cannot be matched by the access path syntax, and require the full power of CodeQL.
19+
* For example, complex overloading patterns might require more local reasoning at the call site.
20+
* - The input/output behaviour cannot be described statically in the access path syntax, but the relevant access paths
21+
* can be generated dynamically in CodeQL, based on the usages found in the codebase.
22+
*
23+
* Subclasses should bind `this` to a unique identifier for the function being modelled. There is no special
24+
* interpreation of the `this` value, it should just not clash with the `this`-value used by other classes.
25+
*
26+
* For example, this models flow through calls such as `require("my-library").myFunction()`:
27+
* ```codeql
28+
* class MyFunction extends SummarizedCallable {
29+
* MyFunction() { this = "MyFunction" }
30+
*
31+
* override predicate propagatesFlow(string input, string output, boolean preservesValues) {
32+
* input = "Argument[0]" and
33+
* output = "ReturnValue" and
34+
* preservesValue = false
35+
* }
36+
*
37+
* override DataFlow::InvokeNode getACall() {
38+
* result = API::moduleImport("my-library").getMember("myFunction").getACall()
39+
* }
40+
* }
41+
* ```
42+
* This would be equivalent to the following model written as a data extension:
43+
* ```yaml
44+
* extensions:
45+
* - addsTo:
46+
* pack: codeql/javascript-all
47+
* extensible: summaryModel
48+
* data:
49+
* - ["my-library", "Member[myFunction]", "Argument[0]", "ReturnValue", "taint"]
50+
* ```
51+
*/
1052
abstract class SummarizedCallable extends LibraryCallable, Impl::Public::SummarizedCallable {
1153
bindingset[this]
1254
SummarizedCallable() { any() }
@@ -15,6 +57,9 @@ abstract class SummarizedCallable extends LibraryCallable, Impl::Public::Summari
1557
* Holds if data may flow from `input` to `output` through this callable.
1658
*
1759
* `preservesValue` indicates whether this is a value-preserving step or a taint-step.
60+
*
61+
* See the [library customization docs](https://codeql.github.com/docs/codeql-language-guides/customizing-library-models-for-javascript) for
62+
* the syntax of the `input` and `output` parameters.
1863
*/
1964
pragma[nomagic]
2065
predicate propagatesFlow(string input, string output, boolean preservesValue) { none() }

0 commit comments

Comments
 (0)