How to fix: Square webhook signature key in source
Square HMAC signature keys let attackers forge webhook events (payments.created, refund.updated). Must live server-side only.
Why it matters
An exposed Square webhook signature key allows an attacker to forge webhook events: sending fake payments.completed or refund.updated events to your server, causing it to fulfill orders, ship goods, or issue refunds for transactions that never occurred.
Square HMAC signature keys let attackers forge webhook events (payments.created, refund.updated). Must live server-side only.
How to fix it
- 1Move the signature key to a server-only environment variable
- 2Rotate the key in Square Developer Dashboard → Webhooks → Signature key
- 3Verify all incoming webhooks server-side before acting on them
Code examples
Next.js: verify Square webhook signature server-side
import { createHmac } from 'crypto';
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const body = await req.text();
const signature = req.headers.get('x-square-hmacsha256-signature')!;
const notifUrl = process.env.SQUARE_WEBHOOK_NOTIFICATION_URL!;
const sigKey = process.env.SQUARE_WEBHOOK_SIGNATURE_KEY!; // server-only
const hmac = createHmac('sha256', sigKey)
.update(notifUrl + body)
.digest('base64');
if (hmac !== signature) {
return NextResponse.json({ error: 'Invalid signature' }, { status: 401 });
}
// Process event...
return NextResponse.json({ ok: true });
}References
Detected automatically by VulnRadar. The check id is secret-square-webhook-signature, stable across every scan so you can filter or diff on it.
More secrets checks
Questions
- How severe is Square webhook signature key in source?
- VulnRadar rates this critical severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id secret-square-webhook-signature, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Square webhook signature key in source map to?
- It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.