Skip to content

Security scan: resolve findings (2026-07-29) - #41

Merged
FlyOverCoderKY merged 4 commits into
mainfrom
claude/security-scan-fixes
Jul 30, 2026
Merged

FlyOverCoderKY merged 4 commits into
mainfrom
claude/security-scan-fixes

Conversation

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor

Works docs/securityscan.md (2026-07-29 scan: 0 critical, 0 high, 0 medium, 4 low). Every finding was re-checked against the code before deciding; two are real and fixed, two do not hold up in this repository and are disputed with reasoning recorded in the report.

Fixed

[LOW] Missing HTTP Strict-Transport-Security — added
Strict-Transport-Security: max-age=63072000; includeSubDomains; preload to the /* block in public/_headers. www.pegma.dev already serves HTTPS and 301s to the apex, so includeSubDomains is safe today. New src/security-headers.test.ts parses _headers and asserts the whole static header set, so losing any of them fails CI. Two operator actions stay outside this repo: enabling HSTS zone-wide so Worker /api/* responses carry it, and submitting the apex to hstspreload.org.

[LOW] Webhook replay: delivery ID unsigned, no body-hash binding — GitHub's HMAC covers the body only, so x-github-delivery (the @pegma/webhooks ledger dedup key) was unauthenticated input: a previously valid signed body could be re-presented under a fresh delivery GUID and re-apply a stale projection. New worker/src/github-webhook-body-binding.ts binds the SHA-256 of the signed bytes to the first delivery id that carried them with insertIfAbsent, and handleGitHubReleaseWebhook refuses the same bytes under a different id with 409 duplicate_body before the ledger or any projection runs. The claim is race-free rather than a read-then-write check. A failed delivery releases its binding, because GitHub does not auto-retry and operator redelivery must still work. Documented in worker/README.md.

Disputed

[LOW] Access-Control-Allow-Origin: * on static HTML responses — not a valid finding. The header grants cross-origin script reads of bytes already served to anonymous clients and published from a public repository, so it discloses nothing. Nothing on the Pages origin is credentialed, and without Access-Control-Allow-Credentials: true a browser will not attach the __Host- session cookie to a cross-origin read regardless of ACAO. The credentialed surface is /api/* on the Worker, which sends no ACAO (asserted in releases-api.test.ts:177). The finding's own exploitability note says "no practical impact" and calls the fix optional.

[LOW] Public health endpoint discloses versions and ops timing — not a valid finding. The version strings are hardcoded literals in worker/src/index.ts inside a public repo whose package.json pins the same versions, so the endpoint reveals nothing an attacker cannot read from source, and being literals it is not even evidence of what is deployed. The site publishes those versions deliberately: /api/releases and the Stack page are a public feed of every @pegma/* release. The ops timing is already public too — /api/releases returns the same reconciliation instant as observedAt (both 2026-07-30T00:00:05.178Z when probed), and the cron cadence is in the public worker/wrangler.jsonc. datadog and emailDelivery are configuration booleans with no secret values, and @pegma/health defines check detail as "booleans and names, never secrets". The finding's alternative remedy — document the public contract — is already met in worker/README.md. Gating a liveness probe behind sessions would add D1 reads and make it fail for the monitors it exists for.

Also reviewed, no change

The report's "Unverified / Needs Manual Review" note about email-code verify endpoints using composedEmailRecovery instead of readyEmailRecovery (worker/src/identity-api.ts:608,648) holds no exploit path: code handles are minted only by the begin endpoints, which are gated on emailCodeReady, so with delivery disabled a caller would have to guess both an opaque handle and its 8-digit code. In-flight codes surviving a config toggle is the sensible behavior.

Checks

npm run check, npm test (194 tests across both Vitest suites), and npm run build all pass locally. Note that deploy.yml publishes Pages only, so the HSTS header ships on merge while the webhook change reaches production on the next npm run worker:deploy.

🤖 Generated with Claude Code

FlyOverCoderKY and others added 3 commits July 29, 2026 20:30
The Pages response carried CSP, COOP, Permissions-Policy, Referrer-Policy,
and nosniff but no Strict-Transport-Security, so a first-ever plain-HTTP
visit was strippable. Add the header to the /* block with a two-year
max-age; www.pegma.dev already serves HTTPS and 301s to the apex, so
includeSubDomains costs nothing today.

src/security-headers.test.ts parses public/_headers and asserts the whole
set, so dropping any of these headers fails CI rather than a later scan.
Enabling HSTS zone-wide (so Worker /api/* responses carry it) and
submitting the apex to hstspreload.org remain dashboard actions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
GitHub's HMAC covers the request body and nothing else, so
x-github-delivery — the @pegma/webhooks ledger dedup key — was
unauthenticated input. Anyone holding a previously valid signed body could
re-present it under a fresh delivery GUID, walk past dedup, and re-apply a
stale projection until six-hour reconciliation restored GitHub's state.

Move dedup onto data the signature actually covers: bind the SHA-256 of the
signed bytes to the first delivery id that carried them and refuse the same
bytes under a different id with 409 duplicate_body, before the ledger or any
projection runs. The claim is an insertIfAbsent rather than a
read-then-write check, so two concurrent deliveries cannot both win it.

A delivery that fails releases its binding, because GitHub does not
auto-retry and operator redelivery must still run. Release failure only
costs replay detection for one body, so it stays a logged non-event like the
existing health-marker write.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Each of the four Low findings now carries an explicit outcome, so a later
reader knows the scan was worked rather than filed.

Resolved: missing HSTS, and the unsigned webhook dedup key.

Disputed: Access-Control-Allow-Origin on static HTML, because the bytes are
already anonymous and the origin holds nothing credentialed — no ACAO can
attach the __Host- cookie without allow-credentials, and /api/* sends no
ACAO. Also the public health detail, because the version strings are
hardcoded literals in a public repo that pins the same versions, the site
publishes those releases on purpose through /api/releases, and that endpoint
already exposes the same reconciliation instant the finding treats as
sensitive.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 30, 2026 00:31
@cursor

cursor Bot commented Jul 30, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@github-actions

github-actions Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Grok Grok Build Review — no issues

Review complete. No issues found — the changes look solid.

This change correctly remediates the two substantiated Low findings and documents sound rejections of the other two. The HSTS header is added at the static origin with a regression test that pins the broader security-header set. The webhook body-hash binding is placed after authentication and allowlisting, claims with insertIfAbsent, refuses cross-delivery replays before ledger or projection work, and retains the claim through failure so GitHub same-id redelivery remains viable. The implementation, tests, and in-repo documentation are consistent and production-appropriate for this reference environment.

Reviewed commit 7667ad1 · workflow run

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Resolves (and documents dispositions for) low-severity security-scan findings by hardening static response headers on the Pages site and adding replay protection for GitHub release webhooks handled by the Worker.

Changes:

  • Add HSTS to Cloudflare Pages public/_headers and introduce a test that parses _headers to prevent header regressions.
  • Prevent replay of previously signed GitHub webhook bodies under a fresh X-GitHub-Delivery by binding a body hash to the first delivery id that carried it, with unit/integration tests.
  • Update Worker documentation and docs/securityscan.md with fix/dispute dispositions and rationale.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
worker/src/github-webhook-body-binding.ts Adds body-hash binding storage + helpers to detect/reject replayed signed bodies.
worker/src/github-webhook-body-binding.test.ts Tests hashing, binding/replay detection, and release behavior.
worker/src/github-release-webhook.ts Enforces the body-binding check before ledger/projection work; releases binding on processing failure.
worker/src/github-release-webhook.test.ts Adds coverage for body replay rejection and failure/redelivery behavior.
worker/README.md Documents the replay protection behavior and failure/redelivery semantics.
src/security-headers.test.ts Parses public/_headers and asserts HSTS + baseline static security headers.
public/_headers Adds Strict-Transport-Security header to the /* rule.
docs/securityscan.md Records scan dispositions, including resolutions and disputes with reasoning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread worker/src/github-release-webhook.ts Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grok Grok Build Review

The HSTS addition is correct, CI-enforced, and appropriately limited to the Pages surface. The signed-body binding is the right control for unauthenticated delivery IDs on the success path, and the disputed findings are documented with defensible repository-specific reasoning. The failure path is not: releasing the body claim after a processing error is unnecessary for GitHub redelivery and re-opens the exact cross-delivery-id replay window this change claims to close, including after a projection write has already landed.

🐞 1 bugs · ⚠️ 0 warnings · 🤏 0 nits

Reviewed commit e9e0957 · workflow run

Comment thread worker/src/github-release-webhook.ts Resolved
Review caught that releasing the claim on failure re-opened the replay it
exists to refuse: if a later step threw after applyReleaseProjection had
already landed, the catch block dropped the binding, and the same signed
bytes could then be claimed by a fresh delivery GUID and re-enter projection.

The release was never needed. GitHub's X-GitHub-Delivery identifies the
event, not the attempt, so it is constant across redeliveries — a retry of a
failed delivery presents the same id and bindSignedWebhookBody already
reports it as bound. Drop releaseSignedWebhookBody entirely and let the claim
be permanent, which also answers the retention question: expiring a claim
would be granting permission to replay that body later, and growth is one
small row per distinct signed body, the same rate as the @pegma/webhooks
receipt beside it.

The failed-delivery test now asserts what the control actually promises: a
different delivery id still gets 409 while the redelivery under the original
id reaches 204.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@FlyOverCoderKY
FlyOverCoderKY merged commit 136a8c6 into main Jul 30, 2026
2 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the claude/security-scan-fixes branch July 30, 2026 00:45
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.

2 participants