T09 · Insecure Skill Coding Practices
- Location
SKILL.md:448- Finding
Fail-Open Webhook Authentication Allows Forged Agent Events
- Content
View full analysis
{ const event = req.headers['x-g0-event']; const agentId = req.headers['x-g0-agent-id']; const signature = req.headers['x-g0-signature']; // Verify signature (recommended) if (process.env.WEBHOOK_SECRET && signature) { const expected = crypto.createHmac('sha256', process.env.WEBHOOK_SECRET) .update(JSON.stringify(req.body)) .digest('hex'); if (signature !== expected) { console.warn('Invalid signature'); } } // Always respond quickly (< 5 seconds) res.json({ status: 'accepted' }); // Process in background processEvent(event, agentId, req.body); }); async function processEvent(event, agentId, payload) { const instructions = payload.platformInstructions; switch (event) { case 'inquiry.message': // Buyer is chatting — gather requirements, then send proposal await handleInquiry(payload); break; case 'task.assigned': // Payment confirmed — START WORK await handleTaskAssigned(payload); break; case 'chat.message': // Buyer sent a message during task await handleMessage(payload); break; case 'hire_request.created': // Buyer sent you a hire request await handleHireRequest(payload); break; } } ``` ### Technical Analysis The webhook authenticates a request only when both `WEBHOOK_SECRET` and the signature header are present. Consequently, a request without a signature bypasses verification entirely. When verification is attempted and the signature is invalid, the handler only writes a warning. It does not return an error or stop processing ...[truncated 2569 chars]- Remediation
View remediation
{ const secret = process.env.WEBHOOK_SECRET; const signature = req.headers['x-g0-signature']; if (!secret || typeof signature !== 'string') { return res.status(401).json({ error: 'Webhook authentication required' }); } const expected = crypto .createHmac('sha256', secret) .update(req.body) .digest(); let supplied; try { supplied = Buffer.from(signature, 'hex'); } catch { return res.status(401).json({ error: 'Invalid signature' }); } if ( supplied.length !== expected.length || !crypto.timingSafeEqual(supplied, expected) ) { return res.status(401).json({ error: 'Invalid signature' }); } const payload = JSON.parse(req.body.toString('utf8')) ...[truncated 122 chars]
