11# SPDX-License-Identifier: MPL-2.0
2- # Hypatia Neurosymbolic CI/CD Security Scan
2+ # Thin wrapper around hyperpolymath/standards hypatia-scan-reusable.yml.
3+ # See standards#191 for the reusable's purpose and design.
4+
35name : Hypatia Security Scan
46
57on :
68 push :
7- branches : [ main, master, develop ]
9+ branches : [main, master, develop]
810 pull_request :
9- branches : [ main, master ]
11+ branches : [main, master]
1012 schedule :
11- - cron : ' 0 0 * * 0' # Weekly on Sunday
13+ - cron : ' 0 0 * * 0'
1214 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.
15+
16+ # Estate guardrail: cancel superseded runs so re-pushes don't pile up.
1617concurrency :
1718 group : ${{ github.workflow }}-${{ github.ref }}
1819 cancel-in-progress : true
1920
2021permissions :
2122 contents : read
22- # security-events: read lets the built-in GITHUB_TOKEN query this
23- # repo's own Dependabot alerts via the Hypatia DependabotAlerts rule
24- # (DA001-DA004). Without this, `scan_from_path` gets HTTP 403 and
25- # the rule silently returns no findings.
26- # See 007-lang/audits/audit-dependabot-automation-gap-2026-04-17.md.
27- security-events : read
28- # pull-requests: write lets the advisory "Comment on PR with findings"
29- # step post its summary. Without it the built-in GITHUB_TOKEN gets
30- # "Resource not accessible by integration" and (absent continue-on-error)
31- # hard-fails the scan — exactly what the gate-decoupling design forbids.
23+ security-events : write
3224 pull-requests : write
3325
3426jobs :
35- scan :
36- name : Hypatia Neurosymbolic Analysis
37- runs-on : ubuntu-latest
38-
39- steps :
40- - name : Checkout repository
41- uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
42- with :
43- fetch-depth : 0 # Full history for better pattern analysis
44-
45- - name : Setup Elixir for Hypatia scanner
46- uses : erlef/setup-beam@fc68ffb90438ef2936bbb3251622353b3dcb2f93 # v1.18.2
47- with :
48- elixir-version : ' 1.19.4'
49- otp-version : ' 28.3'
50-
51- - name : Clone Hypatia
52- run : |
53- if [ ! -d "$HOME/hypatia" ]; then
54- git clone https://github.com/hyperpolymath/hypatia.git "$HOME/hypatia"
55- fi
56-
57- - name : Build Hypatia scanner (if needed)
58- run : |
59- cd "$HOME/hypatia"
60- if [ ! -f hypatia ]; then
61- echo "Building hypatia scanner..."
62- mix deps.get
63- mix escript.build
64- fi
65-
66- - name : Run Hypatia scan
67- id : scan
68- env :
69- # Pass the built-in Actions token through to Hypatia so the
70- # DependabotAlerts rule can query this repo's own alerts.
71- # For cross-repo scanning (fleet-coordinator scan-supervised),
72- # a PAT with `security_events` scope is required instead.
73- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
74- run : |
75- echo "Scanning repository: ${{ github.repository }}"
76-
77- # Run scanner (exits non-zero when findings exist — suppress to continue)
78- HYPATIA_FORMAT=json "$HOME/hypatia/hypatia-cli.sh" scan . --exit-zero > hypatia-findings.json || true
79-
80- # Count findings
81- FINDING_COUNT=$(jq '. | length' hypatia-findings.json 2>/dev/null || echo 0)
82- echo "findings_count=$FINDING_COUNT" >> $GITHUB_OUTPUT
83-
84- # Extract severity counts
85- CRITICAL=$(jq '[.[] | select(.severity == "critical")] | length' hypatia-findings.json)
86- HIGH=$(jq '[.[] | select(.severity == "high")] | length' hypatia-findings.json)
87- MEDIUM=$(jq '[.[] | select(.severity == "medium")] | length' hypatia-findings.json)
88-
89- echo "critical=$CRITICAL" >> $GITHUB_OUTPUT
90- echo "high=$HIGH" >> $GITHUB_OUTPUT
91- echo "medium=$MEDIUM" >> $GITHUB_OUTPUT
92-
93- echo "## Hypatia Scan Results" >> $GITHUB_STEP_SUMMARY
94- echo "- Total findings: $FINDING_COUNT" >> $GITHUB_STEP_SUMMARY
95- echo "- Critical: $CRITICAL" >> $GITHUB_STEP_SUMMARY
96- echo "- High: $HIGH" >> $GITHUB_STEP_SUMMARY
97- echo "- Medium: $MEDIUM" >> $GITHUB_STEP_SUMMARY
98-
99- - name : Upload findings artifact
100- uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
101- with :
102- name : hypatia-findings
103- path : hypatia-findings.json
104- retention-days : 90
105-
106- - name : Submit findings to gitbot-fleet (Phase 2)
107- if : steps.scan.outputs.findings_count > 0
108- # Phase 2 is the collaborative LEARNING side-channel ("bots share
109- # findings via gitbot-fleet"), not the security gate. The gate is
110- # the baseline-aware "Check for critical or high-severity issues"
111- # step below. A fleet-side regression (e.g. the submit script being
112- # moved/removed) must NEVER hard-fail every consuming repo's scan.
113- # Same reasoning as the "Comment on PR with findings" step.
114- # See hyperpolymath/hypatia#213 (gate decoupling) and the exit-127
115- # estate-wide breakage when gitbot-fleet/scripts/submit-finding.sh
116- # no longer existed on the default branch.
117- continue-on-error : true
118- env :
119- # All GitHub context values surface as env vars so the run
120- # block never interpolates `${{ … }}` inline (closes the
121- # workflow_audit/unsafe_curl_payload + actions_expression_injection
122- # findings).
123- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
124- FLEET_PUSH_TOKEN : ${{ secrets.HYPATIA_DISPATCH_PAT }}
125- FLEET_DISPATCH_TOKEN : ${{ secrets.HYPATIA_DISPATCH_PAT }}
126- GITHUB_REPOSITORY : ${{ github.repository }}
127- GITHUB_SHA : ${{ github.sha }}
128- FINDINGS_COUNT : ${{ steps.scan.outputs.findings_count }}
129- run : |
130- echo "📤 Submitting $FINDINGS_COUNT findings to gitbot-fleet..."
131-
132- # Clone gitbot-fleet to temp directory. A clone failure (network,
133- # repo gone) is non-fatal: learning submission is best-effort.
134- FLEET_DIR="/tmp/gitbot-fleet-$$"
135- if ! git clone --depth 1 https://github.com/hyperpolymath/gitbot-fleet.git "$FLEET_DIR"; then
136- echo "::warning::Could not clone gitbot-fleet — skipping Phase 2 learning submission (non-fatal)."
137- exit 0
138- fi
139-
140- # The submission script's location in gitbot-fleet has drifted
141- # before (it was absent from the default branch, which exit-127'd
142- # every consuming repo's scan). Probe known locations rather than
143- # hard-coding one path, and skip gracefully if none is present.
144- SUBMIT_SCRIPT=""
145- for cand in \
146- "$FLEET_DIR/scripts/submit-finding.sh" \
147- "$FLEET_DIR/scripts/submit_finding.sh" \
148- "$FLEET_DIR/bin/submit-finding.sh" \
149- "$FLEET_DIR/submit-finding.sh"; do
150- if [ -f "$cand" ]; then
151- SUBMIT_SCRIPT="$cand"
152- break
153- fi
154- done
155-
156- if [ -z "$SUBMIT_SCRIPT" ]; then
157- 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."
158- rm -rf "$FLEET_DIR"
159- exit 0
160- fi
161-
162- # Run submission script. Pass the findings path as ABSOLUTE —
163- # the script cd's into its own working dir before reading the
164- # file, so a relative path would resolve to the wrong place.
165- # A submission-script failure is logged but non-fatal.
166- if bash "$SUBMIT_SCRIPT" "$GITHUB_WORKSPACE/hypatia-findings.json"; then
167- echo "✅ Finding submission complete"
168- else
169- echo "::warning::gitbot-fleet submission script exited non-zero — Phase 2 learning submission skipped (non-fatal)."
170- fi
171-
172- # Cleanup
173- rm -rf "$FLEET_DIR"
174-
175- - name : Check for critical issues
176- if : steps.scan.outputs.critical > 0
177- run : |
178- echo "⚠️ Critical security issues found!"
179- echo "Review hypatia-findings.json for details"
180- # Don't fail the build yet - just warn
181- # exit 1
182-
183- - name : Generate scan report
184- run : |
185- cat << EOF > hypatia-report.md
186- # Hypatia Security Scan Report
187-
188- **Repository:** ${{ github.repository }}
189- **Scan Date:** $(date -u +"%Y-%m-%d %H:%M:%S UTC")
190- **Commit:** ${{ github.sha }}
191-
192- ## Summary
193-
194- | Severity | Count |
195- |----------|-------|
196- | Critical | ${{ steps.scan.outputs.critical }} |
197- | High | ${{ steps.scan.outputs.high }} |
198- | Medium | ${{ steps.scan.outputs.medium }} |
199- | **Total**| ${{ steps.scan.outputs.findings_count }} |
200-
201- ## Next Steps
202-
203- 1. Review findings in the artifact: hypatia-findings.json
204- 2. Auto-fixable issues will be addressed by robot-repo-automaton (Phase 3)
205- 3. Manual review required for complex issues
206-
207- ## Learning
208-
209- These findings feed Hypatia's learning engine to improve future rules.
210-
211- ---
212- *Powered by [Hypatia](https://github.com/hyperpolymath/hypatia) - Neurosymbolic CI/CD Intelligence*
213- EOF
214-
215- cat hypatia-report.md >> $GITHUB_STEP_SUMMARY
216-
217- - name : Comment on PR with findings
218- if : github.event_name == 'pull_request' && steps.scan.outputs.findings_count > 0
219- # Advisory only — posting findings as a PR comment must never gate
220- # the scan (hypatia#213 gate decoupling). Belt-and-braces alongside
221- # the pull-requests: write permission above: a token/API hiccup or
222- # a fork PR (read-only token) skips the comment, not the check.
223- continue-on-error : true
224- uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v7
225- with :
226- script : |
227- const fs = require('fs');
228- const findings = JSON.parse(fs.readFileSync('hypatia-findings.json', 'utf8'));
229-
230- const critical = findings.filter(f => f.severity === 'critical').length;
231- const high = findings.filter(f => f.severity === 'high').length;
232-
233- let comment = `## 🔍 Hypatia Security Scan\n\n`;
234- comment += `**Findings:** ${findings.length} issues detected\n\n`;
235- comment += `| Severity | Count |\n|----------|-------|\n`;
236- comment += `| 🔴 Critical | ${critical} |\n`;
237- comment += `| 🟠 High | ${high} |\n`;
238- comment += `| 🟡 Medium | ${findings.length - critical - high} |\n\n`;
239-
240- if (critical > 0) {
241- comment += `⚠️ **Action Required:** Critical security issues found!\n\n`;
242- }
243-
244- comment += `<details><summary>View findings</summary>\n\n`;
245- comment += `\`\`\`json\n${JSON.stringify(findings.slice(0, 10), null, 2)}\n\`\`\`\n`;
246- comment += `</details>\n\n`;
247- comment += `*Powered by Hypatia Neurosymbolic CI/CD Intelligence*`;
248-
249- github.rest.issues.createComment({
250- owner: context.repo.owner,
251- repo: context.repo.repo,
252- issue_number: context.issue.number,
253- body: comment
254- });
27+ hypatia :
28+ uses : hyperpolymath/standards/.github/workflows/hypatia-scan-reusable.yml@97df762107501909f50bb770e9bc200b6c415600
29+ secrets : inherit
0 commit comments