Skip to content

Commit d933152

Browse files
authored
Merge pull request #573 from felicity-semmle/1.19/python-change-notes
Python: finalize change notes for 1.19
2 parents 608d84c + 586eaef commit d933152

File tree

1 file changed

+23
-38
lines changed

1 file changed

+23
-38
lines changed
Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# Improvements to Python analysis
22

3-
43
## General improvements
54

6-
> Changes that affect alerts in many files or from many queries
7-
> For example, changes to file classification
8-
95
### Representation of the control flow graph
106

11-
The representation of the control flow graph (CFG) has been modified to better reflect the semantics of Python.
7+
The representation of the control flow graph (CFG) has been modified to better reflect the semantics of Python. As part of these changes, a new predicate `Stmt.getAnEntryNode()` has been added to make it easier to write reachability queries involving statements.
8+
9+
#### CFG nodes removed
1210

1311
The following statement types no longer have a CFG node for the statement itself, as their sub-expressions already contain all the
1412
semantically significant information:
@@ -20,42 +18,31 @@ semantically significant information:
2018

2119
For example, the CFG for `if cond: foo else bar` now starts with the CFG node for `cond`.
2220

23-
For the following statement types, the CFG node for the statement now follows the CFG nodes of its sub-expressions to better reflect the semantics:
21+
#### CFG nodes reordered
22+
23+
For the following statement types, the CFG node for the statement now follows the CFG nodes of its sub-expressions to follow Python semantics:
2424

2525
* `Print`
2626
* `TemplateWrite`
2727
* `ImportStar`
2828

29-
For example the CFG for `print foo` (in Python 2) has changed from `print -> foo` to `foo -> print`, better reflecting the runtime behavior.
30-
29+
For example the CFG for `print foo` (in Python 2) has changed from `print -> foo` to `foo -> print`, to reflect the runtime behavior.
3130

3231
The CFG for the `with` statement has been re-ordered to more closely reflect the semantics.
3332
For the `with` statement:
3433
```python
3534
with cm as var:
3635
body
3736
```
38-
The order of the CFG changes from:
39-
40-
<with>
41-
cm
42-
var
43-
body
44-
45-
to:
46-
47-
cm
48-
<with>
49-
var
50-
body
51-
52-
A new predicate `Stmt.getAnEntryNode()` has been added to make it easier to write reachability queries involving statements.
5337

38+
* Previous CFG node order: `<with>` -> `cm` -> `var` -> `body`
39+
* New CFG node order: `cm` -> `<with>` -> `var` -> `body`
5440

5541
## New queries
5642

5743
| **Query** | **Tags** | **Purpose** |
5844
|-----------------------------|-----------|--------------------------------------------------------------------|
45+
| Assert statement tests the truth value of a literal constant (`py/assert-literal-constant`) | reliability, correctness | Checks whether an assert statement is testing the truth of a literal constant value. Results are hidden on LGTM by default. |
5946
| Flask app is run in debug mode (`py/flask-debug`) | security, external/cwe/cwe-215, external/cwe/cwe-489 | Finds instances where a Flask application is run in debug mode. Results are shown on LGTM by default. |
6047
| Information exposure through an exception (`py/stack-trace-exposure`) | security, external/cwe/cwe-209, external/cwe/cwe-497 | Finds instances where information about an exception may be leaked to an external user. Results are shown on LGTM by default. |
6148
| Jinja2 templating with autoescape=False (`py/jinja2/autoescape-false`) | security, external/cwe/cwe-079 | Finds instantiations of `jinja2.Environment` with `autoescape=False` which may allow XSS attacks. Results are hidden on LGTM by default. |
@@ -65,35 +52,33 @@ A new predicate `Stmt.getAnEntryNode()` has been added to make it easier to writ
6552
## Changes to existing queries
6653

6754
All taint-tracking queries now support visualization of paths in QL for Eclipse.
68-
Most security alerts are now visible on LGTM by default.
55+
Most security alerts are now visible on LGTM by default. This means that you may see results that were previously hidden for the following queries:
56+
57+
* Code injection (`py/code-injection`)
58+
* Reflected server-side cross-site scripting (`py/reflective-xss`)
59+
* SQL query built from user-controlled sources (`py/sql-injection`)
60+
* Uncontrolled data used in path expression (`py/path-injection`)
61+
* Uncontrolled command line (`py/command-line-injection`)
6962

7063
| **Query** | **Expected impact** | **Change** |
7164
|----------------------------|------------------------|------------------------------------------------------------------|
72-
| Assert statement tests the truth value of a literal constant (`py/assert-literal-constant`) | reliability, correctness | Checks whether an assert statement is testing the truth of a literal constant value. Not shown by default. |
73-
| Code injection (`py/code-injection`) | Supports path visualization and is now visible on LGTM by default | No change to expected results |
74-
| Command injection (`py/command-line-injection`) | Additional sinks in the `os`, and `popen` modules | Possibility of new results |
75-
| Deserializing untrusted input (`py/unsafe-deserialization`) | Supports path visualization | No change to expected results |
76-
| Encoding error (`py/encoding-error`) | Better alert location | Alert is now shown at the position of the first offending character, rather than at the top of the file. |
65+
| Command injection (`py/command-line-injection`) | More results | Additional sinks in the `os`, and `popen` modules may find more results in some projects. |
66+
| Encoding error (`py/encoding-error`) | Better alert location | Alerts are now shown at the start of the encoding error, rather than at the top of the file. |
7767
| Missing call to \_\_init\_\_ during object initialization (`py/missing-call-to-init`) | Fewer false positive results | Results where it is likely that the full call chain has not been analyzed are no longer reported. |
78-
| Reflected server-side cross-site scripting (`py/reflective-xss`) | Supports path visualization and is now visible on LGTM by default | No change to expected results |
79-
| SQL query built from user-controlled sources (`py/sql-injection`) | Supports path visualization and is now visible on LGTM by default | No change to expected results |
80-
| Uncontrolled data used in path expression (`py/path-injection`) | Supports path visualization and is now visible on LGTM by default | No change to expected results |
81-
| Uncontrolled command line (`py/command-line-injection`) | Supports path visualization and is now visible on LGTM by default | No change to expected results |
82-
| URL redirection from remote source (`py/url-redirection`) | Fewer false positive results and now supports path visualization | Taint is no longer tracked from the right hand side of binary expressions. In other words `SAFE + TAINTED` is now treated as safe. |
68+
| URL redirection from remote source (`py/url-redirection`) | Fewer false positive results | Taint is no longer tracked from the right-hand side of binary expressions. In other words `SAFE + TAINTED` is now treated as safe. |
8369

8470

8571
## Changes to code extraction
8672

8773
* Improved scalability: Scaling is near linear to at least 20 CPU cores.
88-
* Five levels of logging can be selected: `ERROR`, `WARN`, `INFO`, `DEBUG` and `TRACE`. `WARN` is the stand-alone default, but `INFO` will be used when run by LGTM.
74+
* Five levels of logging can be selected: `ERROR`, `WARN`, `INFO`, `DEBUG` and `TRACE`. LGTM uses `INFO` level logging. QL tools use `WARN` level logging by default.
8975
* The `-v` flag can be specified multiple times to increase logging level by one per `-v`.
9076
* The `-q` flag has been added and can be specified multiple times to reduce the logging level by one per `-q`.
9177
* Log lines are now in the `[SEVERITY] message` style and never overlap.
92-
* Extractor now outputs the location of the first offending character when an EncodingError is encountered.
78+
* The extractor now outputs the location of the first character that triggers an EncodingError.
9379

9480
## Changes to QL libraries
9581

96-
* Taint tracking analysis now understands HTTP requests in the `twisted` library.
97-
82+
* Taint-tracking analysis now understands HTTP requests in the `twisted` library.
9883
* The analysis now handles `isinstance` and `issubclass` tests involving the basic abstract base classes better. For example, the test `issubclass(list, collections.Sequence)` is now understood to be `True`
9984
* Taint tracking automatically tracks tainted mappings and collections, without you having to add additional taint kinds. This means that custom taints are tracked from `x` to `y` in the following flow: `l = [x]; y =l[0]`.

0 commit comments

Comments
 (0)