Skip to content

Commit 935d5d9

Browse files
committed
Merge branch 'main' into redsun82/swift-ifconfigdecl-ql
2 parents 239ec74 + 8689539 commit 935d5d9

File tree

203 files changed

+4585
-4481
lines changed

Some content is hidden

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

203 files changed

+4585
-4481
lines changed

.github/workflows/ruby-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ jobs:
197197
- name: Prepare test files
198198
shell: bash
199199
run: |
200-
echo "import ruby select count(File f)" > "test.ql"
200+
echo "import codeql.ruby.AST select count(File f)" > "test.ql"
201201
echo "| 4 |" > "test.expected"
202202
echo 'name: sample-tests
203203
version: 0.0.0

cpp/ql/src/Security/CWE/CWE-311/CleartextBufferWrite.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import semmle.code.cpp.ir.dataflow.TaintTracking
1919
import DataFlow::PathGraph
2020

2121
/**
22-
* Taint flow from user input to a buffer write.
22+
* A taint flow configuration for flow from user input to a buffer write.
2323
*/
2424
class ToBufferConfiguration extends TaintTracking::Configuration {
2525
ToBufferConfiguration() { this = "ToBufferConfiguration" }

cpp/ql/src/Security/CWE/CWE-311/CleartextFileWrite.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ import semmle.code.cpp.dataflow.TaintTracking
2121
import DataFlow::PathGraph
2222

2323
/**
24-
* Taint flow from a sensitive expression to a `FileWrite` sink.
24+
* A taint flow configuration for flow from a sensitive expression to a `FileWrite` sink.
2525
*/
2626
class FromSensitiveConfiguration extends TaintTracking::Configuration {
2727
FromSensitiveConfiguration() { this = "FromSensitiveConfiguration" }
2828

2929
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof SensitiveExpr }
3030

3131
override predicate isSink(DataFlow::Node sink) { any(FileWrite w).getASource() = sink.asExpr() }
32+
33+
override predicate isSanitizer(DataFlow::Node node) {
34+
node.asExpr().getUnspecifiedType() instanceof IntegralType
35+
}
3236
}
3337

3438
/**

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ class Encrypted extends Expr {
217217
}
218218

219219
/**
220-
* Taint flow from a sensitive expression.
220+
* A taint flow configuration for flow from a sensitive expression to a network
221+
* operation or encryption operation.
221222
*/
222223
class FromSensitiveConfiguration extends TaintTracking::Configuration {
223224
FromSensitiveConfiguration() { this = "FromSensitiveConfiguration" }
@@ -234,6 +235,10 @@ class FromSensitiveConfiguration extends TaintTracking::Configuration {
234235
// flow through encryption functions to the return value (in case we can reach other sinks)
235236
node2.asExpr().(Encrypted).(FunctionCall).getAnArgument() = node1.asExpr()
236237
}
238+
239+
override predicate isSanitizer(DataFlow::Node node) {
240+
node.asExpr().getUnspecifiedType() instanceof IntegralType
241+
}
237242
}
238243

239244
from

cpp/ql/src/Security/CWE/CWE-313/CleartextSqliteDatabase.ql

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@
1313

1414
import cpp
1515
import semmle.code.cpp.security.SensitiveExprs
16-
import semmle.code.cpp.security.TaintTracking
17-
import TaintedWithPath
18-
19-
class UserInputIsSensitiveExpr extends SecurityOptions {
20-
override predicate isUserInput(Expr expr, string cause) {
21-
expr instanceof SensitiveExpr and cause = "sensitive information"
22-
}
23-
}
16+
import semmle.code.cpp.dataflow.TaintTracking
17+
import DataFlow::PathGraph
2418

2519
class SqliteFunctionCall extends FunctionCall {
2620
SqliteFunctionCall() { this.getTarget().getName().matches("sqlite%") }
@@ -34,25 +28,51 @@ predicate sqlite_encryption_used() {
3428
any(FunctionCall fc).getTarget().getName().matches("sqlite%\\_key\\_%")
3529
}
3630

37-
class Configuration extends TaintTrackingConfiguration {
38-
override predicate isSource(Expr source) {
39-
super.isSource(source) and source instanceof SensitiveExpr
31+
/**
32+
* Gets a field of the class `c`, or of another class contained in `c`.
33+
*/
34+
Field getRecField(Class c) {
35+
result = c.getAField() or
36+
result = getRecField(c.getAField().getUnspecifiedType().stripType())
37+
}
38+
39+
/**
40+
* A taint flow configuration for flow from a sensitive expression to a `SqliteFunctionCall` sink.
41+
*/
42+
class FromSensitiveConfiguration extends TaintTracking::Configuration {
43+
FromSensitiveConfiguration() { this = "FromSensitiveConfiguration" }
44+
45+
override predicate isSource(DataFlow::Node source) { source.asExpr() instanceof SensitiveExpr }
46+
47+
override predicate isSink(DataFlow::Node sink) {
48+
any(SqliteFunctionCall c).getASource() = sink.asExpr() and
49+
not sqlite_encryption_used()
50+
}
51+
52+
override predicate isSanitizer(DataFlow::Node node) {
53+
node.asExpr().getUnspecifiedType() instanceof IntegralType
4054
}
4155

42-
override predicate isSink(Element taintedArg) {
43-
exists(SqliteFunctionCall sqliteCall |
44-
taintedArg = sqliteCall.getASource() and
45-
not sqlite_encryption_used()
56+
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet content) {
57+
// flow out from fields at the sink (only).
58+
this.isSink(node) and
59+
// constrain `content` to a field inside the node.
60+
exists(Class c |
61+
node.asExpr().getUnspecifiedType().stripType() = c and
62+
content.(DataFlow::FieldContent).getField() = getRecField(c)
4663
)
64+
or
65+
// any default implicit reads
66+
super.allowImplicitRead(node, content)
4767
}
4868
}
4969

5070
from
51-
SensitiveExpr taintSource, Expr taintedArg, SqliteFunctionCall sqliteCall, PathNode sourceNode,
52-
PathNode sinkNode
71+
FromSensitiveConfiguration config, SensitiveExpr sensitive, DataFlow::PathNode source,
72+
DataFlow::PathNode sink, SqliteFunctionCall sqliteCall
5373
where
54-
taintedWithPath(taintSource, taintedArg, sourceNode, sinkNode) and
55-
taintedArg = sqliteCall.getASource()
56-
select sqliteCall, sourceNode, sinkNode,
57-
"This SQLite call may store $@ in a non-encrypted SQLite database", taintSource,
58-
"sensitive information"
74+
config.hasFlowPath(source, sink) and
75+
source.getNode().asExpr() = sensitive and
76+
sqliteCall.getASource() = sink.getNode().asExpr()
77+
select sqliteCall, source, sink, "This SQLite call may store $@ in a non-encrypted SQLite database",
78+
sensitive, "sensitive information"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Modernizations from "Cleartext storage of sensitive information in buffer" (`cpp/cleartext-storage-buffer`) have been ported to the "Cleartext storage of sensitive information in file" (`cpp/cleartext-storage-file`), "Cleartext transmission of sensitive information" (`cpp/cleartext-transmission`) and "Cleartext storage of sensitive information in an SQLite database" (`cpp/cleartext-storage-database`) queries. These changes may result in more correct results and fewer false positive results from these queries.

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/CleartextFileWrite.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
edges
2-
| test2.cpp:52:44:52:57 | password_tries | test2.cpp:52:40:52:58 | * ... |
32
| test2.cpp:62:18:62:25 | password | test2.cpp:65:31:65:34 | cpy1 |
43
| test2.cpp:72:17:72:24 | password | test2.cpp:73:30:73:32 | buf |
54
| test2.cpp:72:17:72:24 | password | test2.cpp:76:30:76:32 | buf |
@@ -9,8 +8,6 @@ nodes
98
| test2.cpp:44:37:44:45 | thepasswd | semmle.label | thepasswd |
109
| test2.cpp:45:38:45:47 | accountkey | semmle.label | accountkey |
1110
| test2.cpp:50:41:50:53 | passwd_config | semmle.label | passwd_config |
12-
| test2.cpp:52:40:52:58 | * ... | semmle.label | * ... |
13-
| test2.cpp:52:44:52:57 | password_tries | semmle.label | password_tries |
1411
| test2.cpp:54:41:54:52 | widepassword | semmle.label | widepassword |
1512
| test2.cpp:55:40:55:51 | widepassword | semmle.label | widepassword |
1613
| test2.cpp:57:39:57:49 | call to getPassword | semmle.label | call to getPassword |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// See https://aka.ms/new-console-template for more information
2+
Console.WriteLine("Hello, World!");
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from create_database_utils import *
3+
4+
run_codeql_database_create(['dotnet pack'], test_db="default-db", db=None, lang="csharp")
5+
6+
## Check that the NuGet package is created.
7+
if not os.path.isfile("bin/Debug/dotnet_pack.1.0.0.nupkg"):
8+
raise Exception("The NuGet package was not created.")

0 commit comments

Comments
 (0)