Skip to content

fix: wire validateTaskPayload into POST /github-webhook (closes #139) - #149

Open
Whiznificent wants to merge 1 commit into
Vero-protocol:mainfrom
Whiznificent:fix/wire-validator-into-webhook
Open

fix: wire validateTaskPayload into POST /github-webhook (closes #139)#149
Whiznificent wants to merge 1 commit into
Vero-protocol:mainfrom
Whiznificent:fix/wire-validator-into-webhook

Conversation

@Whiznificent

Copy link
Copy Markdown
Contributor

closes #139

Summary

Wire the existing validateTaskPayload middleware into POST /github-webhook so that signature-valid but structurally invalid payloads are rejected with a 400 response before reaching the idempotency dedupe or queue layer.

Changes

  • index.js: Import validateTaskPayload and insert it into the /github-webhook Express middleware chain between verifySignature and idempotencyMiddleware. Replaced the previous single-line comment with a block that documents the full chain (rate-limit → signature verify → payload validate → idempotency dedupe → handler) and explains why validation comes before idempotency (malformed payloads get a consistent 400 each time instead of being silently cached as seen keys that later surface as confusing 409s). Added a one-line note on /internal/webhooks/replay explaining that route is intentionally unvalidated because it reads already-validated payloads from the raw event store.
  • test/webhook.test.js: Two new integration tests.
    • github webhook rejects signature-valid but structurally invalid payloads with 400 — sends a body with a valid HMAC signature but pull_request.number set to a string instead of an integer and asserts the 400 + structured details response.
    • github webhook rejects payloads with unknown top-level keys (injection guard) — sends a body with an extra top-level property (evilProperty) and asserts the strict-schema rejection surfaces in the response details.

Verification

node --test test/validator.test.js test/webhook.test.js

35 pass, 1 fail — the failing test is a pre-existing flake in this dev environment (default enforceIdempotency needs Redis at runtime) that also fails on main without my changes. Out of scope for #139; tracked separately.

Notes

  • Pure-additive wiring: no behavior change for valid signatures with well-formed payloads.
  • /internal/webhooks/replay is intentionally not affected; payloads there come from the pre-validated raw event store.
  • No new dependencies; uses the existing zod-based validator.

…protocol#139)

The strict zod-based TaskPayload validator already exists in src/middleware/validator.js but had no callers. This change wires it into the /github-webhook middleware chain between verifySignature and idempotencyMiddleware so that signature-valid but structurally invalid payloads (wrong types, unknown top-level keys) are rejected with a 400 response before reaching the idempotency dedupe or queue layer.

Two new integration tests in test/webhook.test.js cover the end-to-end rejection path:
- signature-valid but structurally invalid (non-integer PR number) -> 400
- signature-valid payload with an unknown top-level key -> 400 (injection guard)

The /internal/webhooks/replay endpoint intentionally remains unvalidated; it reads already-validated payloads from the raw event store by Idempotency-Key.
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.

fix: wire existing payload validator into POST /github-webhook

1 participant