You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/codeql/codeql-language-guides/analyzing-data-flow-in-javascript-and-typescript.rst
+62-75
Original file line number
Diff line number
Diff line change
@@ -204,58 +204,45 @@ data flow solver that can check whether there is (global) data flow from a sourc
204
204
Optionally, configurations may specify extra data flow edges to be added to the data flow graph, and may also specify `barriers`. Barriers are data flow nodes or edges through
205
205
which data should not be tracked for the purposes of this analysis.
206
206
207
-
To define a configuration, extend the class ``DataFlow::Configuration`` as follows:
207
+
To define a configuration, add a module that implements the signature ``DataFlow::ConfigSig`` and pass it to ``DataFlow::Global`` as follows:
208
208
209
209
.. code-block:: ql
210
210
211
-
class MyDataFlowConfiguration extends DataFlow::Configuration {
212
-
MyDataFlowConfiguration() { this = "MyDataFlowConfiguration" }
The characteristic predicate ``MyDataFlowConfiguration()`` defines the name of the configuration, so ``"MyDataFlowConfiguration"`` should be replaced by a suitable
225
-
name describing your particular analysis configuration.
The data flow analysis is performed using the predicate ``hasFlow(source, sink)``:
223
+
The data flow analysis is performed using the predicate ``MyAnalysisFlow::flow(source, sink)``:
228
224
229
225
.. code-block:: ql
230
226
231
-
from MyDataFlowConfiguration dataflow, DataFlow::Node source, DataFlow::Node sink
232
-
where dataflow.hasFlow(source, sink)
227
+
from DataFlow::Node source, DataFlow::Node sink
228
+
where MyAnalysisFlow::flow(source, sink)
233
229
select source, "Data flow from $@ to $@.", source, source.toString(), sink, sink.toString()
234
230
235
231
Using global taint tracking
236
232
~~~~~~~~~~~~~~~~~~~~~~~~~~~
237
233
238
-
Global taint tracking extends global data flow with additional non-value-preserving steps, such as flow through string-manipulating operations. To use it, simply extend
239
-
``TaintTracking::Configuration`` instead of ``DataFlow::Configuration``:
234
+
Global taint tracking extends global data flow with additional non-value-preserving steps, such as flow through string-manipulating operations. To use it, simply
235
+
use ``TaintTracking::Global<...>`` instead of ``DataFlow::Global<...>``:
240
236
241
237
.. code-block:: ql
242
238
243
-
class MyTaintTrackingConfiguration extends TaintTracking::Configuration {
244
-
MyTaintTrackingConfiguration() { this = "MyTaintTrackingConfiguration" }
Analogous to ``isAdditionalFlowStep``, there is a predicate ``isAdditionalTaintStep`` that you can override to specify custom flow steps to consider in the analysis.
252
-
Instead of the ``isBarrier`` and ``isBarrierEdge`` predicates, the taint tracking configuration includes ``isSanitizer`` and ``isSanitizerEdge`` predicates that specify
253
-
data flow nodes or edges that act as taint sanitizers and hence stop flow from a source to a sink.
Similar to global data flow, the characteristic predicate ``MyTaintTrackingConfiguration()`` defines the unique name of the configuration, so ``"MyTaintTrackingConfiguration"``
256
-
should be replaced by an appropriate descriptive name.
257
-
258
-
The taint tracking analysis is again performed using the predicate ``hasFlow(source, sink)``.
245
+
The taint tracking analysis is again performed using the predicate ``MyAnalysisFlow::flow(source, sink)``.
259
246
260
247
Examples
261
248
~~~~~~~~
@@ -267,20 +254,20 @@ time using global taint tracking.
267
254
268
255
import javascript
269
256
270
-
class CommandLineFileNameConfiguration extends TaintTracking::Configuration {
271
-
CommandLineFileNameConfiguration() { this = "CommandLineFileNameConfiguration" }
This query will now find flows that involve inter-procedural steps, like in the following example (where the individual steps have been marked with comments
@@ -325,15 +312,15 @@ with an error if it does not. We could then use that function in ``readFileHelpe
325
312
}
326
313
327
314
For the purposes of our above analysis, ``checkPath`` is a `sanitizer`: its output is always untainted, even if its input is tainted. To model this
328
-
we can add an override of ``isSanitizer`` to our taint-tracking configuration like this:
315
+
we can add an ``isBarrier`` predicate to our taint-tracking configuration like this:
329
316
330
317
.. code-block:: ql
331
318
332
-
class CommandLineFileNameConfiguration extends TaintTracking::Configuration {
- :doc:`Basic query for JavaScript and TypeScript code <basic-query-for-javascript-code>`: Learn to write and run a simple CodeQL query.
23
24
@@ -37,4 +38,6 @@ Experiment and learn how to write effective and efficient queries for CodeQL dat
37
38
38
39
- :doc:`Data flow cheat sheet for JavaScript <data-flow-cheat-sheet-for-javascript>`: This article describes parts of the JavaScript libraries commonly used for variant analysis and in data flow queries.
39
40
40
-
- :doc:`Customizing library models for JavaScript <customizing-library-models-for-javascript>`: You can model frameworks and libraries that your codebase depends on using data extensions and publish them as CodeQL model packs.
41
+
- :doc:`Customizing library models for JavaScript <customizing-library-models-for-javascript>`: You can model frameworks and libraries that your codebase depends on using data extensions and publish them as CodeQL model packs.
42
+
43
+
- :doc:`Migrating JavaScript dataflow queries <migrating-javascript-dataflow-queries>`: Guide on migrating data flow queries to the new data flow library.
0 commit comments