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,10 +51,10 @@ jobs:
2951 fetch-depth : 0 # Full history for better pattern analysis
3052
3153 - name : Setup Elixir for Hypatia scanner
32- uses : erlef/setup-beam@e6d7c94229049569db56a7ad5a540c051a010af9 # v1.18.2
54+ uses : erlef/setup-beam@fc68ffb90438ef2936bbb3251622353b3dcb2f93 # v1.18.2
3355 with :
34- elixir-version : ' 1.19.4 '
35- otp-version : ' 28.3 '
56+ elixir-version : ' 1.18 '
57+ otp-version : ' 27 '
3658
3759 - name : Clone Hypatia
3860 run : |
@@ -41,22 +63,27 @@ jobs:
4163 fi
4264
4365 - name : Build Hypatia scanner (if needed)
44- working-directory : ${{ env.HOME }}/hypatia
4566 run : |
46- if [ ! -f hypatia-v2 ]; then
47- echo "Building hypatia-v2 scanner..."
67+ cd "$HOME/hypatia"
68+ if [ ! -f hypatia ]; then
69+ echo "Building hypatia scanner..."
4870 mix deps.get
4971 mix escript.build
50- mv hypatia ../hypatia-v2
5172 fi
5273
5374 - name : Run Hypatia scan
5475 id : scan
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 }}
5582 run : |
5683 echo "Scanning repository: ${{ github.repository }}"
5784
58- # Run scanner
59- HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . > hypatia-findings.json
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
6087
6188 # Count findings
6289 FINDING_COUNT=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0)
@@ -78,40 +105,235 @@ jobs:
78105 echo "- Medium: $MEDIUM" >> $GITHUB_STEP_SUMMARY
79106
80107 - name : Upload findings artifact
81- uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
108+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
82109 with :
83110 name : hypatia-findings
84111 path : hypatia-findings.json
85112 retention-days : 90
86113
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+
87251 - name : Submit findings to gitbot-fleet (Phase 2)
88252 if : steps.scan.outputs.findings_count > 0
253+ # Phase 2 is the collaborative LEARNING side-channel ("bots share
254+ # findings via gitbot-fleet"), not the security gate. The gate is
255+ # the baseline-aware "Check for critical or high-severity issues"
256+ # step below. A fleet-side regression (e.g. the submit script being
257+ # moved/removed) must NEVER hard-fail every consuming repo's scan.
258+ # Same reasoning as the "Comment on PR with findings" step.
259+ # See hyperpolymath/hypatia#213 (gate decoupling) and the exit-127
260+ # estate-wide breakage when gitbot-fleet/scripts/submit-finding.sh
261+ # no longer existed on the default branch.
262+ continue-on-error : true
89263 env :
264+ # All GitHub context values surface as env vars so the run
265+ # block never interpolates `${{ … }}` inline (closes the
266+ # workflow_audit/unsafe_curl_payload + actions_expression_injection
267+ # findings).
90268 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
269+ FLEET_PUSH_TOKEN : ${{ secrets.HYPATIA_DISPATCH_PAT }}
270+ FLEET_DISPATCH_TOKEN : ${{ secrets.HYPATIA_DISPATCH_PAT }}
91271 GITHUB_REPOSITORY : ${{ github.repository }}
92272 GITHUB_SHA : ${{ github.sha }}
273+ FINDINGS_COUNT : ${{ steps.scan.outputs.findings_count }}
93274 run : |
94- echo "📤 Submitting ${{ steps.scan.outputs.findings_count }} findings to gitbot-fleet..."
275+ echo "📤 Submitting $FINDINGS_COUNT findings to gitbot-fleet..."
95276
96- # Clone gitbot-fleet to temp directory
277+ # Clone gitbot-fleet to temp directory. A clone failure (network,
278+ # repo gone) is non-fatal: learning submission is best-effort.
97279 FLEET_DIR="/tmp/gitbot-fleet-$$"
98- git clone https://github.com/hyperpolymath/gitbot-fleet.git "$FLEET_DIR"
280+ if ! git clone --depth 1 https://github.com/hyperpolymath/gitbot-fleet.git "$FLEET_DIR"; then
281+ echo "::warning::Could not clone gitbot-fleet — skipping Phase 2 learning submission (non-fatal)."
282+ exit 0
283+ fi
284+
285+ # The submission script's location in gitbot-fleet has drifted
286+ # before (it was absent from the default branch, which exit-127'd
287+ # every consuming repo's scan). Probe known locations rather than
288+ # hard-coding one path, and skip gracefully if none is present.
289+ SUBMIT_SCRIPT=""
290+ for cand in \
291+ "$FLEET_DIR/scripts/submit-finding.sh" \
292+ "$FLEET_DIR/scripts/submit_finding.sh" \
293+ "$FLEET_DIR/bin/submit-finding.sh" \
294+ "$FLEET_DIR/submit-finding.sh"; do
295+ if [ -f "$cand" ]; then
296+ SUBMIT_SCRIPT="$cand"
297+ break
298+ fi
299+ done
300+
301+ if [ -z "$SUBMIT_SCRIPT" ]; then
302+ echo "::warning::gitbot-fleet submit-finding script not found at any known path — skipping Phase 2 learning submission (non-fatal). Findings are still uploaded as an artifact and gated below."
303+ rm -rf "$FLEET_DIR"
304+ exit 0
305+ fi
99306
100- # Run submission script
101- bash "$FLEET_DIR/scripts/submit-finding.sh" hypatia-findings.json
307+ # Run submission script. Pass the findings path as ABSOLUTE —
308+ # the script cd's into its own working dir before reading the
309+ # file, so a relative path would resolve to the wrong place.
310+ # A submission-script failure is logged but non-fatal.
311+ if bash "$SUBMIT_SCRIPT" "$GITHUB_WORKSPACE/hypatia-findings.json"; then
312+ echo "✅ Finding submission complete"
313+ else
314+ echo "::warning::gitbot-fleet submission script exited non-zero — Phase 2 learning submission skipped (non-fatal)."
315+ fi
102316
103317 # Cleanup
104318 rm -rf "$FLEET_DIR"
105319
106- echo "✅ Finding submission complete"
107-
108320 - name : Check for critical issues
109321 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`.
110333 run : |
111- echo "⚠️ Critical security issues found!"
112- echo "Review hypatia-findings.json for details"
113- # Don't fail the build yet - just warn
114- # 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."
115337
116338 - name : Generate scan report
117339 run : |
@@ -133,9 +355,14 @@ jobs:
133355
134356 ## Next Steps
135357
136- 1. Review findings in the artifact: hypatia-findings.json
137- 2. Auto-fixable issues will be addressed by robot-repo-automaton (Phase 3)
138- 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.
139366
140367 ## Learning
141368
@@ -149,6 +376,11 @@ jobs:
149376
150377 - name : Comment on PR with findings
151378 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
152384 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
153385 with :
154386 script : |
0 commit comments