Skip to content

Commit 8f5af3f

Browse files
authored
Merge branch 'main' into swift/js-injection
2 parents 8b33277 + 0796926 commit 8f5af3f

File tree

610 files changed

+50380
-15093
lines changed

Some content is hidden

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

610 files changed

+50380
-15093
lines changed

.github/ISSUE_TEMPLATE/lgtm-com---false-positive.md

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: CodeQL False positive
3+
about: Report CodeQL alerts that you think should not have been detected (not applicable, not exploitable, etc.)
4+
title: False positive
5+
labels: false-positive
6+
assignees: ''
7+
8+
---
9+
10+
**Description of the false positive**
11+
12+
<!-- Please explain briefly why you think it shouldn't be included. -->
13+
14+
**Code samples or links to source code**
15+
16+
<!--
17+
For open source code: file links with line numbers on GitHub, for example:
18+
https://github.com/github/codeql/blob/dc440aaee6695deb0d9676b87e06ea984e1b4ae5/javascript/ql/test/query-tests/Security/CWE-078/CommandInjection/exec-sh2.js#L10
19+
20+
For closed source code: (redacted) code samples that illustrate the problem, for example:
21+
22+
```
23+
function execSh(command, options) {
24+
return cp.spawn(getShell(), ["-c", command], options) // <- command line injection
25+
};
26+
```
27+
-->
28+
29+
**URL to the alert on GitHub code scanning (optional)**
30+
31+
<!--
32+
1. Open the project on GitHub.com.
33+
2. Switch to the `Security` tab.
34+
3. Browse to the alert that you would like to report.
35+
4. Copy and paste the page URL here.
36+
-->

.github/workflows/compile-queries.yml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
if: ${{ github.event_name == 'pull_request' }}
2727
uses: actions/cache@v3
2828
with:
29-
path: '*/ql/src/.cache'
29+
path: '**/.cache'
3030
key: codeql-compile-pr-${{ github.sha }} # deliberately not using the `compile-compile-main` keys here.
3131
restore-keys: |
3232
codeql-compile-${{ github.base_ref }}-${{ env.merge-base }}
@@ -36,7 +36,7 @@ jobs:
3636
if: ${{ github.event_name != 'pull_request' }}
3737
uses: actions/cache@v3
3838
with:
39-
path: '*/ql/src/.cache'
39+
path: '**/.cache'
4040
key: codeql-compile-${{ github.ref_name }}-${{ github.sha }} # just fill on main
4141
restore-keys: | # restore from another random commit, to speed up compilation.
4242
codeql-compile-${{ github.ref_name }}-
@@ -46,14 +46,26 @@ jobs:
4646
with:
4747
channel: 'release'
4848
- name: check formatting
49-
run: codeql query format */ql/**/*.{qll,ql} --check-only
49+
run: find */ql -type f \( -name "*.qll" -o -name "*.ql" \) -print0 | xargs -0 codeql query format --check-only
5050
- name: compile queries - check-only
5151
# run with --check-only if running in a PR (github.sha != main)
5252
if : ${{ github.event_name == 'pull_request' }}
5353
shell: bash
54-
run: codeql query compile -j0 */ql/src --keep-going --warnings=error --check-only
54+
run: codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --check-only
5555
- name: compile queries - full
5656
# do full compile if running on main - this populates the cache
5757
if : ${{ github.event_name != 'pull_request' }}
5858
shell: bash
59-
run: codeql query compile -j0 */ql/src --keep-going --warnings=error
59+
run: |
60+
# Move all the existing cache into another folder, so we only preserve the cache for the current queries.
61+
mkdir -p ${COMBINED_CACHE_DIR}
62+
rm -f */ql/{src,examples}/.cache/{lock,size} # -f to avoid errors if the cache is empty.
63+
# copy the contents of the .cache folders into the combined cache folder.
64+
cp -r */ql/{src,examples}/.cache/* ${COMBINED_CACHE_DIR}/ || : # ignore missing files
65+
# clean up the .cache folders
66+
rm -rf */ql/{src,examples}/.cache/*
67+
68+
# compile the queries
69+
codeql query compile -j0 */ql/{src,examples} --keep-going --warnings=error --compilation-cache ${COMBINED_CACHE_DIR}
70+
env:
71+
COMBINED_CACHE_DIR: ${{ github.workspace }}/compilation-dir

.github/workflows/swift.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
filters: |
2929
codegen:
30-
- 'github/workflows/swift.yml'
30+
- '.github/workflows/swift.yml'
3131
- "misc/bazel/**"
3232
- "*.bazel*"
3333
- 'swift/actions/setup-env/**'
@@ -111,4 +111,10 @@ jobs:
111111
- uses: actions/upload-artifact@v3
112112
with:
113113
name: swift-generated-cpp-files
114-
path: swift/generated-cpp-files/**
114+
path: generated-cpp-files/**
115+
database-upgrade-scripts:
116+
runs-on: ubuntu-latest
117+
steps:
118+
- uses: actions/checkout@v3
119+
- uses: ./.github/actions/fetch-codeql
120+
- uses: ./swift/actions/database-upgrade-scripts

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ repos:
1919
rev: v1.6.0
2020
hooks:
2121
- id: autopep8
22-
files: ^swift/codegen/.*\.py
22+
files: ^swift/.*\.py
2323

2424
- repo: local
2525
hooks:
@@ -44,7 +44,7 @@ repos:
4444

4545
- id: swift-codegen
4646
name: Run Swift checked in code generation
47-
files: ^swift/(codegen/|.*/generated/|ql/lib/(swift\.dbscheme$|codeql/swift/elements))
47+
files: ^swift/(schema.py$|codegen/|.*/generated/|ql/lib/(swift\.dbscheme$|codeql/swift/elements))
4848
language: system
4949
entry: bazel run //swift/codegen -- --quiet
5050
pass_filenames: false

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ WORKSPACE.bazel @github/codeql-ci-reviewers
4545
/.github/workflows/js-ml-tests.yml @github/codeql-ml-powered-queries-reviewers
4646
/.github/workflows/ql-for-ql-* @github/codeql-ql-for-ql-reviewers
4747
/.github/workflows/ruby-* @github/codeql-ruby
48-
/.github/workflows/swift-* @github/codeql-c
48+
/.github/workflows/swift.yml @github/codeql-c

config/identical-files.json

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -486,40 +486,6 @@
486486
"python/ql/lib/semmle/python/security/internal/SensitiveDataHeuristics.qll",
487487
"ruby/ql/lib/codeql/ruby/security/internal/SensitiveDataHeuristics.qll"
488488
],
489-
"ReDoS Util Python/JS/Ruby/Java": [
490-
"javascript/ql/lib/semmle/javascript/security/regexp/NfaUtils.qll",
491-
"python/ql/lib/semmle/python/security/regexp/NfaUtils.qll",
492-
"ruby/ql/lib/codeql/ruby/security/regexp/NfaUtils.qll",
493-
"java/ql/lib/semmle/code/java/security/regexp/NfaUtils.qll"
494-
],
495-
"ReDoS Exponential Python/JS/Ruby/Java": [
496-
"javascript/ql/lib/semmle/javascript/security/regexp/ExponentialBackTracking.qll",
497-
"python/ql/lib/semmle/python/security/regexp/ExponentialBackTracking.qll",
498-
"ruby/ql/lib/codeql/ruby/security/regexp/ExponentialBackTracking.qll",
499-
"java/ql/lib/semmle/code/java/security/regexp/ExponentialBackTracking.qll"
500-
],
501-
"ReDoS Polynomial Python/JS/Ruby/Java": [
502-
"javascript/ql/lib/semmle/javascript/security/regexp/SuperlinearBackTracking.qll",
503-
"python/ql/lib/semmle/python/security/regexp/SuperlinearBackTracking.qll",
504-
"ruby/ql/lib/codeql/ruby/security/regexp/SuperlinearBackTracking.qll",
505-
"java/ql/lib/semmle/code/java/security/regexp/SuperlinearBackTracking.qll"
506-
],
507-
"RegexpMatching Python/JS/Ruby": [
508-
"javascript/ql/lib/semmle/javascript/security/regexp/RegexpMatching.qll",
509-
"python/ql/lib/semmle/python/security/regexp/RegexpMatching.qll",
510-
"ruby/ql/lib/codeql/ruby/security/regexp/RegexpMatching.qll"
511-
],
512-
"BadTagFilterQuery Python/JS/Ruby": [
513-
"javascript/ql/lib/semmle/javascript/security/BadTagFilterQuery.qll",
514-
"python/ql/lib/semmle/python/security/BadTagFilterQuery.qll",
515-
"ruby/ql/lib/codeql/ruby/security/BadTagFilterQuery.qll"
516-
],
517-
"OverlyLargeRange Python/JS/Ruby/Java": [
518-
"javascript/ql/lib/semmle/javascript/security/OverlyLargeRangeQuery.qll",
519-
"python/ql/lib/semmle/python/security/OverlyLargeRangeQuery.qll",
520-
"ruby/ql/lib/codeql/ruby/security/OverlyLargeRangeQuery.qll",
521-
"java/ql/lib/semmle/code/java/security/OverlyLargeRangeQuery.qll"
522-
],
523489
"CFG": [
524490
"csharp/ql/lib/semmle/code/csharp/controlflow/internal/ControlFlowGraphImplShared.qll",
525491
"ruby/ql/lib/codeql/ruby/controlflow/internal/ControlFlowGraphImplShared.qll",

cpp/autobuilder/Semmle.Autobuild.Cpp.Tests/Semmle.Autobuild.Cpp.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
<ItemGroup>
1212
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
1313
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
14-
<PackageReference Include="xunit" Version="2.4.1" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
14+
<PackageReference Include="xunit" Version="2.4.2" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1616
<PrivateAssets>all</PrivateAssets>
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
1818
</PackageReference>
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
1920
</ItemGroup>
2021

2122
<ItemGroup>

cpp/autobuilder/Semmle.Autobuild.Cpp/Semmle.Autobuild.Cpp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<PackageReference Include="Microsoft.Build" Version="16.11.0" />
20+
<PackageReference Include="Microsoft.Build" Version="17.3.2" />
2121
</ItemGroup>
2222

2323
<ItemGroup>

cpp/ql/lib/experimental/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 111 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ abstract class Configuration extends string {
147147
*/
148148
FlowFeature getAFeature() { none() }
149149

150+
/** Holds if sources should be grouped in the result of `hasFlowPath`. */
151+
predicate sourceGrouping(Node source, string sourceGroup) { none() }
152+
153+
/** Holds if sinks should be grouped in the result of `hasFlowPath`. */
154+
predicate sinkGrouping(Node sink, string sinkGroup) { none() }
155+
150156
/**
151157
* Holds if data may flow from `source` to `sink` for this configuration.
152158
*/
@@ -158,7 +164,7 @@ abstract class Configuration extends string {
158164
* The corresponding paths are generated from the end-points and the graph
159165
* included in the module `PathGraph`.
160166
*/
161-
predicate hasFlowPath(PathNode source, PathNode sink) { flowsTo(source, sink, _, _, this) }
167+
predicate hasFlowPath(PathNode source, PathNode sink) { hasFlowPath(source, sink, this) }
162168

163169
/**
164170
* Holds if data may flow from some source to `sink` for this configuration.
@@ -2712,6 +2718,18 @@ private newtype TPathNode =
27122718
state = sink.getState() and
27132719
config = sink.getConfiguration()
27142720
)
2721+
} or
2722+
TPathNodeSourceGroup(string sourceGroup, Configuration config) {
2723+
exists(PathNodeImpl source |
2724+
sourceGroup = source.getSourceGroup() and
2725+
config = source.getConfiguration()
2726+
)
2727+
} or
2728+
TPathNodeSinkGroup(string sinkGroup, Configuration config) {
2729+
exists(PathNodeSink sink |
2730+
sinkGroup = sink.getSinkGroup() and
2731+
config = sink.getConfiguration()
2732+
)
27152733
}
27162734

27172735
/**
@@ -2920,6 +2938,22 @@ abstract private class PathNodeImpl extends TPathNode {
29202938
)
29212939
}
29222940

2941+
string getSourceGroup() {
2942+
this.isSource() and
2943+
this.getConfiguration().sourceGrouping(this.getNodeEx().asNode(), result)
2944+
}
2945+
2946+
predicate isFlowSource() {
2947+
this.isSource() and not exists(this.getSourceGroup())
2948+
or
2949+
this instanceof PathNodeSourceGroup
2950+
}
2951+
2952+
predicate isFlowSink() {
2953+
this = any(PathNodeSink sink | not exists(sink.getSinkGroup())) or
2954+
this instanceof PathNodeSinkGroup
2955+
}
2956+
29232957
private string ppAp() {
29242958
this instanceof PathNodeSink and result = ""
29252959
or
@@ -2959,7 +2993,9 @@ abstract private class PathNodeImpl extends TPathNode {
29592993

29602994
/** Holds if `n` can reach a sink. */
29612995
private predicate directReach(PathNodeImpl n) {
2962-
n instanceof PathNodeSink or directReach(n.getANonHiddenSuccessor())
2996+
n instanceof PathNodeSink or
2997+
n instanceof PathNodeSinkGroup or
2998+
directReach(n.getANonHiddenSuccessor())
29632999
}
29643000

29653001
/** Holds if `n` can reach a sink or is used in a subpath that can reach a sink. */
@@ -3015,6 +3051,12 @@ class PathNode instanceof PathNodeImpl {
30153051

30163052
/** Holds if this node is a source. */
30173053
final predicate isSource() { super.isSource() }
3054+
3055+
/** Holds if this node is a grouping of source nodes. */
3056+
final predicate isSourceGroup(string group) { this = TPathNodeSourceGroup(group, _) }
3057+
3058+
/** Holds if this node is a grouping of sink nodes. */
3059+
final predicate isSinkGroup(string group) { this = TPathNodeSinkGroup(group, _) }
30183060
}
30193061

30203062
/**
@@ -3136,9 +3178,66 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
31363178

31373179
override Configuration getConfiguration() { result = config }
31383180

3139-
override PathNodeImpl getASuccessorImpl() { none() }
3181+
override PathNodeImpl getASuccessorImpl() {
3182+
result = TPathNodeSinkGroup(this.getSinkGroup(), config)
3183+
}
31403184

31413185
override predicate isSource() { sourceNode(node, state, config) }
3186+
3187+
string getSinkGroup() { config.sinkGrouping(node.asNode(), result) }
3188+
}
3189+
3190+
private class PathNodeSourceGroup extends PathNodeImpl, TPathNodeSourceGroup {
3191+
string sourceGroup;
3192+
Configuration config;
3193+
3194+
PathNodeSourceGroup() { this = TPathNodeSourceGroup(sourceGroup, config) }
3195+
3196+
override NodeEx getNodeEx() { none() }
3197+
3198+
override FlowState getState() { none() }
3199+
3200+
override Configuration getConfiguration() { result = config }
3201+
3202+
override PathNodeImpl getASuccessorImpl() {
3203+
result.getSourceGroup() = sourceGroup and
3204+
result.getConfiguration() = config
3205+
}
3206+
3207+
override predicate isSource() { none() }
3208+
3209+
override string toString() { result = sourceGroup }
3210+
3211+
override predicate hasLocationInfo(
3212+
string filepath, int startline, int startcolumn, int endline, int endcolumn
3213+
) {
3214+
filepath = "" and startline = 0 and startcolumn = 0 and endline = 0 and endcolumn = 0
3215+
}
3216+
}
3217+
3218+
private class PathNodeSinkGroup extends PathNodeImpl, TPathNodeSinkGroup {
3219+
string sinkGroup;
3220+
Configuration config;
3221+
3222+
PathNodeSinkGroup() { this = TPathNodeSinkGroup(sinkGroup, config) }
3223+
3224+
override NodeEx getNodeEx() { none() }
3225+
3226+
override FlowState getState() { none() }
3227+
3228+
override Configuration getConfiguration() { result = config }
3229+
3230+
override PathNodeImpl getASuccessorImpl() { none() }
3231+
3232+
override predicate isSource() { none() }
3233+
3234+
override string toString() { result = sinkGroup }
3235+
3236+
override predicate hasLocationInfo(
3237+
string filepath, int startline, int startcolumn, int endline, int endcolumn
3238+
) {
3239+
filepath = "" and startline = 0 and startcolumn = 0 and endline = 0 and endcolumn = 0
3240+
}
31423241
}
31433242

31443243
private predicate pathNode(
@@ -3495,6 +3594,15 @@ private module Subpaths {
34953594
* Will only have results if `configuration` has non-empty sources and
34963595
* sinks.
34973596
*/
3597+
private predicate hasFlowPath(
3598+
PathNodeImpl flowsource, PathNodeImpl flowsink, Configuration configuration
3599+
) {
3600+
flowsource.isFlowSource() and
3601+
flowsource.getConfiguration() = configuration and
3602+
(flowsource = flowsink or pathSuccPlus(flowsource, flowsink)) and
3603+
flowsink.isFlowSink()
3604+
}
3605+
34983606
private predicate flowsTo(
34993607
PathNodeImpl flowsource, PathNodeSink flowsink, Node source, Node sink,
35003608
Configuration configuration

0 commit comments

Comments
 (0)