Skip to content

Commit 9998752

Browse files
Accept suggested wording improvements
Co-authored-by: Felicity Chapman <[email protected]>
1 parent 1a702bf commit 9998752

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ For a more general introduction to modeling data flow, see ":ref:`About data flo
1515
Local data flow
1616
---------------
1717

18-
Local data flow is data flow within a single method or callable. Local data flow is easier, faster, and more precise than global data flow, and is sufficient for many queries.
18+
Local data flow tracks the flow of data within a single method or callable. Local data flow is easier, faster, and more precise than global data flow. Before looking at more complex tracking, you should always consider local tracking because it is sufficient for many queries.
1919

2020
Using local data flow
2121
~~~~~~~~~~~~~~~~~~~~~
2222

23-
The local data flow library is in the module ``DataFlow`` and it defines the class ``Node``, representing any element through which data can flow.
23+
You can use the local data flow library by importing the ``DataFlow`` module. The library uses the class ``Node`` to represent any element through which data can flow.
2424
``Node``\ s are divided into expression nodes (``ExprNode``) and parameter nodes (``ParameterNode``).
25-
You can map between a data flow ``ParameterNode`` and its corresponding ``Parameter`` AST node using the ``asParameter`` member predicate.
26-
Meanwhile, the ``asExpr`` member predicate maps between a data flow ``ExprNode`` and its corresponding ``ExprCfgNode`` in the control-flow library.
25+
You can map a data flow ``ParameterNode`` to its corresponding ``Parameter`` AST node using the ``asParameter`` member predicate.
26+
Similarly, you can use the ``asExpr`` member predicate to map a data flow ``ExprNode`` to its corresponding ``ExprCfgNode`` in the control-flow library.
2727

2828
.. code-block:: ql
2929
@@ -37,7 +37,7 @@ Meanwhile, the ``asExpr`` member predicate maps between a data flow ``ExprNode``
3737
...
3838
}
3939
40-
You can also use the predicates ``exprNode`` and ``parameterNode``:
40+
You can use the predicates ``exprNode`` and ``parameterNode`` to map from expressions and parameters to their data-flow node:
4141

4242
.. code-block:: ql
4343
@@ -52,8 +52,8 @@ You can also use the predicates ``exprNode`` and ``parameterNode``:
5252
ParameterNode parameterNode(Parameter p) { ... }
5353
5454
Note that since ``asExpr`` and ``exprNode`` map between data-flow and control-flow nodes, you then need to call the ``getExpr`` member predicate on the control-flow node to map to the corresponding AST node,
55-
e.g. by writing ``node.asExpr().getExpr()``.
56-
Due to the control-flow graph being split, there can be multiple data-flow and control-flow nodes associated with a single expression AST node.
55+
for example, by writing ``node.asExpr().getExpr()``.
56+
A control-flow graph considers every way control can flow through code, consequently, there can be multiple data-flow and control-flow nodes associated with a single expression node in the AST.
5757

5858
The predicate ``localFlowStep(Node nodeFrom, Node nodeTo)`` holds if there is an immediate data flow edge from the node ``nodeFrom`` to the node ``nodeTo``.
5959
You can apply the predicate recursively, by using the ``+`` and ``*`` operators, or you can use the predefined recursive predicate ``localFlow``.
@@ -67,7 +67,7 @@ For example, you can find flow from an expression ``source`` to an expression ``
6767
Using local taint tracking
6868
~~~~~~~~~~~~~~~~~~~~~~~~~~
6969

70-
Local taint tracking extends local data flow by including non-value-preserving flow steps.
70+
Local taint tracking extends local data flow to include flow steps where values are not preserved, for example, string manipulation.
7171
For example:
7272

7373
.. code-block:: ruby
@@ -91,17 +91,17 @@ For example, you can find taint propagation from an expression ``source`` to an
9191
Using local sources
9292
~~~~~~~~~~~~~~~~~~~
9393

94-
When asking for local data flow or taint propagation between two expressions as above, you would normally constrain the expressions to be relevant to a certain investigation.
95-
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.
94+
When exploring local data flow or taint propagation between two expressions as above, you would normally constrain the expressions to be relevant to your investigation.
95+
The next section gives some concrete examples, but first it's helpful to introduce the concept of a local source.
9696

9797
A local source is a data-flow node with no local data flow into it.
9898
As such, it is a local origin of data flow, a place where a new value is created.
99-
This includes parameters (which only receive global data flow) and most expressions (because they are not value-preserving).
99+
This includes parameters (which only receive values from global data flow) and most expressions (because they are not value-preserving).
100100
The class ``LocalSourceNode`` represents data-flow nodes that are also local sources.
101101
It comes with a useful member predicate ``flowsTo(DataFlow::Node node)``, which holds if there is local data flow from the local source to ``node``.
102102

103-
Examples
104-
~~~~~~~~
103+
Examples of local data flow
104+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
105105

106106
This query finds the filename argument passed in each call to ``File.open``:
107107

@@ -134,8 +134,8 @@ So we use local data flow to find all expressions that flow into the argument:
134134
Many expressions flow to the same call.
135135
If you run this query, you may notice that you get several data-flow nodes for an expression as it flows towards a call (notice repeated locations in the ``call`` column).
136136
We are mostly interested in the "first" of these, what might be called the local source for the file name.
137-
To restrict attention to such local sources, and to simultaneously make the analysis more performant, we have the QL class ``LocalSourceNode``.
138-
We could demand that ``expr`` is such a node:
137+
To restrict the results to local sources for the file name, and to simultaneously make the analysis more efficient, we can use the CodeQL class ``LocalSourceNode``.
138+
We can update the query to specify that ``expr`` is an instance of a ``LocalSourceNode``.
139139

140140
.. code-block:: ql
141141
@@ -149,7 +149,7 @@ We could demand that ``expr`` is such a node:
149149
expr instanceof DataFlow::LocalSourceNode
150150
select call, expr
151151
152-
However, we could also enforce this by casting.
152+
An alternative approach to limit the results to local sources for the file name is to enforce this by casting.
153153
That would allow us to use the member predicate ``flowsTo`` on ``LocalSourceNode`` like so:
154154

155155
.. code-block:: ql
@@ -181,7 +181,7 @@ We now mostly have one expression per call.
181181

182182
We may still have cases of more than one expression flowing to a call, but then they flow through different code paths (possibly due to control-flow splitting).
183183

184-
We might want to make the source more specific, for example a parameter to a method or block.
184+
We might want to make the source more specific, for example, a parameter to a method or block.
185185
This query finds instances where a parameter is used as the name when opening a file:
186186

187187
.. code-block:: ql
@@ -197,7 +197,7 @@ This query finds instances where a parameter is used as the name when opening a
197197
198198
Using the exact name supplied via the parameter may be too strict.
199199
If we want to know if the parameter influences the file name, we can use taint tracking instead of data flow.
200-
This query finds calls to ``File.open`` where the filename is derived from a parameter:
200+
This query finds calls to ``File.open`` where the file name is derived from a parameter:
201201

202202
.. code-block:: ql
203203
@@ -224,7 +224,7 @@ However, global data flow is less precise than local data flow, and the analysis
224224
Using global data flow
225225
~~~~~~~~~~~~~~~~~~~~~~
226226

227-
The global data flow library is used by extending the class ``DataFlow::Configuration``:
227+
You can use the global data flow library by extending the class ``DataFlow::Configuration``:
228228

229229
.. code-block:: ql
230230
@@ -316,15 +316,15 @@ Class hierarchy
316316
- ``Concepts::SystemCommandExecution`` - a data-flow node that executes an operating system command, for instance by spawning a new process.
317317
- ``Concepts::FileSystemAccess`` - a data-flow node that performs a file system access, including reading and writing data, creating and deleting files and folders, checking and updating permissions, and so on.
318318
- ``Concepts::Path::PathNormalization`` - a data-flow node that performs path normalization. This is often needed in order to safely access paths.
319-
- ``Concepts::CodeExecution`` - a data-flow node that dynamically executes Python code.
319+
- ``Concepts::CodeExecution`` - a data-flow node that dynamically executes Ruby code.
320320
- ``Concepts::SqlExecution`` - a data-flow node that executes SQL statements.
321321
- ``Concepts::HTTP::Server::RouteSetup`` - a data-flow node that sets up a route on a server.
322322
- ``Concepts::HTTP::Server::HttpResponse`` - a data-flow node that creates an HTTP response on a server.
323323

324324
- ``TaintTracking::Configuration`` - base class for custom global taint tracking analysis.
325325

326-
Examples
327-
~~~~~~~~
326+
Examples of global data flow
327+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328328

329329
This query shows a data flow configuration that uses all network input as data sources:
330330

0 commit comments

Comments
 (0)