mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
edf10769ac
Comprehensive CI/CD security hardening pass over all 33 workflows. Action pinning - Every `uses:` is now pinned to a 40-char commit SHA with a `# vX.Y.Z` comment alongside (167 occurrences resolved). Tag-style refs like `@v4` are mutable and have been used in past supply-chain attacks (e.g. tj-actions/changed-files in March 2025) to repoint widely-used actions to malicious commits. - Removed redundant `version: "10.13.1"` hardcodes from `pnpm/action-setup` call sites so the action inherits from package.json `packageManager` (one source of truth). Automated maintenance - Added `.github/dependabot.yml` for the `github-actions` ecosystem so SHA pins stay current. Without this, pins go stale fast and new upstream advisories never reach us. Minor/patch bumps are grouped; major bumps stay separate so they get a real review. Static analysis - Added `.github/zizmor.yml` configuration and `.github/workflows/security_zizmor.yml` (blocking on PR, runs on push to main, weekly schedule for advisory drift). zizmor catches the well-known classes of Actions footguns: template injection from untrusted input, dangerous triggers, unpinned uses, excessive token scopes, secret exfil patterns. - All 28 high-severity and 54 medium-severity findings from the baseline scan are remediated. Each suppression in zizmor.yml carries a per-finding justification comment so future maintainers can audit the trust assumption. Workflow hardening (from zizmor + manual audit) - Added `persist-credentials: false` to every `actions/checkout` except the 7 workflows that legitimately push back to the repo via the workflow token (release tagging, auto-formatting, docs-sync, registry updates). Each retained credential persistence carries a `persist-credentials required: ...` comment explaining the call site. - Routed every attacker-controllable expansion (`github.head_ref`, `github.event.pull_request.head.repo.full_name`, `inputs.*`, step outputs) through `env:` and referenced as quoted shell variables. Eliminates 17 template-injection vectors in fork-PR-reachable workflows. - Added per-job `permissions:` blocks across 14 workflows; demoted broad workflow-level `id-token: write` to the specific Depot-runner jobs that need it; narrowed `pull-requests: write` / `actions: write` to the jobs that actually call those APIs. Audit-driven fixes - `publish-release.yml` build job: dropped `token:` and added `persist-credentials: false`. The subsequent `Upload workspace` step was packing `.git/config` (with the persisted GITHUB_TOKEN) into a 1-day-retention artifact downloadable by anyone with `actions:read`. - `auto_merge_showcases.yml`: team-membership check now authorizes on the PR AUTHOR (`pull_request.user.login`), never `context.actor` — the actor is whoever triggered the latest event, so a team member synchronizing or reopening an outsider's PR would otherwise green-light auto-merge of code they didn't author. - `static_quality.yml`: pinned ruff to a specific version so a compromised release can't land on the next PR run with the persisted-credentials write token in the format job. - `showcase_capture-previews.yml`: switched the args-string construction to a bash array so a slug or demo value containing whitespace or shell metacharacters stays a single argument rather than being re-tokenized by the shell.
107 lines
4.3 KiB
YAML
107 lines
4.3 KiB
YAML
name: "Security: Fork PR Alert"
|
|
|
|
on:
|
|
pull_request:
|
|
types: [opened, synchronize, closed, reopened]
|
|
|
|
permissions:
|
|
pull-requests: write
|
|
contents: read
|
|
|
|
jobs:
|
|
fork-pr-monitor:
|
|
if: github.event.pull_request.head.repo.full_name != github.repository
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Check for suspicious patterns
|
|
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
|
|
with:
|
|
script: |
|
|
const pr = context.payload.pull_request;
|
|
const alerts = [];
|
|
|
|
// 1. Check for [skip ci] in commit messages from fork PRs
|
|
if (context.payload.action === 'opened' || context.payload.action === 'synchronize') {
|
|
const commits = await github.rest.pulls.listCommits({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: pr.number,
|
|
per_page: 100
|
|
});
|
|
|
|
const skipCiCommits = commits.data.filter(c =>
|
|
/\[skip ci\]|\[ci skip\]|\[no ci\]/i.test(c.commit.message)
|
|
);
|
|
|
|
if (skipCiCommits.length > 0) {
|
|
alerts.push(`⚠️ **[skip ci] detected in fork PR** — ${skipCiCommits.length} commit(s) contain CI skip directives. Commits: ${skipCiCommits.map(c => c.sha.substring(0, 7)).join(', ')}`);
|
|
}
|
|
}
|
|
|
|
// 2. Check for force-push that reduces changed files to 0 (evidence cleanup)
|
|
if (context.payload.action === 'synchronize') {
|
|
const prDetails = await github.rest.pulls.get({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: pr.number
|
|
});
|
|
|
|
if (prDetails.data.changed_files === 0) {
|
|
alerts.push(`🚨 **Zero-file fork PR after force-push** — PR was force-pushed to show 0 changed files. This matches the TanStack attack cleanup pattern.`);
|
|
}
|
|
}
|
|
|
|
// 3. Check for rapid open-then-close (PR used only to trigger CI)
|
|
if (context.payload.action === 'closed' && !pr.merged) {
|
|
const created = new Date(pr.created_at);
|
|
const closed = new Date(pr.closed_at);
|
|
const minutesOpen = (closed - created) / (1000 * 60);
|
|
|
|
if (minutesOpen < 30) {
|
|
alerts.push(`🚨 **Fork PR closed rapidly** — opened and closed within ${Math.round(minutesOpen)} minutes without merging. May indicate a CI-trigger-only attack.`);
|
|
}
|
|
}
|
|
|
|
// 4. Check for large bundled files (>5000 lines) added by the PR
|
|
if (context.payload.action === 'opened' || context.payload.action === 'synchronize') {
|
|
const files = await github.rest.pulls.listFiles({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
pull_number: pr.number,
|
|
per_page: 100
|
|
});
|
|
|
|
const largeNewFiles = files.data.filter(f =>
|
|
f.status === 'added' && f.additions > 5000
|
|
);
|
|
|
|
if (largeNewFiles.length > 0) {
|
|
alerts.push(`⚠️ **Large files added by fork PR** — ${largeNewFiles.map(f => '`' + f.filename + '` (' + f.additions + ' lines)').join(', ')}. Bundled payloads are a common supply-chain attack vector.`);
|
|
}
|
|
}
|
|
|
|
// Report alerts
|
|
if (alerts.length > 0) {
|
|
const body = [
|
|
'## 🔒 Supply Chain Security Alert',
|
|
'',
|
|
'This fork PR triggered the following security alerts:',
|
|
'',
|
|
alerts.join('\n\n'),
|
|
'',
|
|
'---',
|
|
'_Automated by supply-chain security monitor. See [TanStack incident](https://socket.dev/blog/tanstack-npm-packages-compromised-mini-shai-hulud-supply-chain-attack) for context._'
|
|
].join('\n');
|
|
|
|
// Post as PR comment
|
|
await github.rest.issues.createComment({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
issue_number: pr.number,
|
|
body: body
|
|
});
|
|
|
|
// Also set the action as failed annotation
|
|
core.warning(alerts.join(' | '));
|
|
}
|