Skip to content

Commit 0785c1b

Browse files
committed
JS: Address comments
1 parent 17573af commit 0785c1b

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

docs/language/learn-ql/javascript/type-tracking.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ all of these steps are included in a single predicate,
121121
to be used with the companion class
122122
`TypeTracker <https://help.semmle.com/qldoc/javascript/semmle/javascript/dataflow/TypeTracking.qll/type.TypeTracking$TypeTracker.html>`__.
123123

124-
Predicates that use type tracking usually conform to the following general pattern (explanation follows below):
124+
Predicates that use type tracking usually conform to the following general pattern, which we explain below:
125125

126126
.. code-block:: ql
127127
@@ -175,7 +175,7 @@ this is the starting point of type tracking:
175175
t.start() and
176176
result = firebase().getAMethodCall("database")
177177
178-
In the recursive case, we apply the ``track`` predicate on a previously-found firebase database node, such as ``firebase.database()``.
178+
In the recursive case, we apply the ``track`` predicate on a previously-found Firebase database node, such as ``firebase.database()``.
179179
The ``track`` predicate maps this to a successor of that node, such as ``getDatabase()``, and
180180
binds ``t`` to the continuation of ``t2`` with this extra step included:
181181

@@ -186,8 +186,8 @@ binds ``t`` to the continuation of ``t2`` with this extra step included:
186186
)
187187
188188
To understand the role of ``t`` here, note that type tracking can step *into* a property, which means
189-
the data flow node returned from ``track`` is not necessarily a firebase database instance, it could be
190-
an object *containing* a firebase database in one of its properties.
189+
the data flow node returned from ``track`` is not necessarily a Firebase database instance, it could be
190+
an object *containing* a Firebase database in one of its properties.
191191

192192
For example, in the program below, the ``firebaseDatabase(t)`` predicate includes the ``obj`` node in its result,
193193
but with ``t`` recording the fact that the actual value being tracked is inside the ``DB`` property:
@@ -198,7 +198,7 @@ but with ``t`` recording the fact that the actual value being tracked is inside
198198
let db = obj.DB;
199199
200200
This brings us to the last predicate. This uses ``TypeTracker::end()`` to filter out
201-
the paths where the firebase database instance ended up inside a property of another object,
201+
the paths where the Firebase database instance ended up inside a property of another object,
202202
so it includes ``db`` but not ``obj``:
203203

204204
.. code-block:: ql
@@ -275,12 +275,12 @@ For reference, here's our simple Firebase model with type tracking on every pred
275275
}
276276
277277
`Here <https://lgtm.com/query/1053770500827789481>`__ is a run of an example query using the model to find `set` calls on one of the Firebase sample projects.
278-
It's been modified slightly to handle a bit more of the API, which is out of scope of this tutorial.
278+
It's been modified slightly to handle a bit more of the API, which is beyond the scope of this tutorial.
279279

280280
Tracking associated data
281281
------------------------
282282

283-
By adding extra parameters to the type-tracking predicate we can carry along
283+
By adding extra parameters to the type-tracking predicate, we can carry along
284284
extra bits of information about the result.
285285

286286
For example, here's a type-tracking version of ``firebaseRef()``, which
@@ -339,12 +339,12 @@ Reading is an asynchronous operation and the result is obtained through a callba
339339
The actual forecast is obtained by the call to ``snapshot.val()``.
340340

341341
Looking for all method calls named ``val`` will in practice find many unrelated methods,
342-
so we'll use type tracking again in order to take the receiver type into account.
342+
so we'll use type tracking again to take the receiver type into account.
343343

344344
The receiver ``snapshot`` is a parameter to a callback function, which ultimately escapes
345345
into the ``once()`` call. We'll extend our model from above to use back-tracking to find
346-
all functions that flow into the ``once()`` call. Type tracking backwards is not much
347-
different from forwards; the differences are:
346+
all functions that flow into the ``once()`` call.
347+
Backwards type tracking is not too different from forwards type tracking. The differences are:
348348

349349
- The ``TypeTracker`` parameter instead has type ``TypeBackTracker``.
350350
- The call to ``.track()`` is instead a call to ``.backtrack()``
@@ -387,14 +387,14 @@ Based on that we can track the ``snapshot`` value and find the ``val()`` call it
387387
result = firebaseSnapshot(refName).getAMethodCall("val")
388388
}
389389
390-
With this addition, ``firebaseDatabaseRead("forecast")`` finds the call to ``snapshot.val()`` which contains the value of the forecast.
390+
With this addition, ``firebaseDatabaseRead("forecast")`` finds the call to ``snapshot.val()`` that contains the value of the forecast.
391391

392392
`Here <https://lgtm.com/query/8761360814276109092>`__ is a run of an example query using the model to find `val` calls.
393393

394394
Summary
395395
-------
396396

397-
This covers the use of the type-tracking library. To recap, use this template to define forward type-tracking predicates:
397+
We have covered how to use the type-tracking library. To recap, use this template to define forward type-tracking predicates:
398398

399399
.. code-block:: ql
400400
@@ -443,7 +443,7 @@ Limitations
443443
As mentioned, type tracking will track values in and out of function calls and properties,
444444
but only within some limits.
445445

446-
For example, type tracking does not always track *through* functions, that is, if a value flows into a parameter
446+
For example, type tracking does not always track *through* functions. That is, if a value flows into a parameter
447447
and back out of the return value, it might not be tracked back out to the call site again.
448448
Here's an example that the model from this tutorial won't find:
449449

@@ -455,12 +455,12 @@ Here's an example that the model from this tutorial won't find:
455455
let wrapper = wrapDB(firebase.database())
456456
wrapper.db.ref("forecast"); // <-- not found
457457
458-
This is an example of where `data flow configurations <https://help.semmle.com/QL/learn-ql/javascript/dataflow.html#global-data-flow>`__ are more powerful.
458+
This is an example of where `data-flow configurations <https://help.semmle.com/QL/learn-ql/javascript/dataflow.html#global-data-flow>`__ are more powerful.
459459

460460
When to use type tracking
461461
-------------------------
462462

463-
Type tracking and data flow configurations are different solutions to the same
463+
Type tracking and data-flow configurations are different solutions to the same
464464
problem, each with their own tradeoffs.
465465

466466
Type tracking can be used in any number of predicates, which may depend on each other
@@ -470,23 +470,23 @@ Type-tracking predicates can have any number of extra parameters, making it poss
470470
to construct source/sink pairs. Omitting source/sink pairs can be useful when there is a huge number
471471
of sources and sinks.
472472

473-
Data flow configurations have more restricted dependencies but are more powerful in other ways.
473+
Data-flow configurations have more restricted dependencies but are more powerful in other ways.
474474
For performance reasons,
475475
the sources, sinks, and steps of a configuration should not depend on whether a flow path has been found using
476476
that configuration or any other configuration.
477477
In that sense, the sources, sinks, and steps must be configured "up front" and can't be discovered on-the-fly.
478478
The upside is that they track flow through functions and callbacks in some ways that type tracking doesn't,
479479
which is particularly important for security queries.
480-
Also, path queries can only be defined using data flow configurations.
480+
Also, path queries can only be defined using data-flow configurations.
481481

482482
Prefer type tracking when:
483483

484484
- Disambiguating generically named methods or properties.
485485
- Making reusable library components to be shared between queries.
486486
- The set of source/sink pairs is too large to compute or has insufficient information.
487-
- The information is needed as input to a data flow configuration.
487+
- The information is needed as input to a data-flow configuration.
488488

489-
Prefer data flow configurations when:
489+
Prefer data-flow configurations when:
490490

491491
- Tracking user-controlled data -- use `taint tracking <https://help.semmle.com/QL/learn-ql/javascript/dataflow.html#using-global-taint-tracking>`__.
492492
- Differentiating between different kinds of user-controlled data -- use :doc:`flow labels <flow-labels>`.

0 commit comments

Comments
 (0)