Skip to content

Commit 98fed6e

Browse files
authored
fix(review-gate): sanitize Idempotency-Key to API-allowed charset (#48)
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).
1 parent 6dfb1e4 commit 98fed6e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

.github/workflows/review-gate.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,18 @@ jobs:
334334
# openssl output is "(stdin)= <hex>" or "SHA2-256(stdin)= <hex>"; take last.
335335
SIG="$(printf '%s' "$POST_BODY" | openssl dgst -sha256 -hmac "$ABCA_WEBHOOK_SECRET" | awk '{print $NF}')"
336336
337+
# The Task API validates Idempotency-Key against ^[a-zA-Z0-9_-]{1,128}$.
338+
# $REPO carries a "/" (owner/repo), so map every disallowed char to "-"
339+
# and cap at 128. Still per-(repo,PR,SHA) unique, which is all we need.
340+
IDEMPOTENCY_KEY="$(printf 'review-%s-%s-%s' "$REPO" "$PR_NUMBER" "$HEAD_SHA" \
341+
| tr -c 'a-zA-Z0-9_-' '-' | cut -c1-128)"
342+
337343
HTTP_CODE="$(curl -sS -o /tmp/abca-resp.txt -w '%{http_code}' \
338344
-X POST "${ABCA_TASK_API_URL%/}/webhooks/tasks" \
339345
-H 'Content-Type: application/json' \
340346
-H "X-Webhook-Id: $ABCA_WEBHOOK_ID" \
341347
-H "X-Webhook-Signature: sha256=$SIG" \
342-
-H "Idempotency-Key: review-$REPO-$PR_NUMBER-$HEAD_SHA" \
348+
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
343349
--data-raw "$POST_BODY")"
344350
345351
if [[ "$HTTP_CODE" =~ ^2 ]]; then

0 commit comments

Comments
 (0)