Skip to content

Commit 2da1503

Browse files
committed
Merge branch 'master' into python-support-django2
2 parents e804e98 + dd0ce1c commit 2da1503

File tree

705 files changed

+34874
-18826
lines changed

Some content is hidden

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

705 files changed

+34874
-18826
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ Follow the steps below to help other users understand what your query does, and
4646
Query help files explain the purpose of your query to other users. Write your query help in a `.qhelp` file and save it in the same directory as your new query.
4747
For more information on writing query help, see the [Query help style guide](https://github.com/Semmle/ql/blob/master/docs/query-help-style-guide.md).
4848

49+
7. **Maintain backwards compatibility**
50+
51+
The standard CodeQL libraries must evolve in a backwards compatible manner. If any backwards incompatible changes need to be made, the existing API must first be marked as deprecated. This is done by adding a `deprecated` annotation along with a QLDoc reference to the replacement API. Only after at least one full release cycle has elapsed may the old API be removed.
52+
53+
In addition to contributions to our standard queries and libraries, we also welcome contributions of a more experimental nature, which do not need to fulfill all the requirements listed above. See the guidelines for [experimental queries and libraries](docs/experimental.md) for details.
54+
4955
## Using your personal data
5056

5157
If you contribute to this project, we will record your name and email

change-notes/1.24/analysis-cpp.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
2727

2828
## Changes to libraries
2929

30-
* The data-flow library has been improved when flow through functions needs to be
31-
combined with both taint tracking and flow through fields allowing more flow
32-
to be tracked. This affects and improves some security queries, which may
33-
report additional results.
30+
* The data-flow library has been improved, which affects and improves some security queries. The improvements are:
31+
- Track flow through functions that combine taint tracking with flow through fields.
32+
- Track flow through clone-like functions, that is, functions that read contents of a field from a
33+
parameter and stores the value in the field of a returned object.
3434
* Created the `semmle.code.cpp.models.interfaces.Allocation` library to model allocation such as `new` expressions and calls to `malloc`. This in intended to replace the functionality in `semmle.code.cpp.commons.Alloc` with a more consistent and useful interface.
3535
* Created the `semmle.code.cpp.models.interfaces.Deallocation` library to model deallocation such as `delete` expressions and calls to `free`. This in intended to replace the functionality in `semmle.code.cpp.commons.Alloc` with a more consistent and useful interface.
3636
* The new class `StackVariable` should be used in place of `LocalScopeVariable`
@@ -46,3 +46,5 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
4646
the following improvements:
4747
* The library now models data flow through `strdup` and similar functions.
4848
* The library now models data flow through formatting functions such as `sprintf`.
49+
* The security pack taint tracking library (`semmle.code.cpp.security.TaintTracking`) uses a new intermediate representation. This provides a more precise analysis of pointers to stack variables and flow through parameters, improving the results of many security queries.
50+
* The global value numbering library (`semmle.code.cpp.valuenumbering.GlobalValueNumbering`) uses a new intermediate representation to provide a more precise analysis of heap allocated memory and pointers to stack variables.

change-notes/1.24/analysis-csharp.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ The following changes in version 1.24 affect C# analysis in all applications.
3333

3434
## Changes to libraries
3535

36-
* The data-flow library has been improved when flow through methods needs to be
37-
combined with both taint tracking and flow through fields allowing more flow
38-
to be tracked. This affects and improves most security queries, which may
39-
report additional results.
36+
* The data-flow library has been improved, which affects and improves most security queries. The improvements are:
37+
- Track flow through methods that combine taint tracking with flow through fields.
38+
- Track flow through clone-like methods, that is, methods that read contents of a field from a
39+
parameter and stores the value in the field of a returned object.
4040
* The taint tracking library now tracks flow through (implicit or explicit) conversion operator calls.
4141
* [Code contracts](https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts) are now recognized, and are treated like any other assertion methods.
4242
* Expression nullability flow state is given by the predicates `Expr.hasNotNullFlowState()` and `Expr.hasMaybeNullFlowState()`.

change-notes/1.24/analysis-java.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The following changes in version 1.24 affect Java analysis in all applications.
55
## General improvements
66

77
* Alert suppression can now be done with single-line block comments (`/* ... */`) as well as line comments (`// ...`).
8+
* A `Customizations.qll` file has been added to allow customizations of the standard library that apply to all queries.
89

910
## New queries
1011

@@ -26,10 +27,10 @@ The following changes in version 1.24 affect Java analysis in all applications.
2627

2728
## Changes to libraries
2829

29-
* The data-flow library has been improved when flow through methods needs to be
30-
combined with both taint tracking and flow through fields allowing more flow
31-
to be tracked. This affects and improves most security queries, which may
32-
report additional results.
30+
* The data-flow library has been improved, which affects and improves most security queries. The improvements are:
31+
- Track flow through methods that combine taint tracking with flow through fields.
32+
- Track flow through clone-like methods, that is, methods that read contents of a field from a
33+
parameter and stores the value in the field of a returned object.
3334
* Identification of test classes has been improved. Previously, one of the
3435
match conditions would classify any class with a name containing the string
3536
"Test" as a test class, but now this matching has been replaced with one that

change-notes/1.24/analysis-javascript.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
## General improvements
44

5+
* TypeScript 3.8 is now supported.
6+
57
* Alert suppression can now be done with single-line block comments (`/* ... */`) as well as line comments (`// ...`).
68

79
* Imports with the `.js` extension can now be resolved to a TypeScript file,
810
when the import refers to a file generated by TypeScript.
911

1012
* Imports that rely on path-mappings from a `tsconfig.json` file can now be resolved.
1113

14+
* Export declarations of the form `export * as ns from "x"` are now analyzed more precisely.
15+
1216
* The analysis of sanitizer guards has improved, leading to fewer false-positive results from the security queries.
1317

18+
* The call graph construction has been improved, leading to more results from the security queries:
19+
- Calls can now be resolved to indirectly-defined class members in more cases.
20+
- Calls through partial invocations such as `.bind` can now be resolved in more cases.
21+
22+
* Support for flow summaries has been more clearly marked as being experimental and moved to the new `experimental` folder.
23+
1424
* Support for the following frameworks and libraries has been improved:
1525
- [Electron](https://electronjs.org/)
1626
- [Handlebars](https://www.npmjs.com/package/handlebars)
@@ -24,6 +34,7 @@
2434
- [http2](https://nodejs.org/api/http2.html)
2535
- [lazy-cache](https://www.npmjs.com/package/lazy-cache)
2636
- [react](https://www.npmjs.com/package/react)
37+
- [request](https://www.npmjs.com/package/request)
2738
- [send](https://www.npmjs.com/package/send)
2839
- [typeahead.js](https://www.npmjs.com/package/typeahead.js)
2940
- [ws](https://github.com/websockets/ws)
@@ -35,7 +46,11 @@
3546
| Cross-site scripting through exception (`js/xss-through-exception`) | security, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights potential XSS vulnerabilities where an exception is written to the DOM. Results are not shown on LGTM by default. |
3647
| Regular expression always matches (`js/regex/always-matches`) | correctness, regular-expressions | Highlights regular expression checks that trivially succeed by matching an empty substring. Results are shown on LGTM by default. |
3748
| Missing await (`js/missing-await`) | correctness | Highlights expressions that operate directly on a promise object in a nonsensical way, instead of awaiting its result. Results are shown on LGTM by default. |
38-
| Prototype pollution in utility function (`js/prototype-pollution-utility`) | security, external/cwe/cwe-400, external/cwe/cwe-471 | Highlights recursive copying operations that are susceptible to prototype pollution. Results are shown on LGTM by default. |
49+
| Polynomial regular expression used on uncontrolled data (`js/polynomial-redos`) | security, external/cwe/cwe-730, external/cwe/cwe-400 | Highlights expensive regular expressions that may be used on malicious input. Results are shown on LGTM by default. |
50+
| Prototype pollution in utility function (`js/prototype-pollution-utility`) | security, external/cwe/cwe-400, external/cwe/cwe-471 | Highlights recursive assignment operations that are susceptible to prototype pollution. Results are shown on LGTM by default. |
51+
| Unsafe jQuery plugin (`js/unsafe-jquery-plugin`) | Highlights potential XSS vulnerabilities in unsafely designed jQuery plugins. Results are shown on LGTM by default. |
52+
| Unnecessary use of `cat` process (`js/unnecessary-use-of-cat`) | correctness, security, maintainability | Highlights command executions of `cat` where the fs API should be used instead. Results are shown on LGTM by default. |
53+
3954

4055
## Changes to existing queries
4156

@@ -48,8 +63,10 @@
4863
| Expression has no effect (`js/useless-expression`) | Fewer false positive results | The query now recognizes block-level flow type annotations and ignores the first statement of a try block. |
4964
| Use of call stack introspection in strict mode (`js/strict-mode-call-stack-introspection`) | Fewer false positive results | The query no longer flags expression statements. |
5065
| Missing CSRF middleware (`js/missing-token-validation`) | Fewer false positive results | The query reports fewer duplicates and only flags handlers that explicitly access cookie data. |
51-
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional ways dangerous paths can be constructed. |
66+
| Uncontrolled data used in path expression (`js/path-injection`) | More results | This query now recognizes additional ways dangerous paths can be constructed and used. |
5267
| Uncontrolled command line (`js/command-line-injection`) | More results | This query now recognizes additional ways of constructing arguments to `cmd.exe` and `/bin/sh`. |
68+
| Syntax error (`js/syntax-error`) | Lower severity | This results of this query are now displayed with lower severity. |
69+
| Use of password hash with insufficient computational effort (`js/insufficient-password-hash`) | Fewer false positive results | This query now recognizes additional cases that do not require secure hashing. |
5370

5471
## Changes to libraries
5572

config/identical-files.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,12 @@
222222
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/internal/PrintSSA.qll",
223223
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/internal/PrintSSA.qll"
224224
],
225-
"C++ IR ValueNumberInternal": [
225+
"IR ValueNumberInternal": [
226226
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/internal/ValueNumberingInternal.qll",
227227
"cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/gvn/internal/ValueNumberingInternal.qll",
228-
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/internal/ValueNumberingInternal.qll"
228+
"cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/gvn/internal/ValueNumberingInternal.qll",
229+
"csharp/ql/src/semmle/code/csharp/ir/implementation/raw/gvn/internal/ValueNumberingInternal.qll",
230+
"csharp/ql/src/semmle/code/csharp/ir/implementation/unaliased_ssa/gvn/internal/ValueNumberingInternal.qll"
229231
],
230232
"C++ IR ValueNumber": [
231233
"cpp/ql/src/semmle/code/cpp/ir/implementation/raw/gvn/ValueNumbering.qll",

cpp/ql/src/Likely Bugs/Arithmetic/UnsignedGEZero.qll

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,33 @@ class ConstantZero extends Expr {
1515
}
1616
}
1717

18+
/**
19+
* Holds if `candidate` is an expression such that if it's unsigned then we
20+
* want an alert at `ge`.
21+
*/
22+
private predicate lookForUnsignedAt(GEExpr ge, Expr candidate) {
23+
// Base case: `candidate >= 0`
24+
ge.getRightOperand() instanceof ConstantZero and
25+
candidate = ge.getLeftOperand().getFullyConverted() and
26+
// left operand was a signed or unsigned IntegralType before conversions
27+
// (not a pointer, checking a pointer >= 0 is an entirely different mistake)
28+
// (not an enum, as the fully converted type of an enum is compiler dependent
29+
// so checking an enum >= 0 is always reasonable)
30+
ge.getLeftOperand().getUnderlyingType() instanceof IntegralType
31+
or
32+
// Recursive case: `...(largerType)candidate >= 0`
33+
exists(Conversion conversion |
34+
lookForUnsignedAt(ge, conversion) and
35+
candidate = conversion.getExpr() and
36+
conversion.getType().getSize() > candidate.getType().getSize()
37+
)
38+
}
39+
1840
class UnsignedGEZero extends GEExpr {
1941
UnsignedGEZero() {
20-
this.getRightOperand() instanceof ConstantZero and
21-
// left operand was a signed or unsigned IntegralType before conversions
22-
// (not a pointer, checking a pointer >= 0 is an entirely different mistake)
23-
// (not an enum, as the fully converted type of an enum is compiler dependent
24-
// so checking an enum >= 0 is always reasonable)
25-
getLeftOperand().getUnderlyingType() instanceof IntegralType and
2642
exists(Expr ue |
27-
// ue is some conversion of the left operand
28-
ue = getLeftOperand().getConversion*() and
29-
// ue is unsigned
30-
ue.getUnderlyingType().(IntegralType).isUnsigned() and
31-
// ue may be converted to zero or more strictly larger possibly signed types
32-
// before it is fully converted
33-
forall(Expr following | following = ue.getConversion+() |
34-
following.getType().getSize() > ue.getType().getSize()
35-
)
43+
lookForUnsignedAt(this, ue) and
44+
ue.getUnderlyingType().(IntegralType).isUnsigned()
3645
)
3746
}
3847
}

cpp/ql/src/experimental/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory contains [experimental](../../../../docs/experimental.md) CodeQL queries and libraries.

cpp/ql/src/semmle/code/cpp/Field.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import semmle.code.cpp.exprs.Access
1919
class Field extends MemberVariable {
2020
Field() { fieldoffsets(underlyingElement(this), _, _) }
2121

22+
override string getCanonicalQLClass() { result = "Field" }
23+
2224
/**
2325
* Gets the offset of this field in bytes from the start of its declaring
2426
* type (on the machine where facts were extracted).
@@ -84,6 +86,8 @@ class Field extends MemberVariable {
8486
class BitField extends Field {
8587
BitField() { bitfield(underlyingElement(this), _, _) }
8688

89+
override string getCanonicalQLClass() { result = "BitField" }
90+
8791
/**
8892
* Gets the size of this bitfield in bits (on the machine where facts
8993
* were extracted).

cpp/ql/src/semmle/code/cpp/Variable.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ private import semmle.code.cpp.internal.ResolveClass
2828
* can have multiple declarations.
2929
*/
3030
class Variable extends Declaration, @variable {
31+
override string getCanonicalQLClass() { result = "Variable" }
32+
3133
/** Gets the initializer of this variable, if any. */
3234
Initializer getInitializer() { result.getDeclaration() = this }
3335

@@ -351,6 +353,8 @@ class StackVariable extends LocalScopeVariable {
351353
* A local variable can be declared by a `DeclStmt` or a `ConditionDeclExpr`.
352354
*/
353355
class LocalVariable extends LocalScopeVariable, @localvariable {
356+
override string getCanonicalQLClass() { result = "LocalVariable" }
357+
354358
override string getName() { localvariables(underlyingElement(this), _, result) }
355359

356360
override Type getType() { localvariables(underlyingElement(this), unresolveElement(result), _) }
@@ -396,6 +400,8 @@ class NamespaceVariable extends GlobalOrNamespaceVariable {
396400
NamespaceVariable() {
397401
exists(Namespace n | namespacembrs(unresolveElement(n), underlyingElement(this)))
398402
}
403+
404+
override string getCanonicalQLClass() { result = "NamespaceVariable" }
399405
}
400406

401407
/**
@@ -415,6 +421,8 @@ class NamespaceVariable extends GlobalOrNamespaceVariable {
415421
*/
416422
class GlobalVariable extends GlobalOrNamespaceVariable {
417423
GlobalVariable() { not this instanceof NamespaceVariable }
424+
425+
override string getCanonicalQLClass() { result = "GlobalVariable" }
418426
}
419427

420428
/**
@@ -434,6 +442,8 @@ class GlobalVariable extends GlobalOrNamespaceVariable {
434442
class MemberVariable extends Variable, @membervariable {
435443
MemberVariable() { this.isMember() }
436444

445+
override string getCanonicalQLClass() { result = "MemberVariable" }
446+
437447
/** Holds if this member is private. */
438448
predicate isPrivate() { this.hasSpecifier("private") }
439449

0 commit comments

Comments
 (0)