Plaid Webhooks: Signature Validation and the Replay Attack Problem
Plaid's webhook signature validation looks simple until you realize their docs barely mention replay attacks. Here's what I actually do in production.
Plaid's webhook signature validation looks straightforward on paper. Verify the JWT, trust the payload, move on. What the docs don't hammer home is that a valid signature is not a complete security check - an attacker who captures a legitimate webhook request can replay it minutes or hours later, and your endpoint will accept it without complaint.
I hit this in a real way building a cash-flow dashboard for a small lending company. We were ingesting TRANSACTIONS_SYNC webhooks and triggering sync jobs. The signature verification passed. Everything looked fine. It took a code review to realize we had zero protection against a captured request being replayed.
What Plaid's Webhooks Actually Do
Plaid sends webhooks for async events - new transactions available, auth status changes, item errors, that kind of thing. The payloads don't carry the sensitive financial data themselves; they carry a notification that you should go fetch something via the API. That's a sensible design.
But the security contract has two parts that only one of them gets top billing in the docs:
- Signature verification - prove Plaid sent this payload (Plaid covers this thoroughly)
- Replay prevention - prove this specific request is fresh (Plaid mentions it, then moves on)
Plaid signs webhooks using a JWT scheme with rotating keys. The verification flow is: fetch the current signing keys from https://api.plaid.com/webhook_verification_key/get, decode the JWT header to get the kid (key ID), grab the matching key, verify the token. The payload is the JWT claims body. It's not a simple HMAC-SHA256 like Stripe uses - it's a full JWT with an iat (issued-at) claim baked in.
That iat claim is your lever for replay prevention. Use it.
The Verification Code I Actually Ship
Here's the middleware I use in Laravel. It lives at app/Http/Middleware/VerifyPlaidWebhook.php.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Firebase\JWT\JWT;
use Firebase\JWT\JWK;
use Firebase\JWT\Key;
class VerifyPlaidWebhook
{
// Reject webhooks older than 5 minutes
private const MAX_AGE_SECONDS = 300;
// Cache Plaid's signing keys for 1 hour
private const KEY_CACHE_TTL = 3600;
public function handle(Request $request, Closure $next): mixed
{
$token = $request->header('Plaid-Verification');
if (empty($token)) {
return response()->json(['error' => 'Missing verification header'], 401);
}
try {
$decoded = $this->verifyToken($token, $request->getContent());
} catch (\Throwable $e) {
report($e);
return response()->json(['error' => 'Invalid webhook signature'], 401);
}
// Replay attack prevention: check the issued-at timestamp
$iat = $decoded->iat ?? 0;
$age = time() - $iat;
if ($age > self::MAX_AGE_SECONDS || $age < -30) {
return response()->json(['error' => 'Webhook timestamp out of range'], 401);
}
// Idempotency check: reject if we've seen this exact JWT before
$jti = $decoded->jti ?? null;
if ($jti) {
$cacheKey = 'plaid_webhook_jti:' . $jti;
if (Cache::has($cacheKey)) {
return response()->json(['error' => 'Duplicate webhook'], 200);
}
// Store JTI for the max age window plus a small buffer
Cache::put($cacheKey, 1, self::MAX_AGE_SECONDS + 60);
}
return $next($request);
}
private function verifyToken(string $token, string $rawBody): object
{
// Decode header without verification to get kid
$parts = explode('.', $token);
if (count($parts) !== 3) {
throw new \InvalidArgumentException('Malformed JWT');
}
$header = json_decode(base64_decode(strtr($parts[0], '-_', '+/')), true);
$kid = $header['kid'] ?? null;
if (!$kid) {
throw new \InvalidArgumentException('No kid in JWT header');
}
$key = $this->getSigningKey($kid);
// firebase/php-jwt handles signature + expiry verification
$decoded = JWT::decode($token, $key);
// Verify the payload hash - this is the part people skip
// Plaid puts a SHA256 hash of the raw body in the request_body_sha256 claim
$expectedHash = hash('sha256', $rawBody);
if (!hash_equals($expectedHash, $decoded->request_body_sha256 ?? '')) {
throw new \RuntimeException('Payload hash mismatch');
}
return $decoded;
}
private function getSigningKey(string $kid): Key
{
$cacheKey = 'plaid_signing_key:' . $kid;
$keyData = Cache::remember($cacheKey, self::KEY_CACHE_TTL, function () use ($kid) {
$response = Http::withToken(config('services.plaid.secret'))
->post(config('services.plaid.base_url') . '/webhook_verification_key/get', [
'client_id' => config('services.plaid.client_id'),
'secret' => config('services.plaid.secret'),
'key_id' => $kid,
]);
if (!$response->successful()) {
throw new \RuntimeException('Failed to fetch Plaid signing key');
}
return $response->json('key');
});
// JWK::parseKey returns a Key object from an associative array
return JWK::parseKey($keyData, 'RS256');
}
}
Register it in bootstrap/app.php (Laravel 11) or Kernel.php (10 and below) as a route middleware and apply it to your Plaid webhook routes. Use api guard so CSRF doesn't block it.
The Gotchas That Will Bite You
The payload hash check is not optional. I've seen integrations that verify the JWT signature and call it done. The JWT proves Plaid signed a token. The request_body_sha256 claim proves this token corresponds to this body. Without that check, an attacker could potentially substitute a different payload under a valid JWT header. Plaid documents this claim, but it's buried.
Key rotation will break you if you cache too aggressively. Plaid rotates signing keys periodically. If you cache forever, you'll start rejecting valid webhooks after a rotation. The kid in the JWT header will change, so cache per kid with a reasonable TTL (I use 1 hour). On a cache miss, fetch fresh from the API. This also means your first request after a rotation takes a round-trip to Plaid's API - that's acceptable.
The jti claim is not always present in older webhook types. I found this out the hard way. Build your idempotency logic to degrade gracefully when jti is absent - fall back to the iat plus a hash of the payload. It's not as clean but it's better than crashing.
Clock skew is real. I allow a -30 second buffer for the age check. Your server and Plaid's infrastructure won't always agree on the exact second. I've seen Plaid webhooks arrive with an iat a few seconds in the future. Without that negative buffer, you'd reject them.
Sandbox webhooks behave differently. In the Plaid sandbox, you can fire test webhooks from the dashboard. Those go through the same signing pipeline, but I've had moments where the sandbox key wasn't rotating on the same schedule as production. Keep your sandbox and production credential configs strictly separate and don't assume sandbox behavior matches production.
Don't return 4xx on duplicates. Return 200. If your app returns a 4xx on a webhook Plaid considers successfully delivered, Plaid's retry logic may kick in and you'll get a cascade. A 200 with a "duplicate" body is the right answer - it tells Plaid you got it, and you've silently swallowed the replay.
When I'd Reach for This (and When I Wouldn't)
If you're doing anything financial with Plaid - transaction sync, account balance monitoring, payment initiation status - you need this whole stack. Full stop. The lending company situation I mentioned earlier was processing downstream jobs based on webhook triggers. A replay attack there would kick off redundant sync jobs at best, and at worst could mess up state machines that tracked loan eligibility. The cost of doing this right is a few hours. The cost of skipping it is a production incident you explain to a client.
If you're just prototyping or running a quick internal tool against sandbox, the full implementation is overkill. But the second you're touching real user financial data, the bar changes.
I wouldn't lean on webhooks alone for anything where financial state has to be exact. Plaid's own guidance is to treat webhooks as a signal to fetch fresh data, not as the authoritative data source itself. I follow that. The webhook fires, I validate it, I enqueue a job to call the actual API, I don't trust the webhook payload as ground truth for anything that hits the database directly.
The Bottom Line
Plaid's signature scheme is solid. The firebase/php-jwt library handles the heavy lifting fine. What's missing from the docs is a clear warning that signature verification without timestamp checking is not replay protection - it's just authentication. Add the age check, add the JTI store, verify the body hash, and you have something worth shipping. It took me getting this wrong once to make sure I never will again.
Need help shipping something like this? Get in touch.