Skip to content

Commit 732aad7

Browse files
authored
ci(security): add advisory CodeQL, secret-scan and Dependabot (#37)
1 parent 5a1af98 commit 732aad7

3 files changed

Lines changed: 212 additions & 0 deletions

File tree

‎.github/dependabot.yml‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# ADVISORY - version-update PRs only; nothing here is a required check.
2+
# Weekly, with minor and patch bumps grouped into one PR per ecosystem so the queue stays
3+
# reviewable. Major bumps arrive as their own PRs on purpose: they are the ones that break.
4+
version: 2
5+
updates:
6+
- package-ecosystem: npm
7+
directories:
8+
- "/"
9+
- "/packages/contracts"
10+
- "/packages/defaults/hallucination-hal-local"
11+
- "/packages/defaults/identity-erc8004-viem"
12+
schedule:
13+
interval: weekly
14+
day: monday
15+
time: "06:37"
16+
timezone: Etc/UTC
17+
open-pull-requests-limit: 5
18+
groups:
19+
npm-minor-patch:
20+
update-types:
21+
- minor
22+
- patch
23+
- package-ecosystem: github-actions
24+
directory: "/"
25+
schedule:
26+
interval: weekly
27+
day: monday
28+
time: "06:37"
29+
timezone: Etc/UTC
30+
open-pull-requests-limit: 5
31+
groups:
32+
actions-minor-patch:
33+
update-types:
34+
- minor
35+
- patch

‎.github/workflows/codeql.yml‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: CodeQL
2+
3+
# ADVISORY - not a required check. Static analysis of the JavaScript/TypeScript in this repo;
4+
# findings land in Security -> Code scanning. CodeQL is free on public repositories.
5+
#
6+
# Scope, stated plainly: only `javascript-typescript` is analysed. Any Rust, Solidity or Python
7+
# in this repository is NOT covered by this workflow.
8+
#
9+
# `build-mode: none` - JS/TS needs no build, so this cannot go red on a toolchain problem.
10+
#
11+
# `pull_request` has no `branches:` filter on purpose: a stacked PR (base is another feature
12+
# branch, not `main`) would otherwise never run this workflow at all, and a check that does not
13+
# run looks identical to a check that passed.
14+
15+
on:
16+
push:
17+
branches: [main]
18+
pull_request:
19+
schedule:
20+
- cron: '17 8 * * 3' # weekly; off the hour so it does not queue with every other schedule
21+
22+
permissions:
23+
contents: read
24+
25+
concurrency:
26+
group: codeql-${{ github.ref }}
27+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
28+
29+
jobs:
30+
analyze:
31+
name: Analyze (javascript-typescript)
32+
runs-on: ubuntu-latest
33+
timeout-minutes: 30
34+
permissions:
35+
security-events: write
36+
contents: read
37+
actions: read
38+
steps:
39+
- name: Check out
40+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
41+
with:
42+
persist-credentials: false
43+
44+
- name: Initialize CodeQL
45+
uses: github/codeql-action/init@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
46+
with:
47+
languages: javascript-typescript
48+
build-mode: none
49+
50+
- name: Analyze
51+
uses: github/codeql-action/analyze@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
52+
with:
53+
category: /language:javascript-typescript

‎.github/workflows/secret-scan.yml‎

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: secret-scan
2+
3+
# ADVISORY - not a required check. Fails the run if a commit this push/PR ADDS contains a secret.
4+
#
5+
# Runs the gitleaks binary directly instead of gitleaks/gitleaks-action, which needs a
6+
# GITLEAKS_LICENSE secret on organisation-owned repos. The binary needs no secret at all, so
7+
# this job cannot go red for a missing licence. The tarball is verified against a pinned
8+
# SHA-256 before it is unpacked (bump version and hash together; the hash is published in the
9+
# release's gitleaks_<version>_checksums.txt).
10+
#
11+
# --redact is deliberate and must stay: this repository is PUBLIC and so are its Actions logs,
12+
# so a finding must be reported by rule, file and line and never echoed.
13+
#
14+
# Scope, stated plainly: this scans the COMMITS IN THIS PUSH/PR RANGE. It answers "did this
15+
# change add a secret?" and is blind to anything committed before it existed. It reports
16+
# NOT_CHECKED (a warning, not a pass) if the range holds no commits.
17+
18+
on:
19+
push:
20+
branches: ['**']
21+
pull_request:
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
gitleaks:
28+
name: gitleaks
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 10
31+
steps:
32+
- name: Check out full history
33+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
34+
with:
35+
fetch-depth: 0
36+
persist-credentials: false
37+
38+
- name: Install gitleaks (checksum-pinned)
39+
env:
40+
GITLEAKS_VERSION: 8.30.1
41+
GITLEAKS_SHA256: 551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb
42+
run: |
43+
set -euo pipefail
44+
curl -sSfL --retry 3 -o "$RUNNER_TEMP/gitleaks.tar.gz" \
45+
"https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz"
46+
echo "${GITLEAKS_SHA256} $RUNNER_TEMP/gitleaks.tar.gz" | sha256sum -c -
47+
tar -xzf "$RUNNER_TEMP/gitleaks.tar.gz" -C "$RUNNER_TEMP" gitleaks
48+
"$RUNNER_TEMP/gitleaks" version
49+
50+
- name: Scan the commits this event adds
51+
env:
52+
EVENT_NAME: ${{ github.event_name }}
53+
PR_BASE: ${{ github.event.pull_request.base.sha }}
54+
PR_HEAD: ${{ github.event.pull_request.head.sha }}
55+
PUSH_BEFORE: ${{ github.event.before }}
56+
PUSH_AFTER: ${{ github.sha }}
57+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
58+
run: |
59+
set -euo pipefail
60+
zero=0000000000000000000000000000000000000000
61+
62+
# Work out WHICH commits this event adds.
63+
if [ "$EVENT_NAME" = "pull_request" ]; then
64+
range=("${PR_BASE}..${PR_HEAD}")
65+
elif [ "$PUSH_BEFORE" = "$zero" ]; then
66+
# New branch: everything not already on the default branch.
67+
range=("$PUSH_AFTER" --not "origin/${DEFAULT_BRANCH}")
68+
elif git cat-file -e "${PUSH_BEFORE}^{commit}" 2>/dev/null; then
69+
range=("${PUSH_BEFORE}..${PUSH_AFTER}")
70+
else
71+
# Force-push: the old tip is not in this clone, so scan the new tip only.
72+
range=(-1 "$PUSH_AFTER")
73+
fi
74+
75+
in_range=$(git rev-list --count "${range[@]}")
76+
echo "range: ${range[*]} (${in_range} commit(s) in range)"
77+
78+
# --exit-code 2 = leaks found. A gitleaks crash exits 1, so "found a secret" and
79+
# "the scanner broke" are different codes; both leave the job red.
80+
report="$RUNNER_TEMP/gitleaks-report.json"
81+
log="$RUNNER_TEMP/gitleaks.log"
82+
rc=0
83+
"$RUNNER_TEMP/gitleaks" git . \
84+
--log-opts="${range[*]}" \
85+
--redact --no-banner --no-color --exit-code 2 \
86+
--report-format json --report-path "$report" 2>&1 | tee "$log" || rc=$?
87+
88+
# Take the count from gitleaks itself, not from `git rev-list`. gitleaks diffs
89+
# commits, and a merge commit has no diff, so a range of only merge commits has a
90+
# non-zero rev-list count and 0 commits scanned. Reporting the first as the second
91+
# is how a scan "passes" over nothing.
92+
scanned=$(grep -oE '[0-9]+ commits? scanned' "$log" | head -n1 | grep -oE '^[0-9]+' || true)
93+
94+
if [ "$rc" = "2" ]; then
95+
{
96+
echo "### secret-scan: FAILED - secret(s) found"
97+
echo "${scanned:-?} commit(s) scanned. Values are redacted; rule, file and line only:"
98+
echo
99+
jq -r 'def s: gsub("[\r\n%]"; ""); .[] | "- `\(.RuleID|s)` at `\(.File|s):\(.StartLine)` in \(.Commit[0:8]|s)"' "$report"
100+
} >> "$GITHUB_STEP_SUMMARY"
101+
jq -r 'def s: gsub("[\r\n%]"; ""); .[] | "::error file=\(.File|s),line=\(.StartLine),title=gitleaks \(.RuleID|s)::possible secret (redacted) in commit \(.Commit[0:8]|s)"' "$report"
102+
echo "FAILED: gitleaks reported finding(s); see the summary for rule, file and line"
103+
exit 1
104+
fi
105+
106+
if [ "$rc" != "0" ]; then
107+
echo "FAILED: gitleaks exited ${rc}, which is a scanner error and not a finding"
108+
exit 1
109+
fi
110+
111+
if [ -z "$scanned" ] || [ "$scanned" = "0" ]; then
112+
echo "::warning title=secret-scan NOT_CHECKED::gitleaks scanned ${scanned:-an unreported number of} commits in range (${range[*]}); nothing was verified"
113+
{
114+
echo "### secret-scan: NOT_CHECKED"
115+
echo "gitleaks reported ${scanned:-no} commits scanned for \`${range[*]}\` (${in_range} in range). No findings, but nothing was verified either."
116+
} >> "$GITHUB_STEP_SUMMARY"
117+
exit 0
118+
fi
119+
120+
{
121+
echo "### secret-scan: VERIFIED"
122+
echo "${scanned} commit(s) scanned (\`${range[*]}\`), 0 findings."
123+
} >> "$GITHUB_STEP_SUMMARY"
124+
echo "VERIFIED: ${scanned} commit(s) scanned, 0 findings"

0 commit comments

Comments
 (0)