Recommended pattern for plugins that need to verify signed webhook bodies (Slack/Stripe/GitHub etc.)? #1043
shinobiworks
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.
-
Context
I'm building a plugin that receives Slack webhooks. Slack signs each request with HMAC-SHA256 computed over
"v0:" + timestamp + ":" + rawBodyBytes, and the receiver must verify this signature using the exact bytes Slack sent. This is a standard pattern for any signed webhook source (Slack, Stripe, GitHub, Linear, Discord, etc.).What I observed
Looking at
EmDashRuntime.handlePluginApiRouteindist/astro/middleware.mjs, the framework callsawait request.json()before invoking the route handler. This consumes the body stream, so my handler cannot callctx.request.text()to read the raw bytes (it throwsTypeError: Body has already been used, which gets caught and returned as500 INTERNAL_ERROR "Plugin route error").The route context provides
ctx.input(parsed JSON) but not the raw body string. I checked theRouteContexttype and thePluginRouteinterface for an opt-out flag or rawBody accessor and didn't find one.Question
Is there an intended pattern for plugins to access the raw request body for signature verification? Or is this a use case EmDash currently doesn't cover?
I'm currently working around it with a patches/ override that adds
ctx.rawBody(5-line patch across middleware.mjs / search-.mjs / types-.d.mts), but I'd prefer to use a supported API if one exists or could be added.EmDash version
0.12.0
Beta Was this translation helpful? Give feedback.
All reactions