Skip to content

Commit bf888f0

Browse files
committed
Merge remote-tracking branch 'upstream/main' into incomplete-url-string-sanitization
Conflicts: config/identical-files.json javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitization.ql javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitization.qll ruby/ql/src/queries/security/cwe-020/IncompleteUrlSubstringSanitization.qll
2 parents f95e1ef + 117fb5b commit bf888f0

File tree

1,308 files changed

+77783
-53595
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,308 files changed

+77783
-53595
lines changed

.github/workflows/check-qldoc.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: "Check QLdoc coverage"
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- "*/ql/lib/**"
7+
- .github/workflows/check-qldoc.yml
8+
branches:
9+
- main
10+
- "rc/*"
11+
12+
jobs:
13+
qldoc:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Install CodeQL
18+
run: |
19+
gh extension install github/gh-codeql
20+
gh codeql set-channel nightly
21+
gh codeql version
22+
env:
23+
GITHUB_TOKEN: ${{ github.token }}
24+
25+
- uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 2
28+
29+
- name: Check QLdoc coverage
30+
shell: bash
31+
run: |
32+
EXIT_CODE=0
33+
changed_lib_packs="$(git diff --name-only --diff-filter=ACMRT HEAD^ HEAD | { grep -o '^[a-z]*/ql/lib' || true; } | sort -u)"
34+
for pack_dir in ${changed_lib_packs}; do
35+
lang="${pack_dir%/ql/lib}"
36+
gh codeql generate library-doc-coverage --output="${RUNNER_TEMP}/${lang}-current.txt" --dir="${pack_dir}"
37+
done
38+
git checkout HEAD^
39+
for pack_dir in ${changed_lib_packs}; do
40+
lang="${pack_dir%/ql/lib}"
41+
gh codeql generate library-doc-coverage --output="${RUNNER_TEMP}/${lang}-baseline.txt" --dir="${pack_dir}"
42+
awk -F, '{gsub(/"/,""); if ($4==0 && $6=="public") print "\""$3"\"" }' "${RUNNER_TEMP}/${lang}-current.txt" | sort -u > "${RUNNER_TEMP}/current-undocumented.txt"
43+
awk -F, '{gsub(/"/,""); if ($4==0 && $6=="public") print "\""$3"\"" }' "${RUNNER_TEMP}/${lang}-baseline.txt" | sort -u > "${RUNNER_TEMP}/baseline-undocumented.txt"
44+
UNDOCUMENTED="$(grep -f <(comm -13 "${RUNNER_TEMP}/baseline-undocumented.txt" "${RUNNER_TEMP}/current-undocumented.txt") "${RUNNER_TEMP}/${lang}-current.txt" || true)"
45+
if [ -n "$UNDOCUMENTED" ]; then
46+
echo "$UNDOCUMENTED" | awk -F, '{gsub(/"/,""); print "::warning file='"${pack_dir}"'/"$1",line="$2"::Missing QLdoc for "$5, $3 }'
47+
EXIT_CODE=1
48+
fi
49+
done
50+
exit "${EXIT_CODE}"

config/blame-deprecations.mjs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import cp from "child_process";
4+
function* walk(dir) {
5+
for (const file of fs.readdirSync(dir)) {
6+
const filePath = path.join(dir, file);
7+
if (fs.statSync(filePath).isDirectory()) {
8+
yield* walk(filePath);
9+
} else {
10+
yield filePath;
11+
}
12+
}
13+
}
14+
15+
function* deprecatedFiles(dir) {
16+
for (const file of walk(dir)) {
17+
if (file.endsWith(".ql") || file.endsWith(".qll")) {
18+
const contents = fs.readFileSync(file, "utf8");
19+
if (/\sdeprecated\s/.test(contents)) {
20+
yield file;
21+
}
22+
}
23+
}
24+
}
25+
26+
const blameRegExp =
27+
/^(\^?\w+)\s.+\s+(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (?:\+|-)\d{4})\s+(\d+)\).*$/;
28+
29+
function* deprecationMessages(dir) {
30+
for (const file of deprecatedFiles(dir)) {
31+
const blame = cp.execFileSync("git", ["blame", "--", file]);
32+
const lines = blame.toString().split("\n");
33+
for (let i = 0; i < lines.length; i++) {
34+
const line = lines[i];
35+
if (line.includes(" deprecated ")) {
36+
try {
37+
const [_, sha, time, lineNumber] = line.match(blameRegExp);
38+
const date = new Date(time);
39+
// check if it's within the last 14 months (a year, plus 2 months for safety, in case a PR was delayed)
40+
if (date.getTime() >= Date.now() - 14 * 31 * 24 * 60 * 60 * 1000) {
41+
continue;
42+
}
43+
const message = `${file}:${lineNumber} was last updated on ${date.getFullYear()}-${date.getMonth()}-${date.getDate()}`;
44+
yield [message, date];
45+
} catch (e) {
46+
console.log(e);
47+
console.log("----");
48+
console.log(line);
49+
console.log("----");
50+
process.exit(0);
51+
}
52+
}
53+
}
54+
}
55+
}
56+
[...deprecationMessages(".")]
57+
.sort((a, b) => a[1].getTime() - b[1].getTime())
58+
.forEach((msg) => console.log(msg[0]));

config/identical-files.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@
7373
"java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll",
7474
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/SsaReadPositionCommon.qll"
7575
],
76+
"Model as Data Generation Java/C# - Utils": [
77+
"java/ql/src/utils/model-generator/ModelGeneratorUtils.qll",
78+
"csharp/ql/src/utils/model-generator/ModelGeneratorUtils.qll"
79+
],
80+
"Model as Data Generation Java/C# - SummaryModels": [
81+
"java/ql/src/utils/model-generator/CaptureSummaryModels.qll",
82+
"csharp/ql/src/utils/model-generator/CaptureSummaryModels.qll"
83+
],
7684
"Sign Java/C#": [
7785
"java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/Sign.qll",
7886
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/Sign.qll"
@@ -426,7 +434,6 @@
426434
"python/ql/src/Lexical/CommentedOutCodeMetricOverview.inc.qhelp"
427435
],
428436
"FLinesOfDuplicatedCodeCommon.inc.qhelp": [
429-
"cpp/ql/src/Metrics/Files/FLinesOfDuplicatedCodeCommon.inc.qhelp",
430437
"java/ql/src/Metrics/Files/FLinesOfDuplicatedCodeCommon.inc.qhelp",
431438
"javascript/ql/src/Metrics/FLinesOfDuplicatedCodeCommon.inc.qhelp",
432439
"python/ql/src/Metrics/FLinesOfDuplicatedCodeCommon.inc.qhelp"
@@ -512,5 +519,13 @@
512519
"IncompleteUrlSubstringSanitization": [
513520
"javascript/ql/src/Security/CWE-020/IncompleteUrlSubstringSanitization.qll",
514521
"ruby/ql/src/queries/security/cwe-020/IncompleteUrlSubstringSanitization.qll"
522+
],
523+
"Hostname Regexp queries": [
524+
"javascript/ql/src/Security/CWE-020/HostnameRegexpShared.qll",
525+
"ruby/ql/src/queries/security/cwe-020/HostnameRegexpShared.qll"
526+
],
527+
"ApiGraphModels": [
528+
"javascript/ql/lib/semmle/javascript/frameworks/data/internal/ApiGraphModels.qll",
529+
"ruby/ql/lib/codeql/ruby/frameworks/data/internal/ApiGraphModels.qll"
515530
]
516531
}

0 commit comments

Comments
 (0)