Skip to content

feat: reusable security gate as a composite action - #13

Open
VincentJerico wants to merge 1 commit into
mainfrom
feat/reusable-security-gate
Open

VincentJerico wants to merge 1 commit into
mainfrom
feat/reusable-security-gate

Conversation

@VincentJerico

Copy link
Copy Markdown
Owner

What & why

Third of three security-automation PRs. The header and error-page checks only ever tested Juice Shop. This packages them as a composite action other repos can call: uses: VincentJerico/security-testing/gate@<sha>.

Why a composite action and not a reusable workflow: a reusable workflow runs on a fresh runner, so it would have to start the caller's app from a command string passed in as an input. A composite action runs inside the caller's own job, after the caller has started its app the usual way, and github.action_path gives it exactly the pinned commit's code.

  • gate/action.yml:
    • Runs gate/check.ts in a pinned node:22.23.4-slim container (--network host), so the caller's Node version is untouched.
    • Optionally runs ZAP's passive baseline with the caller's rules.conf. A crash counts as a scan error, the same fix as in feat: nightly drift watch with a security-drift issue #12.
    • Inputs reach the shell only through env.
  • gate/check.ts: goes through the existing target guard (localhost only, before any request). It checks each policy route's headers with the existing checkHeaders policy and requests a probe route that doesn't exist to look for a stack trace.
  • gate/policy.ts:
    • What the caller lists: routes, the probe, and accepted findings, each with a reason.
    • What fails: findings nobody accepted, and accepted findings that no longer happen (stale). That's the same principle as the pinned tests here.
    • Validation: a policy with a missing reason or an unknown route is refused.
  • gate/examples/juice-shop.policy.json: S-1 to S-5 accepted, with references to docs/FINDINGS.md.
  • tsconfig.json: allowImportingTsExtensions, so check.ts runs as plain node (Node 22 strips the types). No new dependencies.
  • README: new "Reusable security gate" section with usage.

Proof it can fail

  • tests/gate.selftest.spec.ts, 8 passed locally:
    • Policy logic: accepted, unaccepted, stale and invalid policies.
    • Against the live Juice Shop: the real policy passes ("0 not accepted, 0 stale"). An empty policy fails with NEW /: Content-Security-Policy is missing and the S-5 stack trace. An acceptance for a problem Juice Shop doesn't have fails as STALE.
    • Target guard: https://example.com is refused.
  • New CI job gate-selftest: uses ./gate the way a caller would. Juice Shop's policy plus ZAP rules must pass. A run with tests/fixtures/gate-accepts-nothing.policy.json must fail, and the job checks that it did.
  • Local checks: full suite 37 passed. Lint, format and typecheck pass. actionlint reports no issues.

First caller: TaskFlow

Run locally against TaskFlow main (e9012be), Vincent's own app:

  • No security headers: TaskFlow sends none of the five headers on /, /health or /api/tasks, so the gate reports 15 findings.
  • Error page: its 404 doesn't leak a stack trace.
  • Version leak: it also sends X-Powered-By: Express.

Wiring the gate into TaskFlow's CI (and fixing the headers, e.g. with helmet) is for the TaskFlow session. I'm handing it the findings and a ready-to-use policy.

🤖 Generated with Claude Code

gate/action.yml runs the header policy and a stack-trace probe (in a
node:22 container) against an app on localhost in the calling job, plus
an optional ZAP baseline. A policy file lists routes and accepted
findings with reasons; unaccepted findings and stale acceptances fail.
CI runs it against Juice Shop: its policy must pass, an empty one must
fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant