Claude MCP skill timing side-channel in authentication and feature enumeration — SA-SKL-TIMING4
Timing side-channels allow an attacker to extract secret information — HMAC key bytes, valid token prefixes, user plan status, valid resource IDs — by measuring response latency rather than inspecting response content. MCP skill APIs are particularly susceptible because they use HMAC signatures for webhook verification, short invite codes for onboarding, and sequential integer or UUID identifiers for audit results, all of which can be targeted by timing attacks when comparison logic is not constant-time. The four SA-SKL-TIMING4 patterns cover the most exploitable timing leaks found across community MCP skill codebases.
What makes timing attacks viable against MCP skill APIs
Timing attacks require the attacker to measure response latency precisely enough to distinguish between code paths that differ by microseconds. Modern high-bandwidth, low-jitter connections (especially same-datacenter calls from a cloud attacker VM to a cloud-hosted skill) reduce network jitter to the point where application-level timing differences of a few hundred microseconds are reliably measurable with enough samples. HMAC byte-by-byte comparison leaks the most significant byte's correctness in roughly 50 to 200 microseconds — detectable with 50–100 samples per byte at a 32-byte HMAC, requiring about 12,800 requests to recover a full key.
Lower-precision leaks — DB query timing (10–20 ms), 403 vs 404 response time (5–20 ms) — are exploitable with far fewer requests and are robust even over residential internet connections. These patterns are classified as MEDIUM to HIGH because they provide information that enables secondary attacks (brute-force, enumeration) rather than directly exposing secrets.
=== instead of crypto.timingSafeEqual; attacker recovers HMAC bytes one at a time via per-byte response time measurementTIMING4-001 — Webhook HMAC string comparison leaks bytes via response time
Webhook delivery systems sign the payload with an HMAC-SHA256 key and include the signature in a request header (X-Webhook-Signature: sha256=abc123...). The receiver verifies the signature by computing the expected HMAC and comparing it to the received value. If the comparison uses JavaScript's === operator (or !==), V8's string comparison returns false at the first byte that differs — without comparing the remaining bytes. By submitting signatures that differ at byte position 0, 1, 2, and so on, and measuring which submission takes fractionally longer (indicating a match up to that byte), an attacker can determine the correct HMAC one byte at a time. Recovery requires roughly 256 × 32 = 8,192 requests on a local network connection.
The fix is to use crypto.timingSafeEqual(), which always compares every byte of both buffers in constant time regardless of where the first difference occurs. The function takes two Buffer arguments of equal length; both inputs must be converted to Buffers before comparison.
// VULNERABLE — HMAC compared with string ===; leaks bytes via timing
import crypto from 'crypto';
import express from 'express';
const WEBHOOK_SECRET = process.env.WEBHOOK_SECRET!;
function verifyWebhookSignature(payload: Buffer, signature: string): boolean {
const expected = crypto
.createHmac('sha256', WEBHOOK_SECRET)
.update(payload)
.digest('hex');
// VULNERABLE: string === exits at first differing byte
// attacker measures response time to determine how many leading bytes match
// recovers full HMAC byte-by-byte in ~8,192 requests
return `sha256=${expected}` === signature;
}
app.post('/webhooks/github', express.raw({ type: '*/*' }), (req, res) => {
const sig = req.headers['x-hub-signature-256'] as string;
if (!verifyWebhookSignature(req.body, sig)) {
return res.status(401).json({ error: 'Invalid signature' });
}
processWebhookPayload(req.body);
res.sendStatus(200);
});
// FIXED — constant-time comparison via crypto.timingSafeEqual
import crypto from 'crypto';
function verifyWebhookSignature(payload: Buffer, signature: string): boolean {
const expected = crypto
.createHmac('sha256', WEBHOOK_SECRET)
.update(payload)
.digest('hex');
const expectedBuf = Buffer.from(`sha256=${expected}`);
const receivedBuf = Buffer.from(signature);
// timingSafeEqual requires equal-length buffers — if lengths differ, signatures
// cannot match; return false without exposing length information via timing
if (expectedBuf.length !== receivedBuf.length) {
return false;
}
// Always compares every byte — no short-circuit on first mismatch
return crypto.timingSafeEqual(expectedBuf, receivedBuf);
}
app.post('/webhooks/github', express.raw({ type: '*/*' }), (req, res) => {
const sig = req.headers['x-hub-signature-256'] as string;
// Reject missing signature without calling timingSafeEqual
if (!sig || !sig.startsWith('sha256=')) {
return res.status(401).json({ error: 'Missing signature' });
}
if (!verifyWebhookSignature(req.body, sig)) {
return res.status(401).json({ error: 'Invalid signature' });
}
processWebhookPayload(req.body);
res.sendStatus(200);
});
TIMING4-002 — Invite code redemption timing enables brute-force
Onboarding invite codes in MCP skill platforms are typically 8–12 character alphanumeric strings. When an invite code is submitted, the handler queries the database: if the code exists and is unredeemed, the query returns a row (2ms); if the code does not exist, the query returns nothing and the handler returns 404 immediately (0ms). This 2ms difference is reliably measurable over a local network connection and indicates whether a submitted code is structurally valid (exists in the DB) versus invalid (does not exist). An attacker can use timing to enumerate which codes have been issued before brute-forcing the remaining entropy, dramatically reducing the search space for a code that belongs to a high-value user (such as an admin invite code).
The fix pads all invite code responses to a minimum constant-time floor, ensuring that the response latency reveals nothing about whether the code was found in the database. Using await new Promise(r => setTimeout(r, 10)) before all responses ensures at least 10ms regardless of DB outcome.
// VULNERABLE — valid codes take 2ms (DB hit); invalid take 0ms (immediate 404)
app.post('/api/invite/redeem', async (req, res) => {
const { code } = req.body;
// VULNERABLE: DB query returns in 2ms if code exists, 0ms if not
// attacker distinguishes valid codes from invalid by measuring response time
// reduces brute-force search from 36^8 to only valid code space
const invite = await db.query(
'SELECT * FROM invites WHERE code = ? AND redeemed_at IS NULL',
[code]
);
if (!invite) {
return res.status(404).json({ error: 'Invalid invite code' });
}
await redeemInvite(invite.id, req.user.id);
res.json({ success: true });
});
// FIXED — constant-time minimum floor regardless of DB outcome
app.post('/api/invite/redeem', async (req, res) => {
const { code } = req.body;
const start = Date.now();
const invite = await db.query(
'SELECT * FROM invites WHERE code = ? AND redeemed_at IS NULL',
[code]
);
// Constant-time minimum: always wait at least MIN_RESPONSE_MS before responding
// attacker cannot distinguish "code exists in DB" from "code not found"
const MIN_RESPONSE_MS = 10;
const elapsed = Date.now() - start;
if (elapsed < MIN_RESPONSE_MS) {
await new Promise(r => setTimeout(r, MIN_RESPONSE_MS - elapsed));
}
if (!invite) {
// Same response body shape for both failure modes — no length difference
return res.status(404).json({ error: 'Invalid or expired invite code' });
}
await redeemInvite(invite.id, req.user.id);
res.json({ success: true });
});
TIMING4-003 — Premium feature flag DB query timing leaks plan status
When a user requests a resource that is behind a feature flag (e.g., a premium API endpoint), the handler queries the database to check whether the user has a premium record. Users with a premium subscription have a row in the subscriptions table that the query finds in roughly 15ms (index hit plus row read). Users without a premium subscription cause a full index scan that returns no row in roughly 2ms (table miss). The 13ms difference is measurable without authentication — an attacker can probe any user's plan status by user ID or email, building a map of which accounts are premium before targeting them for social engineering or account takeover attempts.
// VULNERABLE — premium check timing leaks plan status to unauthenticated callers
app.get('/api/users/:userId/premium-badge', async (req, res) => {
// No authentication required for public badge endpoint
const { userId } = req.params;
// VULNERABLE: 15ms if user has premium record (index hit + row read)
// 2ms if user has no premium record (index scan, no row)
// attacker enumerates which user IDs have premium plan via timing
const sub = await db.query(
'SELECT plan FROM subscriptions WHERE user_id = ? AND active = 1',
[userId]
);
res.json({ premium: !!sub, userId });
});
// FIXED — constant-time minimum floor; normalise response timing
app.get('/api/users/:userId/premium-badge', async (req, res) => {
const { userId } = req.params;
const start = Date.now();
const sub = await db.query(
'SELECT plan FROM subscriptions WHERE user_id = ? AND active = 1',
[userId]
);
// Always wait at least 20ms — longer than the worst-case DB query
// so timing carries no information about whether a row was found
const MIN_RESPONSE_MS = 20;
const elapsed = Date.now() - start;
if (elapsed < MIN_RESPONSE_MS) {
await new Promise(r => setTimeout(r, MIN_RESPONSE_MS - elapsed));
}
res.json({ premium: !!sub, userId });
});
TIMING4-004 — 403 vs 404 response time enumerates valid audit IDs
When an authenticated user requests an audit result that belongs to another user, the response depends on whether the audit ID exists in the database. A fast path check for ownership can return 403 "not your audit" in 5ms by checking the user ID on the already-fetched row. A missing audit ID takes 20ms because the database query must scan the index, find nothing, and return a not-found result. By measuring response time, an attacker can distinguish "audit ID exists (but belongs to someone else)" from "audit ID does not exist" — revealing which audit IDs are valid without reading the audit content. This enables the attacker to build a list of valid audit IDs for other users, which can then be targeted in IDOR attempts or leaked to competitors.
// VULNERABLE — 403 (5ms fast path) vs 404 (20ms DB query) enumerates valid IDs
app.get('/api/audits/:id', requireAuth, async (req, res) => {
const { id } = req.params;
// VULNERABLE: two code paths with different DB query costs
// Path A: audit exists, belongs to req.user.id → 5ms (row read + ownership check)
// Path B: audit exists, belongs to other user → 5ms (row read, ownership fail) → 403
// Path C: audit does not exist → 20ms (full index scan, no row) → 404
// attacker distinguishes B from C by timing → enumerates valid audit IDs
const audit = await db.query('SELECT * FROM audits WHERE id = ?', [id]);
if (!audit) {
return res.status(404).json({ error: 'Audit not found' });
}
if (audit.user_id !== req.user.id) {
return res.status(403).json({ error: 'Access denied' });
}
res.json(audit);
});
// FIXED — constant-time minimum floor; single error message for all negative cases
app.get('/api/audits/:id', requireAuth, async (req, res) => {
const { id } = req.params;
const start = Date.now();
const audit = await db.query('SELECT * FROM audits WHERE id = ?', [id]);
// Determine outcome before any early return — prevents fast-path timing leaks
const found = !!audit;
const owned = found && audit.user_id === req.user.id;
// Constant-time minimum — always wait at least 25ms regardless of outcome
const MIN_RESPONSE_MS = 25;
const elapsed = Date.now() - start;
if (elapsed < MIN_RESPONSE_MS) {
await new Promise(r => setTimeout(r, MIN_RESPONSE_MS - elapsed));
}
if (!owned) {
// Same status and message for both "not found" and "not yours" —
// attacker cannot distinguish the two cases by timing or by message content
return res.status(404).json({ error: 'Audit not found' });
}
res.json(audit);
});
Detection with SkillAudit
SkillAudit's SA-SKL-TIMING4 rule set detects timing side-channels through static analysis and active timing probes. The static pass flags HMAC or token comparisons that use ===, !==, or string comparison methods on cryptographic material, and identifies route handlers where early-return paths before a database query create timing differences. The active probe submits known-valid and known-invalid inputs (invite codes, webhook signatures, audit IDs) and statistically analyses response latency distributions to detect exploitable timing separation. See also SA-SKL-CRYPTO2 for weak token generation patterns that increase the impact of timing-assisted brute-force attacks.
Run SA-SKL-TIMING4 on your skill: Paste your MCP skill's GitHub URL at skillaudit.dev to get a full scan. The free tier covers public repositories and returns a shareable security badge.
| Finding | Severity | Vulnerable pattern | Fix |
|---|---|---|---|
TIMING4-001 | Critical | HMAC signature comparison via ===; short-circuits at first byte mismatch; byte-by-byte recovery in ~8,192 requests | crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(received)) — always compares all bytes |
TIMING4-002 | High | Invite code DB hit (2ms) vs miss (0ms); timing distinguishes valid codes from invalid; brute-force search space reduced | Constant-time minimum floor of 10ms on all invite redemption responses regardless of DB outcome |
TIMING4-003 | Medium | Premium DB query: 15ms (row found) vs 2ms (no row); unauthenticated callers identify premium users by timing | Minimum 20ms floor on all plan-check endpoints; response time carries no information about DB hit/miss |
TIMING4-004 | Medium | 403 fast-path (5ms) vs 404 DB scan (20ms); attacker enumerates valid audit IDs without reading content | Single code path for all negative outcomes; constant 25ms minimum; same error message for 403 and 404 cases |