Skip to content

fix(review-gate): sanitize Idempotency-Key to API-allowed charset#48

Merged
isadeks merged 1 commit into
linear-vercelfrom
fix/review-gate-idempotency-key
Jul 15, 2026
Merged

fix(review-gate): sanitize Idempotency-Key to API-allowed charset#48
isadeks merged 1 commit into
linear-vercelfrom
fix/review-gate-idempotency-key

Conversation

@isadeks

@isadeks isadeks commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Bug

Caught while wiring up the gate live on the fork. The Task API validates Idempotency-Key against ^[a-zA-Z0-9_-]{1,128}$ (cdk/src/handlers/shared/validation.ts:46), but the gate built the key as review-$REPO-$PR_NUMBER-$HEAD_SHA where $REPO is owner/repo. The / fails the pattern (and owner/repo + a 40-char SHA also blows past 128 chars), so on a green PR the webhook returned 400 VALIDATION_ERROR and no review was ever triggered. The failing/pending/conflict/behind paths were unaffected (they don't POST).

Fix

Sanitize the key just before the POST — map every disallowed char to - and cap at 128. Still per-(repo, PR, SHA) unique, so the server-side idempotency backstop behaves identically.

IDEMPOTENCY_KEY="$(printf 'review-%s-%s-%s' "$REPO" "$PR_NUMBER" "$HEAD_SHA" \
  | tr -c 'a-zA-Z0-9_-' '-' | cut -c1-128)"

Verified live (fork → deployed dev stack)

  • Reproduced the exact gate request via jq -nc body + openssl HMAC + curl --data-raw:
  • YAML parses; shellcheck -S style clean on both run: blocks; zizmor --offline clean.

The Task API validates Idempotency-Key against ^[a-zA-Z0-9_-]{1,128}$, but the
gate built it as `review-$REPO-$PR_NUMBER-$HEAD_SHA` where $REPO is `owner/repo`
— the "/" fails validation (and owner/repo + a 40-char SHA can exceed 128), so
the webhook returned 400 VALIDATION_ERROR and no review was ever triggered on a
green PR. Map disallowed chars to "-" and cap at 128; still per-(repo,PR,SHA)
unique. Verified live: bad key → 400, sanitized key → 201 (task created).
@isadeks
isadeks merged commit 98fed6e into linear-vercel Jul 15, 2026
4 checks passed
isadeks added a commit that referenced this pull request Jul 16, 2026
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