Secures webhooks with HMAC signatures: signing payloads with openssl and node crypto, signature verification middleware, and replay protection.
Agentic Workflow: Read -> Reason -> Act (api-webhook-specialist)
You are api-webhook-specialist (backend) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — backend context for api-webhook-specialist
- Domain: Secures webhooks with HMAC signatures: signing payloads with openssl and node crypto, signature verification middleware, and replay protection.
- hmac-signing: Sign and verify webhook payloads —
openssl dgst -sha256 -hmac "secret-key" -hex payload.json
- verification: Verify signatures in middleware —
node -e "const c=require('crypto'); const ok=(sig,p)=>{const expect=c.createHmac
- Check
knowledge and prerequisites: node.js, python, ngrok, redis
2. Reason — think for api-webhook-specialist
- For
hmac-signing: Sign and verify webhook payloads — decide which checks to run
- For
verification: Verify signatures in middleware — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with api-webhook-specialist tools
- Tools:
Glob, Grep, Read, Openssl, Bash (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
api-webhook-specialist:2ae6a813
API Webhook Specialist
Webhook signature security.
What This Skill Does
- Signs payloads with HMAC-SHA256
- Verifies signatures in middleware
- Protects against replay and forgery
When to Use
- Receiving third-party webhooks
- Emitting signed webhooks
- Auditing delivery authenticity
Real Commands
openssl dgst -sha256 -hmac "secret-key" -hex payload.json
node -e "const c=require('crypto'); console.log(c.createHmac('sha256','secret-key').update('payload').digest('hex'))"
Verification Middleware
app.post('/webhooks', (req, res) => {
const sig = req.get('X-Signature').replace('sha256=', '');
const expected = crypto.createHmac('sha256', SECRET)
.update(JSON.stringify(req.body)).digest('hex');
if (!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))) {
return res.sendStatus(401);
}
res.sendStatus(200);
});
Testing
- Send bad signatures and expect 401
- Verify timestamped replay rejection
- Test header/body integrity
Best Practices
- Rotate webhook secrets regularly
- Use timingSafeEqual for comparisons
- Include timestamps to block replays
Capabilities
hmac-signing
Sign and verify webhook payloads
Parameters:
secret (string): Shared HMAC secret
algorithm (string): sha256, sha512
payload (string): Payload to sign
Commands:
openssl dgst -sha256 -hmac "secret-key" -hex payload.json
node -e "const c=require('crypto'); const sig=c.createHmac('sha256','secret-key').update(JSON.stringify({event:'x'})).digest('hex'); console.log(sig)"
node -e "const c=require('crypto'); const sig=(s)=>c.createHmac('sha256','secret-key').update(s).digest('hex'); const payload=JSON.stringify({a:1}); console.log('X-Signature:', sig(payload))"
curl -s -X POST http://localhost:3000/webhooks -H 'Content-Type: application/json' -H "X-Signature: sha256=$(openssl dgst -sha256 -hmac 'secret-key' -hex payload.json | awk '{print $2}')" -d @payload.json -w '\n%{http_code}\n'
Examples:
- openssl dgst -hmac signs with a shared secret
- node crypto verifies signatures in middleware
- curl sends the signature header for testing
verification
Verify signatures in middleware
Commands:
node -e "const c=require('crypto'); const ok=(sig,p)=>{const expect=c.createHmac('sha256','secret-key').update(p).digest('hex'); return c.timingSafeEqual(Buffer.from(sig),Buffer.from(expect))}; console.log(ok('abc','x'), ok(c.createHmac('sha256','secret-key').update('x').digest('hex'),'x'))"
curl -s -X POST http://localhost:3000/webhooks -H 'Content-Type: application/json' -H 'X-Signature: sha256=bad' -d '{"a":1}' -o /dev/null -w '%{http_code}\n'
Examples:
References
1---2name: "api-webhook-specialist"3description: "Secures webhooks with HMAC signatures: signing payloads with openssl and node crypto, signature verification middleware, and replay protection. Use when working with hmac signing, verification or when the user mentions hmac signing, verification."4license: "MIT"5compatibility: "Requires node.js, python, ngrok, redis, stripe-cli. Needs network access."6metadata:7 source: https://skillmd.com/skills/opknock/api-webhook-specialist8 author: Kdesk9 version: 2.0.010 category: backend11allowed-tools: "Glob Grep Read Bash(curl:*) Bash(node:*) Bash(openssl:*)"12---1314Secures webhooks with HMAC signatures: signing payloads with openssl and node crypto, signature verification middleware, and replay protection.1516## Agentic Workflow: Read -> Reason -> Act (api-webhook-specialist)1718You are **api-webhook-specialist** (backend) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — backend context for `api-webhook-specialist`21- Domain: Secures webhooks with HMAC signatures: signing payloads with openssl and node crypto, signature verification middleware, and replay protection.22- **hmac-signing**: Sign and verify webhook payloads — `openssl dgst -sha256 -hmac "secret-key" -hex payload.json`23- **verification**: Verify signatures in middleware — `node -e "const c=require('crypto'); const ok=(sig,p)=>{const expect=c.createHmac`24- Check `knowledge` and `prerequisites: node.js, python, ngrok, redis`2526### 2. Reason — think for `api-webhook-specialist`27- For `hmac-signing`: Sign and verify webhook payloads — decide which checks to run28- For `verification`: Verify signatures in middleware — decide which checks to run29- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs3031### 3. Act — execute with `api-webhook-specialist` tools32- Tools: `Glob`, `Grep`, `Read`, `Openssl`, `Bash` (see frontmatter `tools`/`allowed-tools`)33- Use `safe_path` for any write; record evidence (paths, checksums)34- Fingerprint: `api-webhook-specialist:2ae6a813`3536# API Webhook Specialist3738Webhook signature security.3940## What This Skill Does41- Signs payloads with HMAC-SHA25642- Verifies signatures in middleware43- Protects against replay and forgery4445## When to Use46- Receiving third-party webhooks47- Emitting signed webhooks48- Auditing delivery authenticity4950## Real Commands5152```bash53openssl dgst -sha256 -hmac "secret-key" -hex payload.json54node -e "const c=require('crypto'); console.log(c.createHmac('sha256','secret-key').update('payload').digest('hex'))"55```5657## Verification Middleware5859```js60app.post('/webhooks', (req, res) => {61 const sig = req.get('X-Signature').replace('sha256=', '');62 const expected = crypto.createHmac('sha256', SECRET)63 .update(JSON.stringify(req.body)).digest('hex');64 if (!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))) {65 return res.sendStatus(401);66 }67 res.sendStatus(200);68});69```7071## Testing72- Send bad signatures and expect 40173- Verify timestamped replay rejection74- Test header/body integrity757677## Best Practices78- Rotate webhook secrets regularly79- Use timingSafeEqual for comparisons80- Include timestamps to block replays8182## Capabilities8384### hmac-signing85Sign and verify webhook payloads8687**Parameters:**88- `secret` (string): Shared HMAC secret89- `algorithm` (string): sha256, sha51290- `payload` (string): Payload to sign9192**Commands:**93- `openssl dgst -sha256 -hmac "secret-key" -hex payload.json`94- `node -e "const c=require('crypto'); const sig=c.createHmac('sha256','secret-key').update(JSON.stringify({event:'x'})).digest('hex'); console.log(sig)"`95- `node -e "const c=require('crypto'); const sig=(s)=>c.createHmac('sha256','secret-key').update(s).digest('hex'); const payload=JSON.stringify({a:1}); console.log('X-Signature:', sig(payload))"`96- `curl -s -X POST http://localhost:3000/webhooks -H 'Content-Type: application/json' -H "X-Signature: sha256=$(openssl dgst -sha256 -hmac 'secret-key' -hex payload.json | awk '{print $2}')" -d @payload.json -w '\n%{http_code}\n'`9798**Examples:**99- openssl dgst -hmac signs with a shared secret100- node crypto verifies signatures in middleware101- curl sends the signature header for testing102103### verification104Verify signatures in middleware105106**Commands:**107- `node -e "const c=require('crypto'); const ok=(sig,p)=>{const expect=c.createHmac('sha256','secret-key').update(p).digest('hex'); return c.timingSafeEqual(Buffer.from(sig),Buffer.from(expect))}; console.log(ok('abc','x'), ok(c.createHmac('sha256','secret-key').update('x').digest('hex'),'x'))"`108- `curl -s -X POST http://localhost:3000/webhooks -H 'Content-Type: application/json' -H 'X-Signature: sha256=bad' -d '{"a":1}' -o /dev/null -w '%{http_code}\n'`109110**Examples:**111- -cli --help112- -api --help113114## References115- [Stripe Webhook Signatures](https://docs.stripe.com/webhooks/signatures)116- [Node crypto Docs](https://nodejs.org/api/crypto.html)