Skip to content

Commit d1cc53c

Browse files
authored
Merge pull request #588 from adityasharad/merge/1.19-next-301118
Merge rc/1.19 into next.
2 parents 47e15a6 + 3caf4e5 commit d1cc53c

File tree

149 files changed

+13928
-9312
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+13928
-9312
lines changed

change-notes/1.19/analysis-cpp.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323
| Expression has no effect | Fewer false positive results | Expressions in template instantiations are now excluded from this query. |
2424
| Global could be static | Fewer false positive results | Variables with declarations in header files are now excluded from this query. |
2525
| Resource not released in destructor | Fewer false positive results | Placement new is now excluded from the query. Also fixed an issue where false positives could occur if the destructor body was not in the snapshot. |
26+
| Memory is never freed | Fewer false positive results | This query now accounts for C++ _placement new_, which returns a pointer that does not need to be freed. |
2627
| Missing return statement (`cpp/missing-return`) | Visible by default | The precision of this query has been increased from 'medium' to 'high', which makes it visible by default in LGTM. It was 'medium' in release 1.17 and 1.18 because it had false positives due to an extractor bug that was fixed in 1.18. |
2728
| Missing return statement | Fewer false positive results | The query is now produces correct results when a function returns a template-dependent type, or makes a non-returning call to another function. |
29+
| Multiplication result converted to larger type (`cpp/integer-multiplication-cast-to-long`) | Fewer false positive results | Char-typed numbers are no longer considered to be potentially large. |
30+
| Non-virtual destructor in base class (`cpp/virtual-destructor`) | Fewer false positive results | This query was copied from file `AV Rule 78.ql` to `NonVirtualDestructorInBaseClass.ql` and renamed from "No virtual destructor" to "Non-virtual destructor in base class". The new version ignores base classes with non-public destructors since we consider those to be adequately protected. The new version retains the query id `cpp/virtual-destructor` and is displayed by default on LGTM, while `AV Rule 78.ql` is not run on LGTM. |
31+
| Overloaded assignment does not return 'this' (`cpp/assignment-does-not-return-this`) | Fewer false positive results | This query now ignores any return statements that are unreachable. |
2832
| Static array access may cause overflow | More correct results | Data flow to the size argument of a buffer operation is now checked in this query. |
2933
| Call to memory access function may overflow buffer | More correct results | Array indexing with a negative index is now detected by this query. |
3034
| Self comparison | Fewer false positive results | Code inside macro invocations is now excluded from the query. |
@@ -39,6 +43,8 @@
3943

4044
## Changes to QL libraries
4145

42-
* Added a hash consing library for structural comparison of expressions.
43-
* `getBufferSize` now detects variable size structs more reliably.
44-
* Buffer.qll now treats arrays of zero size as a special case.
46+
* Added a hash consing library (`semmle.code.cpp.valuenumbering.HashCons`) for structural comparison of expressions. Unlike the existing library for global value numbering, this library implements a pure syntactic comparison of expressions and will equate expressions even if they may not compute the same value.
47+
* The `Buffer.qll` library has more conservative treatment of arrays embedded in structs. This reduces false positives in a number of security queries, especially `cpp/overflow-buffer`.
48+
* Pre-C99 encodings of _flexible array members_ are recognized more reliably.
49+
* Arrays of zero size are now treated as a special case.
50+
* The library `semmle.code.cpp.dataflow.RecursionPrevention` is now deprecated. It was an aid for transitioning data-flow queries from 1.16 to 1.17, and it no longer has any function. Imports of this library should simply be deleted.

change-notes/1.19/analysis-javascript.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## General improvements
44

5-
* Modelling of taint flow through array operations has been improved. This may give additional results for the security queries.
5+
* Modeling of taint flow through array and buffer operations has been improved. This may give additional results for the security queries.
66

77
* Support for AMD modules has been improved. This may give additional results for the security queries as well as any queries that use type inference on code bases that use such modules.
88

@@ -23,12 +23,14 @@
2323
|-----------------------------------------------|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
2424
| Enabling Node.js integration for Electron web content renderers (`js/enabling-electron-renderer-node-integration`) | security, frameworks/electron, external/cwe/cwe-094 | Highlights Electron web content renderer preferences with Node.js integration enabled, indicating a violation of [CWE-94](https://cwe.mitre.org/data/definitions/94.html). Results are not shown on LGTM by default. |
2525
| File data in outbound network request | security, external/cwe/cwe-200 | Highlights locations where file data is sent in a network request. Results are not shown on LGTM by default. |
26+
| Hard-coded data interpreted as code | security, external/cwe/cwe-506 | Highlights locations where hard-coded data is transformed and then executed as code or interpreted as an import path, which may indicate embedded malicious code ([CWE-506](https://cwe.mitre.org/data/definitions/506.html)). Results are shown on LGTM by default. |
2627
| Host header poisoning in email generation | security, external/cwe/cwe-640 | Highlights code that generates emails with links that can be hijacked by HTTP host header poisoning, indicating a violation of [CWE-640](https://cwe.mitre.org/data/definitions/640.html). Results shown on LGTM by default. |
27-
| Unsafe dynamic method access (`js/unsafe-dynamic-method-access` ) | security, external/cwe/cwe-094 | Highlights code that invokes a user-controlled method on an object with unsafe methods. Results are shown on LGTM by default. |
2828
| Replacement of a substring with itself (`js/identity-replacement`) | correctness, security, external/cwe/cwe-116 | Highlights string replacements that replace a string with itself, which usually indicates a mistake. Results shown on LGTM by default. |
2929
| Stored cross-site scripting (`js/stored-xss`) | security, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights uncontrolled stored values flowing into HTML content, indicating a violation of [CWE-079](https://cwe.mitre.org/data/definitions/79.html). Results shown on LGTM by default. |
3030
| Unclear precedence of nested operators (`js/unclear-operator-precedence`) | maintainability, correctness, external/cwe/cwe-783 | Highlights nested binary operators whose relative precedence is easy to misunderstand. Results shown on LGTM by default. |
3131
| Unneeded defensive code | correctness, external/cwe/cwe-570, external/cwe/cwe-571 | Highlights locations where defensive code is not needed. Results are shown on LGTM by default. |
32+
| Unsafe dynamic method access (`js/unsafe-dynamic-method-access` ) | security, external/cwe/cwe-094 | Highlights code that invokes a user-controlled method on an object with unsafe methods. Results are shown on LGTM by default. |
33+
| Unvalidated dynamic method access (`js/unvalidated-dynamic-method-call` ) | security, external/cwe/cwe-754 | Highlights code that invokes a user-controlled method without guarding against exceptional circumstances. Results are shown on LGTM by default. |
3234
| Useless assignment to property | maintainability | Highlights property assignments whose value is always overwritten. Results are shown on LGTM by default. |
3335
| User-controlled data in file | security, external/cwe/cwe-912 | Highlights locations where user-controlled data is written to a file. Results are not shown on LGTM by default. |
3436

@@ -43,12 +45,13 @@
4345
| Conflicting HTML element attributes | Lower severity | The severity of this rule has been revised to "warning". |
4446
| Duplicate 'if' condition | Lower severity | The severity of this rule has been revised to "warning". |
4547
| Duplicate switch case | Lower severity | The severity of this rule has been revised to "warning". |
48+
| Inconsistent use of 'new' | Simpler result presentation | This rule now only shows one call with `new` and one without. |
4649
| Information exposure through a stack trace | More results | This rule now also flags cases where the entire exception object (including the stack trace) may be exposed. |
47-
| Missing CSRF middleware | Fewer false-positive results | This rule now recognizes additional CSRF protection middlewares. |
4850
| Missing 'this' qualifier | Fewer false-positive results | This rule now recognizes additional intentional calls to global functions. |
51+
| Missing CSRF middleware | Fewer false-positive results | This rule now recognizes additional CSRF protection middlewares. |
4952
| Missing variable declaration | Lower severity | The severity of this rule has been revised to "warning". |
5053
| Regular expression injection | Fewer false-positive results | This rule now identifies calls to `String.prototype.search` with more precision. |
51-
| Remote property injection | Fewer results | The precision of this rule has been revised to "medium". Results are no longer shown on LGTM by default. |
54+
| Remote property injection | Fewer results | The precision of this rule has been revised to "medium". Furthermore, it no longer flags dynamic method calls, which are now handled by two new queries. Results are no longer shown on LGTM by default. |
5255
| Self assignment | Fewer false-positive results | This rule now ignores self-assignments preceded by a JSDoc comment with a `@type` tag. |
5356
| Server-side URL redirect | Fewer false-positive results | This rule now recognizes safe redirects in more cases. |
5457
| Server-side URL redirect | More results | This rule now recognizes redirection calls in more cases. |
@@ -59,6 +62,7 @@
5962
| Unused variable, import, function or class | Fewer false-positive results | This rule now flags fewer variables that may be used by `eval` calls. |
6063
| Unused variable, import, function or class | Fewer results | This rule now flags import statements with multiple unused imports once. |
6164
| Useless assignment to local variable | Fewer false-positive results | This rule now recognizes additional ways default values can be set. |
65+
| Useless conditional | More results, fewer false-positive results | This rule now recognizes conditionals in more cases, but no longer flags certain defensive coding patterns. |
6266
| Whitespace contradicts operator precedence | Fewer false-positive results | This rule no longer flags operators with asymmetric whitespace. |
6367
| Wrong use of 'this' for static method | More results, fewer false-positive results | This rule now recognizes inherited methods. |
6468

Lines changed: 28 additions & 39 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,76 +18,67 @@ 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
|-----------------------------|-----------|--------------------------------------------------------------------|
59-
| 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. Enabled on LGTM by default. |
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. |
46+
| 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. |
47+
| 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. |
48+
| 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. |
49+
| Request without certificate validation (`py/request-without-cert-validation`) | security, external/cwe/cwe-295 | Finds requests where certificate verification has been explicitly turned off, possibly allowing man-in-the-middle attacks. Results are hidden on LGTM by default. |
50+
| Use of weak cryptographic key (`py/weak-crypto-key`) | security, external/cwe/cwe-326 | Finds creation of weak cryptographic keys. Results are shown on LGTM by default. |
6051

6152
## Changes to existing queries
6253

6354
All taint-tracking queries now support visualization of paths in QL for Eclipse.
64-
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`)
6562

6663
| **Query** | **Expected impact** | **Change** |
6764
|----------------------------|------------------------|------------------------------------------------------------------|
68-
| 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. |
69-
| Code injection (`py/code-injection`) | Supports path visualization and is now visible on LGTM by default | No change to expected results |
70-
| Command injection (`py/command-line-injection`) | Additional sinks in the `os`, and `popen` modules | Possibility of new results |
71-
| Deserializing untrusted input (`py/unsafe-deserialization`) | Supports path visualization | No change to expected results |
72-
| 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. |
7367
| 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. |
74-
| 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 |
75-
| 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 |
76-
| 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 |
77-
| Uncontrolled command line (`py/command-line-injection`) | Supports path visualization and is now visible on LGTM by default | No change to expected results |
78-
| 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. |
7969

8070

8171
## Changes to code extraction
8272

8373
* Improved scalability: Scaling is near linear to at least 20 CPU cores.
84-
* 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.
8575
* The `-v` flag can be specified multiple times to increase logging level by one per `-v`.
8676
* The `-q` flag has been added and can be specified multiple times to reduce the logging level by one per `-q`.
8777
* Log lines are now in the `[SEVERITY] message` style and never overlap.
88-
* 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.
8979

9080
## Changes to QL libraries
9181

92-
* Taint tracking analysis now understands HTTP requests in the `twisted` library.
93-
82+
* Taint-tracking analysis now understands HTTP requests in the `twisted` library.
9483
* 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`
9584
* 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)