Skip to content

Commit da367c8

Browse files
authored
Merge branch 'main' into releases
2 parents fd64708 + 00ea65f commit da367c8

File tree

1,451 files changed

+58069
-728
lines changed

Some content is hidden

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

1,451 files changed

+58069
-728
lines changed

.devcontainer/bootstrap.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Installing GH Extensions..."
5+
gh extensions install GitHubSecurityLab/gh-mrva
6+
gh extensions install advanced-security/gh-codeql-scan
7+
8+
echo "Installing stubs..."
9+
chmod +x .devcontainer/scripts/* && cp -r .devcontainer/scripts/* /usr/local/bin/
10+
11+
# Clone an instance of the CodeQL repository
12+
# https://github.com/github/codeql/tree/codeql-cli/latest
13+
echo "Cloning CodeQL repository..."
14+
if [ ! -d "./codeql" ]; then
15+
git clone \
16+
--branch codeql-cli/latest \
17+
https://github.com/github/codeql ./codeql
18+
fi

.devcontainer/devcontainer.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
{
22
"name": "CodeQL-Community-Packs",
3+
"postAttachCommand": ".devcontainer/bootstrap.sh",
4+
"hostRequirements": {
5+
"storage": "32gb",
6+
"memory": "16gb",
7+
"cpus": 4
8+
},
39
"extensions": [
410
"github.vscode-codeql",
5-
"github.copilot"
11+
"github.copilot",
12+
"MS-vsliveshare.vsliveshare",
13+
"lostintangent.github-security-alerts",
14+
"ms-vscode.test-adapter-converter",
15+
"ms-vscode.cpptools",
16+
"ms-dotnettools.vscode-dotnet-runtime",
17+
"ms-python.vscode-pylance",
18+
"redhat.java",
619
],
720
"settings": {
21+
"codeQL.canary": true,
822
"codeQL.runningQueries.autoSave": true,
923
"codeQL.runningQueries.numberOfThreads": 4,
1024
"codeQL.runningQueries.debug": true,
1125
"editor.formatOnSave": true
1226
},
1327
"postCreateCommand": "git submodule init && git submodule update --recursive",
14-
"remoteUser": "root"
15-
}
28+
"remoteUser": "root",
29+
"customizations": {
30+
"codespaces": {
31+
"repositories": {
32+
"github/gh-codeql": {
33+
"permissions": {
34+
"contents": "read"
35+
}
36+
},
37+
"github/codeql": {
38+
"permissions": {
39+
"contents": "read"
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}

.devcontainer/scripts/codeql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
CODEQL_PATH=/home/root/.vscode-remote/data/User/globalStorage/github.vscode-codeql/distribution1/codeql/codeql
5+
6+
if [ ! -f $CODEQL_PATH ]; then
7+
echo "CodeQL not found. Please install the CodeQL extension in VSCode and try again."
8+
exit 1
9+
fi
10+
11+
$CODEQL_PATH $@

.devcontainer/scripts/codeql-scan

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
gh codeql-scan $@

.github/scripts/pr-tests.sh

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/build.yml renamed to .github/workflows/ci.yml

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
workflow_dispatch:
77

88
jobs:
9-
compile:
9+
compile-and-test:
1010
runs-on: ubuntu-latest
1111

1212
strategy:
@@ -55,9 +55,61 @@ jobs:
5555
- name: Test Queries
5656
if: steps.changes.outputs.src == 'true'
5757
env:
58-
GITHUB_TOKEN: ${{ github.token }}
58+
RUNNER_TEMP: ${{ runner.temp }}
59+
shell: python
5960
run: |
60-
./.github/scripts/pr-tests.sh ${{ github.event.number }} ${{ matrix.language }}
61+
import os
62+
import sys
63+
import subprocess
64+
from pathlib import Path
65+
66+
def print_error(fmt, *args):
67+
print(f"::error::{fmt}", *args)
68+
69+
def print_error_and_fail(fmt, *args):
70+
print_error(fmt, args)
71+
sys.exit(1)
72+
73+
runner_temp = os.environ['RUNNER_TEMP']
74+
75+
test_root = Path('${{ github.workspace }}', '${{ matrix.language }}', 'test')
76+
print(f"Executing tests found (recursively) in the directory '{test_root}'")
77+
files_to_close = []
78+
try:
79+
# Runners have 4 cores, so split the tests into 4 "slices", and run one per thread
80+
num_slices = 4
81+
procs = []
82+
83+
for slice in range(1, num_slices+1):
84+
test_report_path = os.path.join(runner_temp, "${{ matrix.language }}", f"test_report_slice_{slice}_of_{num_slices}.json")
85+
os.makedirs(os.path.dirname(test_report_path), exist_ok=True)
86+
test_report_file = open(test_report_path, 'w')
87+
files_to_close.append(test_report_file)
88+
procs.append(subprocess.Popen(["codeql", "test", "run", "--failing-exitcode=122", f"--slice={slice}/{num_slices}", "--ram=2048", "--format=json", test_root], stdout=test_report_file, stderr=subprocess.PIPE))
89+
90+
for p in procs:
91+
_, err = p.communicate()
92+
if p.returncode != 0:
93+
if p.returncode == 122:
94+
# Failed because a test case failed, so just print the regular output.
95+
# This will allow us to proceed to validate-test-results, which will fail if
96+
# any test cases failed
97+
print(f"{err.decode()}")
98+
else:
99+
# Some more serious problem occurred, so print and fail fast
100+
print_error_and_fail(f"Failed to run tests with return code {p.returncode}\n{err.decode()}")
101+
finally:
102+
for file in files_to_close:
103+
file.close()
104+
105+
- name: Upload test results
106+
if: steps.changes.outputs.src == 'true'
107+
uses: actions/upload-artifact@v4
108+
with:
109+
name: ${{ matrix.language }}-test-results
110+
path: |
111+
${{ runner.temp }}/${{ matrix.language }}/test_report_slice_*.json
112+
if-no-files-found: error
61113

62114
- name: Compile / Check Suites & Packs
63115
if: steps.changes.outputs.src == 'true'
@@ -66,6 +118,39 @@ jobs:
66118
run: |
67119
./.github/scripts/pr-suites-packs.sh ${{ github.event.number }} ${{ matrix.language }}
68120
121+
validate-test-results:
122+
name: Validate test results
123+
needs: compile-and-test
124+
runs-on: ubuntu-latest
125+
steps:
126+
- name: Check if compile-and-test job failed to complete, if so fail
127+
if: ${{ needs.compile-and-test.result == 'failure' }}
128+
uses: actions/github-script@v3
129+
with:
130+
script: |
131+
core.setFailed('Test run job failed')
132+
133+
- name: Collect test results
134+
uses: actions/download-artifact@v4
135+
136+
- name: Validate test results
137+
run: |
138+
if [[ ! -n "$(find . -name 'test_report_*' -print -quit)" ]]; then
139+
echo "No test results found"
140+
exit 0
141+
fi
142+
143+
for json_report in *-test-results/test_report_*
144+
do
145+
jq --raw-output '"PASS \(map(select(.pass == true)) | length)/\(length)'" $json_report\"" "$json_report"
146+
done
147+
FAILING_TESTS=$(jq --raw-output '.[] | select(.pass == false)' *-test-results/test_report_*.json)
148+
if [[ ! -z "$FAILING_TESTS" ]]; then
149+
echo "ERROR: The following tests failed:"
150+
echo $FAILING_TESTS | jq .
151+
exit 1
152+
fi
153+
69154
extensions:
70155
runs-on: ubuntu-latest
71156

@@ -143,7 +228,7 @@ jobs:
143228
144229
configs:
145230
runs-on: ubuntu-latest
146-
needs: compile
231+
needs: compile-and-test
147232

148233
steps:
149234
- uses: actions/checkout@v3

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*.actual
1010
*.class
1111
*/*.class
12+
# Cloned repository of codeql
13+
/codeql
1214

1315
# Test files / folders
1416
test.ql

configs/synthetics.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ paths-ignore:
104104
- "vendor/**"
105105
- "examples/**"
106106
- "tests/**"
107+
- "site-packages/**"
107108

108109
# JavaScript
109110
- "node_modules"
@@ -114,3 +115,12 @@ paths-ignore:
114115
- "dist"
115116
- "CoverageResults"
116117
- "**/wwwroot/lib/**"
118+
- "**/deps/**"
119+
- "**/third_party/**"
120+
121+
# Ruby
122+
- "**/gems/**"
123+
- "**/spec/**/*_spec.rb"
124+
- "**/test/**/*_test.rb"
125+
126+

csharp/lib/codeql-pack.lock.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
lockVersion: 1.0.0
33
dependencies:
44
codeql/controlflow:
5-
version: 0.0.3
5+
version: 1.0.10
66
codeql/csharp-all:
7-
version: 0.7.4
7+
version: 3.0.1
88
codeql/dataflow:
9-
version: 0.0.3
9+
version: 1.1.4
1010
codeql/mad:
11-
version: 0.1.4
11+
version: 1.0.10
1212
codeql/ssa:
13-
version: 0.1.4
13+
version: 1.0.10
14+
codeql/threat-models:
15+
version: 1.0.10
1416
codeql/tutorial:
15-
version: 0.1.4
17+
version: 1.0.10
18+
codeql/typetracking:
19+
version: 1.0.10
1620
codeql/util:
17-
version: 0.1.4
21+
version: 1.0.10
22+
codeql/xml:
23+
version: 1.0.10
1824
compiled: false

csharp/lib/ghsl/Cryptography.qll

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module Cryptography {
3636
class CryptoRfc2898DeriveBytes extends HashingAlgorithms {
3737
CryptoRfc2898DeriveBytes() {
3838
exists(ObjectCreation object |
39-
object.getType().getQualifiedName() = "System.Security.Cryptography.Rfc2898DeriveBytes" and
39+
object.getType().hasFullyQualifiedName("System.Security.Cryptography", "Rfc2898DeriveBytes") and
4040
this.asExpr() = object
4141
)
4242
}
@@ -67,7 +67,7 @@ module Cryptography {
6767
exists(ObjectCreation object |
6868
object
6969
.getType()
70-
.hasQualifiedName("System.Security.Cryptography", "DSACryptoServiceProvider") and
70+
.hasFullyQualifiedName("System.Security.Cryptography", "DSACryptoServiceProvider") and
7171
this.asExpr() = object
7272
)
7373
}
@@ -90,7 +90,7 @@ module Cryptography {
9090
exists(ObjectCreation object |
9191
object
9292
.getType()
93-
.hasQualifiedName("System.Security.Cryptography", "RC2CryptoServiceProvider") and
93+
.hasFullyQualifiedName("System.Security.Cryptography", "RC2CryptoServiceProvider") and
9494
this.asExpr() = object
9595
)
9696
}
@@ -113,12 +113,13 @@ module Cryptography {
113113
exists(ObjectCreation object |
114114
object
115115
.getType()
116-
.hasQualifiedName("System.Security.Cryptography", ["RSACryptoServiceProvider", "RSACng"]) and
116+
.hasFullyQualifiedName("System.Security.Cryptography",
117+
["RSACryptoServiceProvider", "RSACng"]) and
117118
this.asExpr() = object
118119
)
119120
or
120121
exists(MethodCall call |
121-
call.getType().hasQualifiedName("System.Security.Cryptography", ["RSA"]) and
122+
call.getType().hasFullyQualifiedName("System.Security.Cryptography", ["RSA"]) and
122123
call.getTarget().hasName("Create") and
123124
this.asExpr() = call
124125
)
@@ -152,7 +153,7 @@ module Cryptography {
152153
exists(ObjectCreation object |
153154
object
154155
.getType()
155-
.hasQualifiedName("System.Security.Cryptography",
156+
.hasFullyQualifiedName("System.Security.Cryptography",
156157
["HMACMD5", "HMACSHA1", "HMACSHA256", "HMACSHA384", "HMACSHA512", "HMACRIPEMD160"]) and
157158
this.asExpr() = object
158159
)

0 commit comments

Comments
 (0)