Skip to content

Commit c624536

Browse files
committed
Java: Summary flow reference material.
1 parent 0f03605 commit c624536

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ The **Reference material** section will in more detail describe the *mini DSLs*
3838
Example: Taint sink in the **java.sql** package.
3939
------------------------------------------------
4040

41-
In this example we will see, how to define the argument passed to the **execute** method as a SQL injection sink.
41+
In this example we will see, how to define the argument of the **execute** method as a SQL injection sink.
4242
This is the **execute** method in the **Statement** class, which is located in the 'java.sql' package.
4343
Please note that this sink is already added to the CodeQL Java analysis.
4444

4545
.. code-block:: java
4646
4747
public static void taintsink(Connection conn, String query) throws SQLException {
4848
Statement stmt = conn.createStatement();
49-
stmt.execute(query); // The argument passed to this method is a SQL injection sink.
49+
stmt.execute(query); // The argument to this method is a SQL injection sink.
5050
}
5151
5252
This can be achieved by adding the following data extension.
@@ -74,20 +74,20 @@ The first five values are used to identify the method (callable) which we are de
7474
For most practical purposes the sixth value is not relevant.
7575
The remaining values are used to define the **access path**, the **kind**, and the **provenance** (origin) of the sink.
7676

77-
- The seventh value **Argument[0]** is the access path to the first argument passed to the method, which means that this is the location of the sink.
78-
- The eighth value **sql** is the kind of the sink. The sink kind is used to define for which queries the sink is in scope.
77+
- The seventh value **Argument[0]** is the **access path** to the first argument passed to the method, which means that this is the location of the sink.
78+
- The eighth value **sql** is the kind of the sink. The sink kind is used to define for which queries the sink is in scope. In this case SQL injection queries.
7979
- The ninth value **manual** is the provenance of the sink, which is used to identify the origin of the sink.
8080

8181
Example: Taint source from the **java.net** package.
8282
----------------------------------------------------
83-
In this example we will see, how to define the return value from the **getInputStream** method as a remote source.
84-
This is the **getInputStream** method in the **Socket** class, which is located in the 'java.net' package.
83+
In this example we will see, how to define the return value from the **getInputStream** method as a **remote** source.
84+
This is the **getInputStream** method in the **Socket** class, which is located in the **java.net** package.
8585
Please note that this source is already added to the CodeQL Java analysis.
8686

8787
.. code-block:: java
8888
8989
public static InputStream tainted(Socket socket) throws IOException {
90-
InputStream stream = socket.getInputStream(); // The return value of this method is a remote source.
90+
InputStream stream = socket.getInputStream(); // The return value of this method is a remote source of taint.
9191
return stream;
9292
}
9393
@@ -207,17 +207,22 @@ These are the same for both of the rows above.
207207

208208
For most practical purposes the sixth value is not relevant.
209209
The remaining values are used to define the **access path**, the **kind**, and the **provenance** (origin) of the source.
210+
210211
- The seventh value is the access path to the **input** where data flows from.
211212
- The eighth value **ReturnValue** is the access path to the **output** where data flows too.
212213

213214
For the first row the
215+
214216
- The seventh value is **Argument[-1].Element**, which is the access path to the elements of the qualifier (the elements of the stream **s** in the example).
215217
- The eight value is **Argument[0].Paramter[0]**, which is the access path the first parameter of the **Function** argument of **map** (the lambda parameter **e** in the example).
216218

217219
For the second row the
220+
218221
- The seventh value is **Argument[0].ReturnValue**, which is the access path to the return value of the **Function** argument of **map** (the return value of the lambda in the example).
219222
- The eighth value is **ReturnValue.Element**, which is the access path to the elements of the return value of **map** (the elements of the stream **l** in the example).
220223

224+
The remaining values for both rows
225+
221226
- The ninth value **value** is the kind of the flow. **value** means that the value is propagated.
222227
- The tenth value **manual** is the provenance of the source, which is used to identify the origin of the summary.
223228

@@ -283,7 +288,7 @@ Taint source. Most taint tracking queries will use the sources added to this ext
283288
- **ext**: Specifies additional API-graph-like edges (mostly empty).
284289
- **output**: Access path to the source, where the possibly tainted data flows from.
285290
- **kind**: Kind of the source.
286-
- **provenance**: Provenance (origin) of the source.
291+
- **provenance**: Provenance (origin) of the source definition.
287292

288293
As most sources are used by all taint tracking queries there are only a few different source kinds.
289294
The following source kinds are supported:
@@ -306,7 +311,7 @@ Taint sink. As opposed to source kinds, there are many different kinds of sinks
306311
- **ext**: Specifies additional API-graph-like edges (mostly empty).
307312
- **input**: Access path to the sink, where we want to check if possibly tainted data flows too.
308313
- **kind**: Kind of the sink.
309-
- **provenance**: Provenance (origin) of the sink.
314+
- **provenance**: Provenance (origin) of the sink definition.
310315

311316
The following sink kinds are supported:
312317

@@ -340,6 +345,24 @@ The following sink kinds are supported:
340345
summaryModel(package, type, subtypes, name, signature, ext, input, output, kind, provenance)
341346
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
342347

348+
Flow through. This extension point is used to model flow through methods.
349+
350+
- **package**: Name of the package where the method resides.
351+
- **type**: Name of the type where the method resides.
352+
- **subtypes**: Whether the method should also apply to all overrides of the method.
353+
- **name**: Name of the method where we are defining flow through.
354+
- **signature**: Type signature of the method where we are defining flow through.
355+
- **ext**: Specifies additional API-graph-like edges (mostly empty).
356+
- **input**: Access path to the input of the method where data will flow to the output.
357+
- **output**: Access path to the output of the method where data will flow from the input.
358+
- **kind**: Kind of the flow through.
359+
- **provenance**: Provenance (origin) of the flow through.
360+
361+
The following kinds are supported:
362+
363+
- **taint**: This means the output is not necessarily equal to the input, but it was derived from the input in an unrestrictive way. An attacker who controls the input will have significant control over the output as well.
364+
- **value**: This means that the output equals the input or a copy of the input such that all of its properties are preserved.
365+
343366
neutralModel(package, type, name, signature, provenance)
344367
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
345368

0 commit comments

Comments
 (0)