fix(review-gate): sanitize Idempotency-Key to API-allowed charset#48
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Caught while wiring up the gate live on the fork. The Task API validates
Idempotency-Keyagainst^[a-zA-Z0-9_-]{1,128}$(cdk/src/handlers/shared/validation.ts:46), but the gate built the key asreview-$REPO-$PR_NUMBER-$HEAD_SHAwhere$REPOisowner/repo. The/fails the pattern (andowner/repo+ a 40-char SHA also blows past 128 chars), so on a green PR the webhook returned400 VALIDATION_ERRORand 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.Verified live (fork → deployed dev stack)
jq -ncbody +opensslHMAC +curl --data-raw:review-isadeks/sample-…-47-<sha>):400 VALIDATION_ERROR "Invalid Idempotency-Key format."201, realcoding/pr-review-v1task created against PR docs(readme): add responsibility note for agent output #47 (nowRUNNING, posting a review).shellcheck -S styleclean on bothrun:blocks;zizmor --offlineclean.