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
+57-70
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 {
Copy file name to clipboardExpand all lines: docs/codeql/codeql-language-guides/codeql-library-for-javascript.rst
+17-28
Original file line number
Diff line number
Diff line change
@@ -700,55 +700,44 @@ The data flow graph-based analyses described so far are all intraprocedural: the
700
700
701
701
We distinguish here between data flow proper, and *taint tracking*: the latter not only considers value-preserving flow (such as from variable definitions to uses), but also cases where one value influences ("taints") another without determining it entirely. For example, in the assignment ``s2 = s1.substring(i)``, the value of ``s1`` influences the value of ``s2``, because ``s2`` is assigned a substring of ``s1``. In general, ``s2`` will not be assigned ``s1`` itself, so there is no data flow from ``s1`` to ``s2``, but ``s1`` still taints ``s2``.
702
702
703
-
It is a common pattern that we wish to specify data flow or taint analysis in terms of its *sources* (where flow starts), *sinks* (where it should be tracked), and *barriers* or *sanitizers* (where flow is interrupted). Sanitizers they are very common in security analyses: for example, an analysis that tracks the flow of untrusted user input into, say, a SQL query has to keep track of code that validates the input, thereby making it safe to use. Such a validation step is an example of a sanitizer.
703
+
It is a common pattern that we wish to specify data flow or taint analysis in terms of its *sources* (where flow starts), *sinks* (where it should be tracked), and *barriers* (also called *sanitizers*) where flow is interrupted. Sanitizers they are very common in security analyses: for example, an analysis that tracks the flow of untrusted user input into, say, a SQL query has to keep track of code that validates the input, thereby making it safe to use. Such a validation step is an example of a sanitizer.
704
704
705
-
The classes ``DataFlow::Configuration`` and ``TaintTracking::Configuration`` allow specifying a data flow or taint analysis, respectively, by overriding the following predicates:
705
+
A module implementing the signature `DataFlow::ConfigSig` may specify a data flow or taint analysisby implementing the following predicates:
706
706
707
707
- ``isSource(DataFlow::Node nd)`` selects all nodes ``nd`` from where flow tracking starts.
708
708
- ``isSink(DataFlow::Node nd)`` selects all nodes ``nd`` to which the flow is tracked.
709
-
- ``isBarrier(DataFlow::Node nd)`` selects all nodes ``nd`` that act as a barrier for data flow; ``isSanitizer`` is the corresponding predicate for taint tracking configurations.
710
-
- ``isBarrierEdge(DataFlow::Node src, DataFlow::Node trg)`` is a variant of ``isBarrier(nd)`` that allows specifying barrier *edges* in addition to barrier nodes; again, ``isSanitizerEdge`` is the corresponding predicate for taint tracking;
711
-
- ``isAdditionalFlowStep(DataFlow::Node src, DataFlow::Node trg)`` allows specifying custom additional flow steps for this analysis; ``isAdditionalTaintStep`` is the corresponding predicate for taint tracking configurations.
709
+
- ``isBarrier(DataFlow::Node nd)`` selects all nodes ``nd`` that act as a barrier/sanitizer for data flow.
710
+
- ``isAdditionalFlowStep(DataFlow::Node src, DataFlow::Node trg)`` allows specifying custom additional flow steps for this analysis.
712
711
713
-
Since for technical reasons both ``Configuration`` classes are subtypes of ``string``, you have to choose a unique name for each flow configuration and equate ``this`` with it in the characteristic predicate (as in the example below).
714
-
715
-
The predicate ``Configuration.hasFlow`` performs the actual flow tracking, starting at a source and looking for flow to a sink that does not pass through a barrier node or edge.
712
+
Such a module can be passed to ``DataFlow::Global<...>``. This will produce a module with a ``flow`` predicate that performs the actual flow tracking, starting at a source and looking for flow to a sink that does not pass through a barrier node.
716
713
717
714
For example, suppose that we are developing an analysis to find hard-coded passwords. We might write a simple query that looks for string constants flowing into variables named ``"password"``.
718
715
719
716
.. code-block:: ql
720
717
721
718
import javascript
722
719
723
-
class PasswordTracker extends DataFlow::Configuration {
0 commit comments