Skip to content

Pass the webhook request through without buffering its body - #3166

Merged
pranaygp merged 2 commits into
mainfrom
naterajlich/webhook-token-before-body-read
Jul 28, 2026
Merged

Pass the webhook request through without buffering its body#3166
pranaygp merged 2 commits into
mainfrom
naterajlich/webhook-token-before-body-read

Conversation

@TooTallNate

@TooTallNateTooTallNate commented Jul 28, 2026

Copy link
Copy Markdown
Member

Problem

The Astro and SvelteKit webhook wrappers copied the incoming request via normalizeRequest() — which reads the whole body with arrayBuffer() — before calling the handler. That read happened before the handler had a chance to look at the token, so requests carrying an unknown token did unnecessary work before being rejected.

Fix

The copy turns out to be unnecessary. Both frameworks already hand the route a standard Request, so the wrappers now pass it straight through:

constcreateHandler=(method)=>async({ request, params, platform })=>{constresponse=awaithandler(request,params.token);returnresponse;};

The body is left untouched until resumeWebhook() has accepted the token. This deletes code rather than adding a second normalizer — an earlier revision of this PR added a streaming variant of normalizeRequest, but with the body read removed that wrapper was just an identity copy of the request, so it's gone.

The flow route keeps normalizeRequest(): it authenticates via the queue trigger rather than a URL token, so the ordering doesn't matter there. Whether the shim is needed there at all is a separate question — see below.

On the origin of the shim

Per prior discussion, normalizeRequest was introduced to get an e2e test passing before a launch, and the specific failure is no longer remembered. For the webhook route I can confirm it is not needed: with it removed, the full e2e.test.ts passes on both frameworks, including the webhook cases that assert exact received bodies across the default, static and manual respondWith paths.

I have not tested removing it from the flow route. That's a larger change and unrelated to this one, so it's left for a follow-up rather than folded in.

Verification

AstroSvelteKit
full e2e.test.ts128 passed, 7 skipped128 passed, 7 skipped
unknown-token requestrejected without the body being readrejected without the body being read

Notes for reviewers

Astro dev server. It reads request bodies upstream of the route handler — a route that never touches the body behaves the same way — so the change is only observable in built output (node adapter / Vercel), which is what gets deployed.

No automated regression guard. The property "the webhook wrapper must not read the body" is currently enforced only by the comment in each builder. Making it testable would mean extracting the wrapper template into an exported constant so a unit test could assert it; happy to add that if reviewers want it.

CopilotAI review requested due to automatic review settings July 28, 2026 20:06
@TooTallNate
TooTallNate requested review from a team and ijjk as code ownersJuly 28, 2026 20:06
@vercel

vercelBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@changeset-bot

changeset-botBot commented Jul 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8ff9026

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
NameType
@workflow/astroPatch
@workflow/sveltekitPatch
workflowPatch
@workflow/world-testingPatch
@workflow/corePatch
@workflow/buildersPatch
@workflow/cliPatch
@workflow/nextPatch
@workflow/nitroPatch
@workflow/vitestPatch
@workflow/web-sharedPatch
@workflow/webPatch
@workflow/nestPatch
@workflow/nuxtPatch
@workflow/rollupPatch
@workflow/vitePatch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

CopilotAI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actionsBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

📊 Workflow Benchmarks

commit 8ff9026 · Tue, 28 Jul 2026 22:06:10 GMT · run logs

Backend: vercel · app: nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep1213 (+72%) 🔻1271 🔴 (+26%) 🔻1290 🔴 (+27%) 🔻1383 🔴 (-8.3%)30
TTFSstream1201 (+26%) 🔻1246 🔴 (+26%) 🔻1262 🔴 (+25%) 🔻1467 🔴 (+40%) 🔻30
TTFShook + stream492 (-59%) 💚1521 🔴 (+18%) 🔻1536 🔴 (+15%)1605 🔴 (±0%)30
STSO1020 steps (1-20)168 (+5.0%)262 🔴 (+1.9%)311 🔴 (+2.6%)321 🔴 (-24%) 💚19
STSO1020 steps (101-120)162 (-12%)253 🔴 (+3.3%)327 🔴 (+16%) 🔻533 🔴 (-24%) 💚19
STSO1020 steps (1001-1020)456 (-2.4%)510 🔴 (-9.7%)522 🔴 (-14%)576 🔴 (-16%) 💚19
WO1020 steps582923 (+51%) 🔻582923 (+51%) 🔻582923 (+51%) 🔻582923 (+51%) 🔻1
SLstream latency80 (-1.2%)136 🔴 (+3.0%)141 🔴 (+0.7%)367 🔴 (+105%) 🔻30
SOstream overhead (text)94 (-6.9%)152 (-16%) 💚187 (-7.4%)285 (+14%)30
SOstream overhead (structured)100 (+1.0%)140 (-14%)147 (-25%) 💚174 (-20%) 💚30
📜 Previous results (2)

acf61a3

Tue, 28 Jul 2026 21:20:47 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep1264 (+79%) 🔻1339 🔴 (+33%) 🔻1397 🔴 (+38%) 🔻1495 🔴 (-0.9%)30
TTFSstream392 (-59%) 💚1319 🔴 (+34%) 🔻1331 🔴 (+32%) 🔻1393 🔴 (+33%) 🔻30
TTFShook + stream515 (-58%) 💚1565 🔴 (+21%) 🔻1581 🔴 (+18%) 🔻1664 🔴 (+3.4%)30
STSO1020 steps (1-20)182 (+14%)310 🔴 (+21%) 🔻387 🔴 (+28%) 🔻635 🔴 (+50%) 🔻19
STSO1020 steps (101-120)188 (+1.6%)262 🔴 (+6.9%)327 🔴 (+16%) 🔻356 🔴 (-49%) 💚19
STSO1020 steps (1001-1020)491 (+5.1%)547 🔴 (-3.2%)593 🔴 (-2.8%)665 🔴 (-3.1%)19
WO1020 steps405492 (+5.1%)405492 (+5.1%)405492 (+5.1%)405492 (+5.1%)1
SLstream latency128 (+58%) 🔻229 🔴 (+73%) 🔻302 🔴 (+116%) 🔻468 🔴 (+161%) 🔻30
SOstream overhead (text)173 (+71%) 🔻264 🔴 (+47%) 🔻286 (+42%) 🔻521 (+108%) 🔻30
SOstream overhead (structured)147 (+48%) 🔻242 (+49%) 🔻264 (+35%) 🔻291 (+34%) 🔻30

d8a70f9

Tue, 28 Jul 2026 20:28:48 GMT · run logs

vercel / nextjs-turbopack

MetricScenarioBest (ms)P75 (ms)P90 (ms)P99 (ms)Samples
TTFSstep291 (-59%) 💚1431 🔴 (+42%) 🔻1459 🔴 (+44%) 🔻1912 🔴 (+27%) 🔻30
TTFSstream216 (-77%) 💚1448 🔴 (+47%) 🔻1524 🔴 (+51%) 🔻1555 🔴 (+48%) 🔻30
TTFShook + stream392 (-68%) 💚1597 🔴 (+24%) 🔻1654 🔴 (+24%) 🔻1706 🔴 (+6.0%)30
STSO1020 steps (1-20)180 (+13%)293 🔴 (+14%)372 🔴 (+23%) 🔻383 🔴 (-9.7%)19
STSO1020 steps (101-120)196 (+5.9%)300 🔴 (+22%) 🔻419 🔴 (+49%) 🔻442 🔴 (-37%) 💚19
STSO1020 steps (1001-1020)575 (+23%) 🔻655 🔴 (+16%) 🔻675 🔴 (+11%)923 🔴 (+35%) 🔻19
WO1020 steps439125 (+14%)439125 (+14%)439125 (+14%)439125 (+14%)1
SLstream latency99 (+22%) 🔻181 🔴 (+37%) 🔻192 🔴 (+37%) 🔻215 🔴 (+20%) 🔻30
SOstream overhead (text)127 (+26%) 🔻248 (+38%) 🔻307 (+52%) 🔻467 (+87%) 🔻30
SOstream overhead (structured)120 (+21%) 🔻215 (+33%) 🔻282 (+45%) 🔻559 (+158%) 🔻30
ℹ️ Metric definitions & methodology

Best/P75/P90/P99 deltas compare against the most recent benchmark run on main at the time of this run. 🔻 flags a delta worse than +15%, 💚 one better than −15%.

Metrics — TTFS: time to first step body (in-deployment start() → first step body, deployment clocks) · STSO: step-to-step overhead (gap between consecutive step bodies) · WO: workflow overhead (whole-run time outside step bodies, in-deployment anchored) · SL: stream latency (in-deployment write → read propagation, readAt - writtenAt) · SO: stream overhead (end-to-end write+consume time beyond the modelled generation window)

Scenarios — step: one trivial no-op step, no stream; no hooks, so the run stays in turbo mode (in-process fast path) · stream: one streaming step; no hooks, so the run stays in turbo mode (in-process fast path) · hook + stream: registers a hook before one step, which exits turbo mode (dispatch path) · 1020 steps: 1020 trivial sequential steps; STSO is measured between consecutive steps in the given step ranges, and WO is the whole-run overhead outside step bodies · stream latency: parallel reader/writer steps on a dedicated stream; SL is the in-deployment write->read propagation (readAt - writtenAt) · stream overhead (text): writer streams 300 variable-length text token deltas paced at 100/s for 3s (a haiku-size LLM's token throughput) while a parallel reader drains the whole stream; SO is the end-to-end write+consume time beyond the 3s generation window (overhead/backpressure) · stream overhead (structured): same workload as stream overhead (text), but each delta is an AI-SDK-style structured object ({ type: 'text-delta', id, text }) instead of a raw string, so the SO gap vs the text scenario is the added serialization cost

🔴 marks a percentile over its target (within target is left unmarked). Targets (p75/p90/p99, ms) — TTFS 200/300/600 · SL 50/60/125 · SO 250/500/1000 · STSO (1-20) 20/30/60 · STSO (101-120) 30/45/90 · STSO (1001-1020) 40/60/120

All metrics are measured from deployment-side timestamps only. Runs are triggered by an in-deployment route that stamps the anchor (clientStart) right before start(), so the CI runner’s request and its path through api.vercel.com sit outside every measured window. TTFS = in-deployment start() → first step body (turbo uses the in-process fast path, non-turbo the dispatch path), and includes the VQS dispatch hop plus any /flow cold start. STSO/WO are measured between step bodies on the deployment. SL is measured inside the workflow (parallel reader/writer steps), so it no longer includes the api.vercel.com read path.

Cold starts are kept in the numbers on purpose — they are part of real bursty-workload latency. The workbench deployment cold-starts the /flow invocation for a large fraction of runs, inflating P75+; the Best column shows the fastest (warm-start) sample for comparison.

@github-actions

github-actionsBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🧪 E2E Test Results

Some tests failed

❌ Failed E2E Tests

▲ Vercel Production (1 failed)

fastify (1 failed):

💻 Local Development (1 failed)

nuxt-stable (1 failed):

  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_41KYNBBR7H0GXN812PT9G0VFCW

E2E Test Summary

Summary
PassedFailedSkippedTotal
❌ ▲ Vercel Production145412391694
❌ 💻 Local Development148512081694
✅ 📦 Local Production162102271848
✅ 🐘 Local Postgres162102271848
✅ 🪟 Windows15400154
✅ 📋 Other102002121232
✅ vercel-multi-region270027
Total7382211138497
Details by Category

❌ ▲ Vercel Production

AppPassedFailedSkipped
✅ astro126028
✅ example126028
✅ express126028
❌ fastify125128
✅ hono126028
✅ nextjs-turbopack15103
✅ nextjs-webpack15103
✅ nitro126028
✅ nuxt126028
✅ sveltekit14509
✅ vite126028

❌ 💻 Local Development

AppPassedFailedSkipped
✅ astro-stable128026
✅ express-stable128026
✅ fastify-stable128026
✅ hono-stable128026
✅ nextjs-turbopack-canary135019
✅ nextjs-turbopack-stable15400
✅ nextjs-webpack-stable15400
✅ nitro-stable128026
❌ nuxt-stable127126
✅ sveltekit-stable14707
✅ vite-stable128026

✅ 📦 Local Production

AppPassedFailedSkipped
✅ astro-stable128026
✅ express-stable128026
✅ fastify-stable128026
✅ hono-stable128026
✅ nextjs-turbopack-canary135019
✅ nextjs-turbopack-stable15400
✅ nextjs-webpack-canary135019
✅ nextjs-webpack-stable15400
✅ nitro-stable128026
✅ nuxt-stable128026
✅ sveltekit-stable14707
✅ vite-stable128026

✅ 🐘 Local Postgres

AppPassedFailedSkipped
✅ astro-stable128026
✅ express-stable128026
✅ fastify-stable128026
✅ hono-stable128026
✅ nextjs-turbopack-canary135019
✅ nextjs-turbopack-stable15400
✅ nextjs-webpack-canary135019
✅ nextjs-webpack-stable15400
✅ nitro-stable128026
✅ nuxt-stable128026
✅ sveltekit-stable14707
✅ vite-stable128026

✅ 🪟 Windows

AppPassedFailedSkipped
✅ nextjs-turbopack15400

✅ 📋 Other

AppPassedFailedSkipped
✅ e2e-local-dev-nest-stable128026
✅ e2e-local-dev-tanstack-start-128026
✅ e2e-local-postgres-nest-stable128026
✅ e2e-local-postgres-tanstack-start-128026
✅ e2e-local-prod-nest-stable128026
✅ e2e-local-prod-tanstack-start-128026
✅ e2e-vercel-prod-nest126028
✅ e2e-vercel-prod-tanstack-start126028

✅ vercel-multi-region

AppPassedFailedSkipped
✅ nextjs-turbopack2700

📋 View full workflow run

@TooTallNateTooTallNate mentioned this pull request Jul 28, 2026
@TooTallNate
TooTallNateforce-pushed the naterajlich/webhook-token-before-body-read branch from d8a70f9 to ef2f142CompareJuly 28, 2026 20:38
@TooTallNateTooTallNate changed the title Validate webhook token before reading the request bodyPass the webhook request through without buffering its bodyJul 28, 2026
@github-actionsgithub-actionsBot mentioned this pull request Jul 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

No backport to stable for 0d6ec43 (AI decision).

This removes an unnecessary normalizeRequest() copy from the generated Astro/SvelteKit webhook routes so the body isn't buffered before the token is validated — an efficiency/cleanup change, not a fix for a user-visible defect. The existing behavior works correctly on stable (the PR confirms e2e passes both with and without the copy); the only difference is that unknown-token requests did some wasted work before rejection, which doesn't rise to a stability problem like an unbounded allocation or crash. Both packages/astro/src/builder.ts and packages/sveltekit/src/builder.ts do exist on stable, so the change would apply, but per the maintenance-branch criteria performance/refactor work stays on main.

To override, re-run the Backport to stable workflow manually via workflow_dispatch and paste this commit SHA into the ref input:

0d6ec438770f42cb3c512e97c27ec551c957de32

@github-actions

Copy link
Copy Markdown
Contributor

Backport PR opened against stable: #3174. (backport job run)

Sign up for freeto 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.

3 participants

@TooTallNate@pranaygp