1010 schedule :
1111 - cron : ' 0 0 * * 0' # Weekly on Sunday
1212 workflow_dispatch :
13+ # Estate guardrail: cancel superseded runs so re-pushes don't pile up
14+ # queued runs across the estate. Safe here because this workflow only
15+ # performs read-only checks/lint/test/scan with no publish or mutation.
16+ concurrency :
17+ group : ${{ github.workflow }}-${{ github.ref }}
18+ cancel-in-progress : true
1319
1420permissions :
1521 contents : read
16- # security-events: read lets the built-in GITHUB_TOKEN query this
17- # repo\'s own Dependabot alerts via the Hypatia DependabotAlerts rule.
18- security-events : read
22+ # security-events: write serves two purposes (write implies read):
23+ # 1. read — lets the built-in GITHUB_TOKEN query this repo's own
24+ # Dependabot alerts via the Hypatia DependabotAlerts rule
25+ # (DA001-DA004). Without read, `scan_from_path` gets HTTP 403
26+ # and the rule silently returns no findings.
27+ # See 007-lang/audits/audit-dependabot-automation-gap-2026-04-17.md.
28+ # 2. write — lets the "Upload SARIF to code scanning" step publish
29+ # Hypatia findings to the Security → Code scanning page so they
30+ # are triaged/deduplicated like CodeQL alerts instead of living
31+ # only in a build artifact nobody is required to look at.
32+ # See hyperpolymath/burble#35 (SARIF integration).
33+ # This is a single-job workflow, so job-level scoping would not
34+ # narrow the grant further; it stays workflow-level and documented.
35+ security-events : write
36+ # pull-requests: write lets the advisory "Comment on PR with findings"
37+ # step post its summary. Without it the built-in GITHUB_TOKEN gets
38+ # "Resource not accessible by integration" and (absent continue-on-error)
39+ # hard-fails the scan — exactly what the gate-decoupling design forbids.
40+ pull-requests : write
1941
2042jobs :
2143 scan :
@@ -29,55 +51,49 @@ jobs:
2951 fetch-depth : 0 # Full history for better pattern analysis
3052
3153 - name : Setup Elixir for Hypatia scanner
32- id : beam
33- continue-on-error : true
34- uses : erlef/setup-beam@e6d7c94229049569db56a7ad5a540c051a010af9 # v1.18.2
54+ uses : erlef/setup-beam@fc68ffb90438ef2936bbb3251622353b3dcb2f93 # v1.18.2
3555 with :
36- elixir-version : ' 1.19.4'
37- otp-version : ' 28.3'
38-
39- # Upstream hyperpolymath/hypatia was refactored to shell entrypoints;
40- # it no longer has a scanner/ subdir. Build the escript at the repo
41- # root only if no prebuilt binary exists, and never hard-fail on a
42- # missing/unbuildable scanner — mirrors the resilient pattern in
43- # static-analysis-gate.yml so a tooling outage cannot block merges.
44- - name : Clone and build Hypatia
45- id : build
46- continue-on-error : true
56+ elixir-version : ' 1.18'
57+ otp-version : ' 27'
58+
59+ - name : Clone Hypatia
4760 run : |
48- git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia" 2>/dev/null || true
49- if [ -f "$HOME/hypatia/mix.exs" ]; then
50- cd "$HOME/hypatia"
51- if [ ! -f hypatia ] && [ ! -f hypatia-v2 ]; then
52- mix deps.get
53- mix escript.build
54- fi
55- echo "ready=true" >> "$GITHUB_OUTPUT"
56- else
57- echo "::notice::Hypatia scanner not available — skipping scan"
58- echo "ready=false" >> "$GITHUB_OUTPUT"
61+ if [ ! -d "$HOME/hypatia" ]; then
62+ git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia"
63+ fi
64+
65+ - name : Build Hypatia scanner (if needed)
66+ run : |
67+ cd "$HOME/hypatia"
68+ if [ ! -f hypatia ]; then
69+ echo "Building hypatia scanner..."
70+ mix deps.get
71+ mix escript.build
5972 fi
6073
6174 - name : Run Hypatia scan
6275 id : scan
63- if : steps.build.outputs.ready == 'true'
76+ env :
77+ # Pass the built-in Actions token through to Hypatia so the
78+ # DependabotAlerts rule can query this repo's own alerts.
79+ # For cross-repo scanning (fleet-coordinator scan-supervised),
80+ # a PAT with `security_events` scope is required instead.
81+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
6482 run : |
6583 echo "Scanning repository: ${{ github.repository }}"
66- set +e
67- HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . > hypatia-findings.json 2>&1
68- set -e
6984
70- # Sanitize: ensure valid JSON array even if the scanner errored.
71- if [ ! -s hypatia-findings.json ] || ! jq empty hypatia-findings.json 2>/dev/null; then
72- echo "[]" > hypatia-findings.json
73- fi
85+ # Run scanner (exits non-zero when findings exist — suppress to continue)
86+ HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . --exit-zero > hypatia-findings.json || true
7487
88+ # Count findings
7589 FINDING_COUNT=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0)
76- CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json 2>/dev/null || echo 0)
77- HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json 2>/dev/null || echo 0)
78- MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json 2>/dev/null || echo 0)
79-
8090 echo "findings_count=$FINDING_COUNT" >> $GITHUB_OUTPUT
91+
92+ # Extract severity counts
93+ CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json)
94+ HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json)
95+ MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json)
96+
8197 echo "critical=$CRITICAL" >> $GITHUB_OUTPUT
8298 echo "high=$HIGH" >> $GITHUB_OUTPUT
8399 echo "medium=$MEDIUM" >> $GITHUB_OUTPUT
@@ -88,23 +104,150 @@ jobs:
88104 echo "- High: $HIGH" >> $GITHUB_STEP_SUMMARY
89105 echo "- Medium: $MEDIUM" >> $GITHUB_STEP_SUMMARY
90106
91- - name : Create stub findings (when Hypatia unavailable)
92- if : steps.build.outputs.ready != 'true'
93- run : |
94- echo "[]" > hypatia-findings.json
95- {
96- echo "## Hypatia Scan"
97- echo ""
98- echo "Skipped: Hypatia scanner not available in this environment."
99- } >> "$GITHUB_STEP_SUMMARY"
100-
101107 - name : Upload findings artifact
102- uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
108+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
103109 with :
104110 name : hypatia-findings
105111 path : hypatia-findings.json
106112 retention-days : 90
107113
114+ - name : Convert Hypatia findings to SARIF
115+ # Always runs (no findings_count guard): an EMPTY SARIF run is
116+ # valid and intentional — uploading it clears stale Hypatia
117+ # alerts from the code-scanning page when a repo goes clean.
118+ # The converter is dependency-free Node (Node ships on
119+ # ubuntu-latest; no npm install — estate npm ban respected) and
120+ # is hardened against the heterogeneous Hypatia JSON schema:
121+ # most findings are {rule_module,severity,type,file,reason,
122+ # action}; only some carry an integer `line`; `file` may be
123+ # empty or absolute. See lib/hypatia/cli.ex (collect_findings).
124+ run : |
125+ cat > "$RUNNER_TEMP/hypatia-sarif.cjs" <<'CJS'
126+ const fs = require('fs');
127+ const path = require('path');
128+ const crypto = require('crypto');
129+
130+ const ws = process.env.GITHUB_WORKSPACE || process.cwd();
131+
132+ let findings = [];
133+ try {
134+ const parsed = JSON.parse(fs.readFileSync('hypatia-findings.json', 'utf8'));
135+ if (Array.isArray(parsed)) findings = parsed;
136+ } catch (_) {
137+ // Scanner unavailable / empty / malformed -> empty SARIF.
138+ // Intentionally clears stale alerts rather than erroring.
139+ findings = [];
140+ }
141+
142+ // Mirrors Hypatia's own "github" annotation mapping
143+ // (lib/hypatia/cli.ex output/2): critical|high -> error,
144+ // medium -> warning, everything else -> note.
145+ const levelFor = (sev) => {
146+ switch (String(sev || '').toLowerCase()) {
147+ case 'critical':
148+ case 'high': return 'error';
149+ case 'medium': return 'warning';
150+ default: return 'note';
151+ }
152+ };
153+
154+ // SARIF artifactLocation.uri must be a repo-relative POSIX
155+ // path. Hypatia may emit absolute paths (scanned under
156+ // $GITHUB_WORKSPACE) or "" / "." for repo-level findings.
157+ const relUri = (file) => {
158+ if (!file) return '.';
159+ let f = String(file);
160+ if (path.isAbsolute(f)) {
161+ const rel = path.relative(ws, f);
162+ f = (rel && !rel.startsWith('..')) ? rel : path.basename(f);
163+ }
164+ f = f.replace(/\\/g, '/').replace(/^\.\//, '');
165+ return f || '.';
166+ };
167+
168+ const rules = new Map();
169+ const results = findings.map((f) => {
170+ const mod = String(f.rule_module || 'hypatia');
171+ const type = String(f.type || 'finding');
172+ const ruleId = `hypatia/${mod}/${type}`;
173+ const level = levelFor(f.severity);
174+ if (!rules.has(ruleId)) {
175+ rules.set(ruleId, {
176+ id: ruleId,
177+ name: `${mod}.${type}`,
178+ shortDescription: { text: `Hypatia ${mod}: ${type}` },
179+ defaultConfiguration: { level }
180+ });
181+ }
182+ const uri = relUri(f.file);
183+ const msg = String(f.reason || f.type || 'Hypatia finding');
184+ const startLine =
185+ Number.isInteger(f.line) && f.line > 0 ? f.line : 1;
186+ // Stable cross-run fingerprint for dedupe (no line, so a
187+ // moved finding in the same file/rule stays one alert).
188+ const fp = crypto
189+ .createHash('sha256')
190+ .update([ruleId, uri, type, msg].join('|'))
191+ .digest('hex');
192+ return {
193+ ruleId,
194+ level,
195+ message: { text: msg },
196+ locations: [
197+ {
198+ physicalLocation: {
199+ artifactLocation: { uri },
200+ region: { startLine }
201+ }
202+ }
203+ ],
204+ partialFingerprints: { 'hypatiaFindingHash/v1': fp }
205+ };
206+ });
207+
208+ const sarif = {
209+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
210+ version: '2.1.0',
211+ runs: [
212+ {
213+ tool: {
214+ driver: {
215+ name: 'Hypatia',
216+ informationUri: 'https://github.com/hyperpolymath/hypatia',
217+ rules: Array.from(rules.values())
218+ }
219+ },
220+ results
221+ }
222+ ]
223+ };
224+
225+ fs.writeFileSync('hypatia.sarif', JSON.stringify(sarif, null, 2));
226+ console.log(`hypatia.sarif written: ${results.length} result(s).`);
227+ CJS
228+ node "$RUNNER_TEMP/hypatia-sarif.cjs"
229+
230+ - name : Upload SARIF to GitHub code scanning
231+ # Fork PRs get a read-only GITHUB_TOKEN, so security-events:write
232+ # is unavailable and upload-sarif cannot publish — skip there
233+ # rather than hard-fail (the push/schedule run on the default
234+ # branch is the authoritative upload). Same-repo PRs and pushes
235+ # do upload. This step is deliberately NOT continue-on-error:
236+ # if the security-surface integration breaks we want a loud red,
237+ # not a silently-ungated scanner (the exact failure mode #35
238+ # exists to end). The empty-SARIF "clear stale alerts" path is
239+ # handled in the converter above and does not error here.
240+ if : >-
241+ always() &&
242+ (github.event_name != 'pull_request' ||
243+ github.event.pull_request.head.repo.fork != true)
244+ uses : github/codeql-action/upload-sarif@0d579ffd059c29b07949a3cce3983f0780820c98 # v3.28.1
245+ with :
246+ sarif_file : hypatia.sarif
247+ # Distinct category so Hypatia results coexist with CodeQL's
248+ # (codeql.yml) instead of overwriting them on the same surface.
249+ category : hypatia
250+
108251 - name : Submit findings to gitbot-fleet (Phase 2)
109252 if : steps.scan.outputs.findings_count > 0
110253 # Phase 2 is the collaborative LEARNING side-channel ("bots share
@@ -176,11 +319,21 @@ jobs:
176319
177320 - name : Check for critical issues
178321 if : steps.scan.outputs.critical > 0
322+ # GATING POLICY (explicit, by design — not an oversight):
323+ # Hypatia is ADVISORY here. Critical findings are surfaced
324+ # (step annotation + SARIF alert on the code-scanning page +
325+ # PR comment) but do NOT fail this check. Enforcement is
326+ # delegated to the code-scanning surface: tighten by adding a
327+ # branch-protection "required" status on the `hypatia` SARIF
328+ # category, not by reintroducing an `exit 1` here. This keeps
329+ # the gate decision in one auditable place (hypatia#213 gate
330+ # decoupling) and lets a repo opt into fail-on-critical without
331+ # editing this canonical workflow. To change the policy, change
332+ # branch protection — deliberately no commented-out `exit 1`.
179333 run : |
180- echo "⚠️ Critical security issues found!"
181- echo "Review hypatia-findings.json for details"
182- # Don't fail the build yet - just warn
183- # exit 1
334+ echo "::warning::Hypatia found critical security issue(s) — advisory."
335+ echo "See the Security → Code scanning page (category: hypatia)"
336+ echo "and the hypatia-findings.json artifact for details."
184337
185338 - name : Generate scan report
186339 run : |
@@ -202,9 +355,14 @@ jobs:
202355
203356 ## Next Steps
204357
205- 1. Review findings in the artifact: hypatia-findings.json
206- 2. Auto-fixable issues will be addressed by robot-repo-automaton (Phase 3)
207- 3. Manual review required for complex issues
358+ 1. Triage findings on the **Security → Code scanning** page
359+ (SARIF category \`hypatia\`) — dismiss/track them there like
360+ CodeQL alerts.
361+ 2. The full finding set is also attached as the
362+ \`hypatia-findings.json\` build artifact for offline review.
363+ 3. Findings are **advisory** today (surfaced, not gated); the
364+ gating policy is documented in the workflow's "Check for
365+ critical issues" step.
208366
209367 ## Learning
210368
@@ -218,6 +376,11 @@ jobs:
218376
219377 - name : Comment on PR with findings
220378 if : github.event_name == 'pull_request' && steps.scan.outputs.findings_count > 0
379+ # Advisory only — posting findings as a PR comment must never gate
380+ # the scan (hypatia#213 gate decoupling). Belt-and-braces alongside
381+ # the pull-requests: write permission above: a token/API hiccup or
382+ # a fork PR (read-only token) skips the comment, not the check.
383+ continue-on-error : true
221384 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
222385 with :
223386 script : |
0 commit comments