Skip to content

Commit 387147e

Browse files
author
james
committed
docs: fix include in data flow slides
1 parent b89f016 commit 387147e

File tree

2 files changed

+9
-116
lines changed

2 files changed

+9
-116
lines changed

docs/language/ql-training-rst/java/apache-struts-java.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ RCE in Apache Struts
4747

4848
- Vulnerable code looked like this (`original <https://lgtm.com/projects/g/apache/struts/snapshot/b434c23f95e0f9d5bde789bfa07f8fc1d5a8951d/files/plugins/rest/src/main/java/org/apache/struts2/rest/handler/XStreamHandler.java?sort=name&dir=ASC&mode=heatmap#L45>`__):
4949

50-
.. code-block:: java
51-
52-
public void toObject(Reader in, Object target) {
53-
XStream xstream = createXStream();
54-
xstream.fromXML(in, target);
55-
}
50+
.. code-block:: java
51+
52+
public void toObject(Reader in, Object target) {
53+
XStream xstream = createXStream();
54+
xstream.fromXML(in, target);
55+
}
5656
5757
- Xstream allows deserialization of **dynamic proxies**, which permit remote code execution.
5858

docs/language/ql-training-rst/java/data-flow-java.rst

Lines changed: 3 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -98,118 +98,11 @@ We want to improve our query to catch more of these cases.
9898
9999
Here the concatenation occurs before the call, so the existing query would miss this - the string concatenation does not occur *directly* as the first argument of the call.
100100

101-
Data flow analysis
102-
==================
101+
.. include general data flow slides
103102
104-
- Models flow of data through the program.
105-
- Implemented in the module ``semmle.code.java.dataflow.DataFlow``.
106-
- Class ``DataFlow::Node`` represents program elements that have a value, such as expressions and function parameters.
103+
.. include:: ../slide-snippets/local-data-flow.rst
107104

108-
- Nodes of the data flow graph.
109-
110-
- Various predicated represent flow between these nodes.
111-
112-
- Edges of the data flow graph.
113-
114-
.. note::
115-
116-
The solution here is to use *data flow*. Data flow is, as the name suggests, about tracking the flow of data through the program. It helps answers questions like: *does this expression ever hold a value that originates from a particular other place in the program*?
117-
118-
We can visualize the data flow problem as one of finding paths through a directed graph, where the nodes of the graph are elements in program, and the edges represent the flow of data between those elements. If a path exists, then the data flows between those two edges.
119-
120-
Local vs global data flow
121-
=========================
122-
123-
- Local (“intra-procedural”) data flow models flow within one function; feasible to compute for all functions in a snapshot
124-
- Global (“inter-procedural”) data flow models flow across function calls; not feasible to compute for all functions in a snapshot
125-
- Different APIs, so discussed separately
126-
- This slide deck focuses on the former.
127-
128-
.. note::
129-
130-
For further information, see:
131-
132-
- `Introduction to data flow analysis in QL <https://help.semmle.com/QL/learn-ql/ql/intro-to-data-flow.html>`__
133-
- `Analyzing data flow in Java <https://help.semmle.com/QL/learn-ql/ql/java/dataflow.html>`__
134-
135-
.. rst-class:: background2
136-
137-
Local data flow
138-
===============
139-
140-
Importing data flow
141-
===================
142-
143-
To use the data flow library, add the following import:
144-
145-
.. code-block:: ql
146-
147-
import semmle.code.java.dataflow.DataFlow
148-
149-
**Note**: this library contains an explicit “module” declaration:
150-
151-
.. code-block:: ql
152-
153-
module DataFlow {
154-
class Node extends ... { ... }
155-
predicate localFlow(Node source, Node sink) {
156-
localFlowStep*(source, sink)
157-
}
158-
...
159-
}
160-
161-
So all references will need to be qualified (that is, ``DataFlow::Node``)
162-
163-
.. note::
164-
165-
A **query library** is file with the extension ``.qll``. Query libraries do not contain a query clause, but may contain modules, classes, and predicates. For example, the `Java data flow library <https://help.semmle.com/qldoc/java/semmle/code/java/dataflow/DataFlow.qll/module.DataFlow.html>`__ is contained in the ``semmle/code/java/dataflow/DataFlow.qll`` QLL file, and can be imported as shown above.
166-
167-
A **module** is a way of organizing QL code by grouping together related predicates, classes, and (sub-)modules. They can be either explicitly declared or implicit. A query library implicitly declares a module with the same name as the QLL file.
168-
169-
For further information on libraries and modules in QL, see the chapter on `Modules <https://help.semmle.com/QL/ql-handbook/modules.html>`__ in the QL language handbook.
170-
171-
For further information on importing QL libraries and modules, see the chapter on `Name resolution <https://help.semmle.com/QL/ql-handbook/name-resolution.html>`__ in the QL language handbook.
172-
173-
Data flow graph
174-
===============
175-
176-
- Class ``DataFlow::Node`` represents data flow graph nodes
177-
- Predicate ``DataFlow::localFlowStep`` represents local data flow graph edges, ``DataFlow::localFlow`` is its transitive closure
178-
- Data flow graph nodes are *not* AST nodes, but they correspond to AST nodes, and there are predicates for mapping between them:
179-
180-
- ``Expr Node.asExpr()``
181-
- ``Parameter Node.asParameter()``
182-
- ``DataFlow::Node DataFlow::exprNode(Expr e)``
183-
- ``DataFlow::Node DataFlow::parameterNode(Parameter p)``
184-
- ``etc.``
185-
186-
.. note::
187-
188-
The ``DataFlow::Node`` class is shared between both the local and global data flow graphs–the primary difference is the edges, which in the “global” case can link different functions.
189-
190-
``localFlowStep`` is the “single step” flow relation–that is, it describes single edges in the local data flow graph. ``localFlow`` represents the `transitive <https://help.semmle.com/QL/ql-handbook/recursion.html#transitive-closures>`__ closure of this relation–in other words, it contains every pair of nodes where the second node is reachable from the first in the data flow graph.
191-
192-
The data flow graph is separate from the `AST <https://en.wikipedia.org/wiki/Abstract_syntax_tree>`__, to allow for flexibility in how data flow is modeled. There are a small number of data flow node types–expression nodes, parameter nodes, uninitialized variable nodes, and definition by reference nodes. Each node provides mapping functions to and from the relevant AST (for example ``Expr``, ``Parameter`` etc.) or symbol table (for example ``Variable``) classes.
193-
194-
Taint tracking
195-
==============
196-
197-
- Usually, we want to generalise slightly by not only considering plain data flow, but also “taint” propagation, that is, whether a value is influenced by or derived from another.
198-
199-
- Examples:
200-
201-
.. code-block:: java
202-
203-
sink = source; // source -> sink: data and taint
204-
strcat(sink, source); // source -> sink: taint, not data
205-
206-
- Library ``semmle.code.java.dataflow.TaintTracking`` provides predicates for tracking taint; ``TaintTracking::localTaintStep`` represents one (local) taint step, ``TaintTracking::localTaint`` is its transitive closure.
207-
208-
.. note::
209-
210-
Taint tracking can be thought of as another type of data flow graph. It usually extends the standard data flow graph for a problem by adding edges between nodes where one one node influences or *taints* another.
211-
212-
The `API <https://help.semmle.com/qldoc/java/semmle/code/java/dataflow/TaintTracking.qll/module.TaintTracking.html>`__ is almost identical to that of the local data flow. All we need to do to switch to taint tracking is ``import semmle.code.java.dataflow.TaintTracking`` instead of ``semmle.code.java.dataflow.DataFlow``, and instead of using ``localFlow``, we use ``localTaint``.
105+
.. resume language-specific slides
213106
214107
Exercise: revisiting SPARQL injection
215108
=====================================

0 commit comments

Comments
 (0)