Raw request body access for plugin routes (webhook signature verification) #2546
marcusbellamyshaw-cell
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Proposal to close #1735: plugin routes have no way to access the raw, unparsed request body, which blocks HMAC-style webhook signature verification (Stripe, GitHub, Shopify, etc.) inside a plugin route -- those schemes sign the exact raw bytes, and re-serializing
ctx.inputdoes not reproduce them.Proposed API
Additive opt-in on the route descriptor:
Setting
raw: trueskips the unconditionalrequest.json()call in bothhandlePluginApiRoute(trusted/configured plugins) andhandleSandboxedRoute(sandboxed/marketplace plugins), reads the body once viarequest.text(), and populatesctx.rawBodyinstead ofctx.input. Routes that don't setrawsee zero behavior change -- same parse, samectx.input, sameguardConsumedRequestBodyproxy (added for #1293).Out of scope
request.text()is sufficient.Acceptance
PluginRoute.raw/RouteContext.rawBodytyped and documented.raw: trueskipsrequest.json(), populatesctx.rawBody, for both trusted and sandboxed paths.rawroutes are unaffected.raw: trueroute computes an HMAC overctx.rawBodymatching a signature computed independently over the same request bytes.Full writeup with exact call-site references (
emdash-runtime.tsL3132/L3381,routes.tsL33-49,types.tsL1061-1083) is on the issue. Happy to open the PR once the shape looks right.All reactions