Unverified webhook endpoints and missing idempotency gates cause duplicate Stripe charges, double CRM records, and spoofed payload execution. Generate copy-ready HMAC signature verification code and atomic deduplication SQL for your n8n pipelines—or unlock all 50 pre-hardened JSON blueprints instantly for $79.
Stripe-Signature{{ $json.body.id }}// n8n Code Node: Stripe-Signature HMAC-SHA256 + 300s Replay Protection
const crypto = require('crypto');
const header = $input.first().json.headers['stripe-signature'] || '';
const parts = Object.fromEntries(header.split(',').map(p => p.split('=')));
const ts = parseInt(parts.t || '0', 10);
if (Math.abs(Math.floor(Date.now() / 1000) - ts) > 300) {
throw new Error('Rejected: Stripe webhook timestamp outside 300s replay window');
}
const signedPayload = parts.t + '.' + ($input.first().json.rawBody || '');
const expected = crypto.createHmac('sha256', $env.STRIPE_WEBHOOK_SECRET).update(signedPayload).digest('hex');
if (!crypto.timingSafeEqual(Buffer.from(parts.v1 || ''), Buffer.from(expected))) {
throw new Error('Rejected: Invalid Stripe-Signature v1 digest');
}
return $input.all();
-- Atomic Idempotency Gate + Dead-Letter Audit Ledger (PostgreSQL)
INSERT INTO stackroi_webhook_ledger (
event_id,
provider,
received_at,
status
) VALUES (
$1, -- Bound to {{ $json.body.id }}
'stripe',
NOW(),
'processing'
)
ON CONFLICT (event_id) DO NOTHING
RETURNING event_id;
Every webhook-triggered workflow in the StackROI 50-Blueprint JSON Vault ships with constant-time HMAC verification, atomic idempotency deduplication, exponential backoff, and Slack/PagerDuty Dead-Letter Queue error sub-workflows ready to import into n8n.
Need a custom high-throughput webhook ingestion cluster or multi-region n8n migration? Request a custom engineering quote.