Skip to content

Commit 0d8f8d2

Browse files
committed
Python, doc: subsection on local sources
also remove references to `parameterNode` which is not available yet.
1 parent 748749c commit 0d8f8d2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

docs/codeql/codeql-language-guides/analyzing-data-flow-in-python.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ Due to the control-flow graph being split, there can be multiple data-flow nodes
4747

4848
The predicate ``localFlowStep(Node nodeFrom, Node nodeTo)`` holds if there is an immediate data flow edge from the node ``nodeFrom`` to the node ``nodeTo``. You can apply the predicate recursively, by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localFlow``.
4949

50-
For example, you can find flow from a parameter ``source`` to an expression ``sink`` in zero or more local steps:
50+
For example, you can find flow from an expression ``source`` to an expression ``sink`` in zero or more local steps:
5151

5252
.. code-block:: ql
5353
54-
DataFlow::localFlow(DataFlow::parameterNode(source), DataFlow::exprNode(sink))
54+
DataFlow::localFlow(DataFlow::exprNode(source), DataFlow::exprNode(sink))
5555
5656
Using local taint tracking
5757
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -67,11 +67,17 @@ If ``x`` is a tainted string then ``y`` is also tainted.
6767

6868
The local taint tracking library is in the module ``TaintTracking``. Like local data flow, a predicate ``localTaintStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo)`` holds if there is an immediate taint propagation edge from the node ``nodeFrom`` to the node ``nodeTo``. You can apply the predicate recursively, by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localTaint``.
6969

70-
For example, you can find taint propagation from a parameter ``source`` to an expression ``sink`` in zero or more local steps:
70+
For example, you can find taint propagation from an expression ``source`` to an expression ``sink`` in zero or more local steps:
7171

7272
.. code-block:: ql
7373
74-
TaintTracking::localTaint(DataFlow::parameterNode(source), DataFlow::exprNode(sink))
74+
TaintTracking::localTaint(DataFlow::exprNode(source), DataFlow::exprNode(sink))
75+
76+
77+
Using local sources
78+
~~~~~~~~~~~~~~~~~~~
79+
80+
When asking for local data-flow or taint propagation between two expressions as above, one would normally constrain the expressions to be relevant to a certain investigation. The next section will give some concrete examples, but there is a more abstract concept that we should call out explicitly, namely that of a local source. A local source is a data-flow node with no local data-flow into it. As such it is a local origin of data flow, a place where a new value is created. This includes parameters (which only receive global data-flow) and most expressions (because they are not value-preserving). Restricting attention to such local sources gives a much lighter and more performant data-flow graph and in most cases also a more suitable abstraction for the investigation of interest. The class ``LocalSourceNode`` is exactly data-flow nodes that are also local sources. It comes with a handy member predicate ``flowsTo(DataFlow::Node node)`` which holds if there is local data-flow from the local source to ``node``.
7581

7682
Examples
7783
~~~~~~~~
@@ -268,6 +274,8 @@ Flow sources
268274

269275
The data flow library contains some predefined flow sources. The class ``RemoteFlowSource`` (defined in module ``semmle.python.dataflow.new.RemoteFlowSources``) represents data flow from remote network inputs. This is useful for finding security problems in networked services.
270276

277+
Also for global flow is it useful to restrict sources to instances of ``LocalSourceNode`` and the predefined sources generally do that.
278+
271279
Example
272280
~~~~~~~
273281

0 commit comments

Comments
 (0)