- Home
- Skills
- APIs & Backend
- stripe webhook raw body
stripe webhook raw body
Correctly preserve and verify Stripe webhook signatures in Express and TypeScript applications.
$20
Works with the AI Agents you already use
stripe webhook raw body
Example session with this skill installed
I'm getting signature verification errors in my Express app when Stripe sends webhooks. How do I fix the raw body issue?
- Read your context and instructions
- Compiled the stripe webhook raw
I have implemented the raw body preservation pattern. The verification was failing because express.json() parses the body into an object, discarding the exact byte sequence Stripe uses for the HMAC signature. I have updated your server configuration and the webhook route to use a verification callback and a hard guard.
Stripe Webhook Implementation
// 1. Update app.ts / server setup
import express, { Request, Response, NextFunction } from 'express';
app.use(
express.json({
verify: (req: any, _res: Response, buf: Buffer) => {
// Store the raw bytes on the request object
req.rawBody = buf;
},
}),
);
// 2. Update types/express.d.ts
declare global {
namespace Express {
interface Request {
rawBody?: Buffer;
}
}
}
// 3. Update routes/webhooks.ts
router.post("/webhook", async (req: Request, res: Response) => {
const sig = req.headers["stripe-signature"];
const webhookSecret = process.env.STRIPE_WEBHOOK_SECRET;
if (!sig || !webhookSecret) {
return res.status(400).send("Missing signature or secret");
}
const rawBody = req.rawBody;
if (!rawBody) {
// Fail hard: do not attempt JSON.stringify(req.body)
return res.status(400).send("Raw body not preserved");
}
try {
const event = stripe.webhooks.constructEvent(rawBody, sig, webhookSecret);
// Process verified event
res.json({ received: true });
} catch (err) {
const message = err instanceof Error ? err.message : "Unknown error";
res.status(400).send(`Webhook Error: ${message}`);
}
});
Next steps
- Ensure the webhook route is defined after the
express.jsonmiddleware update. - Verify your
STRIPE_WEBHOOK_SECRETenvironment variable matches the one in the Stripe Dashboard. - Use the Stripe CLI to trigger a test event and confirm the
rawBodyis correctly captured.
Connects securely to your tools. The creator never sees your data.
About this skill
Webhook signature verification fails when Express middleware parses request bodies, as the original byte sequence is lost. This skill provides the precise implementation pattern to preserve raw request bytes and verify Stripe events. It eliminates the common mistake of re-serializing JSON, which causes cryptographic mismatches due to key ordering and whitespace changes.
What it does
- Preserves raw bytes via the
express.jsonverify callback to ensure signature accuracy. - Enforces hard guards in route handlers to prevent insecure fallbacks to parsed JSON.
- Extends Express types to include
rawBodybuffers, maintaining TypeScript safety. - Configures development modes to handle local testing when secrets are unavailable.
- Audits middleware order to ensure body-parsing doesn't corrupt incoming webhook data.
How it works
- Middleware configuration: Modify the global or route-specific
express.jsonparser to capture the buffer. - Type definition: Extend the Express Request interface to recognize the
rawBodyproperty. - Handler implementation: Add the
constructEventcall with the captured buffer and signature header. - Error handling: Implement guards to return 400 errors if the raw body is missing or the signature is invalid.
Frameworks & tools
Node.js, Express, Stripe SDK, and TypeScript.
Why this beats prompting it yourself
Standard LLM prompts often suggest JSON.stringify(req.body) as a fallback, which is a logic error that causes production failures. This skill provides the specific middleware hook pattern that is physically required for cryptographic verification to succeed.
Use cases
- Adding a new
/webhookendpoint to an existing Express API. - Debugging "No relevant data found in the
Stripe-Signatureheader" errors. - Migrating a Stripe integration from JavaScript to TypeScript with strict typing.
- Setting up local development environments for testing Stripe events.
Known limitations
Requires the use of Express and the standard Stripe Node.js SDK. Signature verification will fail if other global middleware modifies the request stream before this pattern is applied.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
Requires Express framework. Verification fails if global middleware consumes the request stream before the verify callback runs.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 22 days ago