Skip to content

Commit 395a9f0

Browse files
asgerfsubatoi
andauthored
Apply suggestions from code review
Co-authored-by: Ben Ahmady <[email protected]>
1 parent c4c0009 commit 395a9f0

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

docs/codeql/codeql-language-guides/customizing-library-models-for-javascript.rst

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Customizing Library Models for JavaScript
1010

1111
The JavaScript analysis can be customized by adding library models in data extension files.
1212

13-
A data extension for JavaScript is a YAML file of form:
13+
A data extension for JavaScript is a YAML file of the form:
1414

1515
.. code-block:: yaml
1616
@@ -23,7 +23,7 @@ A data extension for JavaScript is a YAML file of form:
2323
- <tuple2>
2424
- ...
2525
26-
The data extension can contribute to the following extension points:
26+
The CodeQL library for JavaScript exposes the following extensible predicates:
2727

2828
- **sourceModel**\(type, path, kind)
2929
- **sinkModel**\(type, path, kind)
@@ -57,7 +57,6 @@ This can be achieved with the following data extension:
5757
data:
5858
- ["execa", "Member[shell].Argument[0]", "command-line-injection"]
5959
60-
To break this down:
6160
6261
- Since we're adding a new sink, we add a tuple to the **sinkModel** extension point.
6362
- The first column, **"execa"**, identifies a set of values from which to begin the search for the sink.
@@ -95,7 +94,6 @@ This source is already known by the CodeQL JS analysis, but we'll show how it co
9594
"remote",
9695
]
9796
98-
To break this down:
9997
10098
- Since we're adding a new taint source, we add a tuple to the **sourceModel** extension point.
10199
- The first column, **"global"**, begins the search at references to the global object (also known as **window** in browser contexts). This is a special JavaScript object that contains all global variables and methods.
@@ -159,17 +157,16 @@ We can recognize this using the following extension:
159157
data:
160158
- ["mysql.Connection", "Member[query].Argument[0]", "sql-injection"]
161159
162-
To break this down:
163160
164161
- The first column, **"mysql.Connection"**, begins the search at any expression whose value is known to be an instance of
165162
the **Connection** type from the **mysql** package. This will select the **connection** parameter above because of its type annotation.
166163
- **Member[query]** selects the **query** member from the connection object.
167164
- **Argument[0]** selects the first argument of a call to that member.
168165
- **sql-injection** indicates that this is considered a sink for the SQL injection query.
169166

170-
This works for the example above because the **connection** parameter has a type annotation that matches what the model is looking for.
167+
This works in this example because the **connection** parameter has a type annotation that matches what the model is looking for.
171168

172-
In the next section, we'll show how to generalize the model to handle the absense of type annotations.
169+
In the next section, we'll show how to generalize the model to handle the absence of type annotations.
173170

174171
Continued example: Dealing with untyped code
175172
--------------------------------------------
@@ -194,7 +191,6 @@ Using a **typeModel** tuple we can tell our model that this function returns an
194191
data:
195192
- ["mysql.Connection", "@example/db", "Member[getConnection].ReturnValue"]
196193
197-
To break this down:
198194
199195
- Since we're providing type information, we add a tuple to the **typeModel** extension point.
200196
- The first column, **"mysql.Connection"**, names the type that we're adding a new definition for.
@@ -239,9 +235,8 @@ This flow is already recognized by the CodeQL JS analysis, but this is how it co
239235
"taint",
240236
]
241237
242-
To break this down:
243238
244-
- Since we're adding flow *through* a function call, we add a tuple to the **summaryModel** extension point.
239+
- Since we're adding flow through a function call, we add a tuple to the **summaryModel** extension point.
245240
- The first column, **"global"**, begins the search for relevant calls at references to the global object.
246241
In JavaScript, global variables are properties of the global object, so this lets us access global variables or functions.
247242
- The second column, **Member[decodeURIComponent]**, is a path leading to the function calls we wish to model.
@@ -250,7 +245,7 @@ To break this down:
250245
- The third column, **Argument[0]**, indicates the input of the flow. In this case, the first argument to the function call.
251246
- The fourth column, **ReturnValue**, indicates the output of the flow. In this case, the return value of the function call.
252247
- The last column, **taint**, indicates the kind of flow to add. The value **taint** means the output is not necessarily equal
253-
to the input, but was was derived from the input in a taint-preserving way.
248+
to the input, but was derived from the input in a taint-preserving way.
254249

255250
Example: Adding flow through 'underscore.forEach'
256251
-------------------------------------------------
@@ -278,9 +273,8 @@ This flow is already recognized by the CodeQL JS analysis, but we'll show how it
278273
"value",
279274
]
280275
281-
To break this down:
282276
283-
- Since we're adding flow *through* a function call, we add a tuple to the **summaryModel** extension point.
277+
- Since we're adding flow through a function call, we add a tuple to the **summaryModel** extension point.
284278
- The first column, **"underscore"**, begins the search for relevant calls at places where the **underscore** package is imported.
285279
- The second column, **Member[forEach]**, selects references to the **forEach** member from the **underscore** package.
286280
- The third column specifies the input of the flow:
@@ -327,7 +321,7 @@ Example:
327321
sinkModel(type, path, kind)
328322
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
329323

330-
Adds a new taint sink. Sinks are query-specific and will usually affect one or two queries.
324+
Adds a new taint sink. Sinks are query-specific and will typically affect one or two queries.
331325

332326
- **type**: Name of a type from which to evaluate **path**.
333327
- **path**: Access path leading to the sink.
@@ -410,7 +404,7 @@ A type can be defined by adding **typeModel** tuples for that type. Additionally
410404
Access paths
411405
------------
412406

413-
The **path**, **input**, and **output** columns consist of a **.**-separated list of components, which is evaluted from left to right, with each step selecting a new set of values derived from the previous set of values.
407+
The **path**, **input**, and **output** columns consist of a **.**-separated list of components, which is evaluated from left to right, with each step selecting a new set of values derived from the previous set of values.
414408

415409
The following components are supported:
416410

@@ -438,7 +432,7 @@ Components related to decorators:
438432
- **DecoratedParameter** selects a parameter that is decorated by the current value.
439433
- **DecoratedMember** selects a method, field, or accessor that is decorated by the current value.
440434

441-
Some additional notes about the syntax of operands:
435+
Additional notes about the syntax of operands:
442436

443437
- Multiple operands may be given to a single component, as a shorthand for the union of the operands. For example, **Member[foo,bar]** matches the union of **Member[foo]** and **Member[bar]**.
444438
- Numeric operands to **Argument**, **Parameter**, and **WithArity** may be given as an interval. For example, **Argument[0..2]** matches argument 0, 1, or 2.
@@ -455,11 +449,11 @@ Source kinds
455449
Sink kinds
456450
~~~~~~~~~~
457451

458-
Unlike sources, sinks tend to be highly query-specific, rarely affecting more than one or two queries. Not every query supports customizable sinks. If there is no suitable sink kind below, it is best to add a new query instead.
452+
Unlike sources, sinks tend to be highly query-specific, rarely affecting more than one or two queries. Not every query supports customizable sinks. If the following sinks are not suitable for your use case, you should add a new query.
459453

460454
- **code-injection**: A sink that can be used to inject code, such as in calls to **eval**.
461455
- **command-line-injection**: A sink that can be used to inject shell commands, such as in calls to **child_process.spawn**.
462-
- **path-injection**: A sink that can be used for path injection in a file system access, such as in a calls to **fs.readFile**.
456+
- **path-injection**: A sink that can be used for path injection in a file system access, such as in calls to **fs.readFile**.
463457
- **sql-injection**: A sink that can be used for SQL injection, such as in a MySQL **query** call.
464458
- **nosql-injection**: A sink that can be used for NoSQL injection, such as in a MongoDB **findOne** call.
465459
- **html-injection**: A sink that can be used for HTML injection, such as in a jQuery **$()** call.

0 commit comments

Comments
 (0)