Claude skill cache poisoning security — SA-SKL-CACHEPOISON
HTTP cache poisoning targets MCP skills that sit behind a CDN or reverse proxy by exploiting the gap between how the cache decides what to store (the cache key) and what gets included in the response body. SkillAudit finds four consistent patterns: authenticated responses cached without Cache-Control: private so user-specific audit data is served to other users, unvalidated X-Forwarded-Host headers used in link generation that an attacker can inject to poison the cache with attacker-controlled URLs, unkeyed tracking query parameters reflected in the cached response body, and CDN caching of large GET requests that behave more like POST operations. SA-SKL-CACHEPOISON-001 through CACHEPOISON-004 cover each with the cache poisoning mechanic and fix.
How cache poisoning differs from cache misconfigurations
Cache misconfigurations serve incorrect data by accident — a cache TTL that is too long, a missing cache-bust on a deploy. Cache poisoning is an active attack: an adversary crafts a specific request that causes the cache to store a malicious or attacker-controlled response, which is then served to all subsequent users who request the same resource. The attack surface in MCP skills is typically the gap between what the CDN (Cloudflare, Fastly) uses as its cache key (usually just method + URL) and what the Node.js application uses to generate the response (URL + headers + request body + session data). Inputs that influence the response body but are not part of the cache key are the poisoning surface.
SA-SKL-CACHEPOISON in scope: CACHEPOISON-001 (authenticated response cached without Cache-Control: private), CACHEPOISON-002 (X-Forwarded-Host used in response without validation), CACHEPOISON-003 (unkeyed query parameter reflected in response body), CACHEPOISON-004 (CDN caches GET with significant request body). Each includes the cache key analysis, attack scenario, and fix.
CACHEPOISON-001 — CDN caches authenticated response
MCP skills that return user-specific data — audit reports, badge data, subscription info — via GET endpoints are cacheable by default from the CDN's perspective unless the response includes Cache-Control: private or Cache-Control: no-store. Without this header, a CDN may cache the response from user A's first request and serve it to user B who requests the same URL moments later. User B receives user A's private audit data. This is especially damaging for audit report endpoints where the URL is the audit ID: once one user's audit result is cached, every subsequent request for that URL receives the cached result regardless of whether the requester owns the audit.
// VULNERABLE: audit report endpoint missing Cache-Control header
app.get('/api/audits/:auditId/report', requireAuth, async (req, res) => {
const audit = await db.audits.findOne({
id: req.params.auditId,
userId: req.session.userId, // Ownership check is correct
});
if (!audit) return res.status(404).json({ error: 'Not found' });
// No Cache-Control header — CDN may cache this response
// User B requests /api/audits/abc123/report → gets user A's report from cache
res.json({ report: audit.report, userId: audit.userId, repoUrl: audit.repoUrl });
});
// FIXED: Cache-Control: private, no-store on all authenticated responses
app.get('/api/audits/:auditId/report', requireAuth, async (req, res) => {
const audit = await db.audits.findOne({
id: req.params.auditId,
userId: req.session.userId,
});
if (!audit) return res.status(404).json({ error: 'Not found' });
// FIXED: Cache-Control: private prevents CDN from caching
// no-store prevents browser and intermediate caches from storing
res.set('Cache-Control', 'private, no-store');
res.set('Vary', 'Cookie'); // Instruct CDN to vary by session cookie if it ignores no-store
res.json({ report: audit.report });
});
Cache-Control: private or Cache-Control: no-store; a CDN or reverse proxy may cache the first user's response and serve it to subsequent requesters of the same URL, disclosing private audit reports, subscription details, or account data to unauthorized users. Fix: add res.set('Cache-Control', 'private, no-store') as middleware on all authenticated routes; use Vary: Cookie as a secondary safeguard. Detection: SkillAudit flags route handlers behind requireAuth middleware that return JSON without setting Cache-Control: private or Cache-Control: no-store.CACHEPOISON-002 — Unvalidated X-Forwarded-Host in cached response
When a CDN or load balancer forwards requests to an origin server, it typically includes an X-Forwarded-Host header containing the original HTTP Host value seen by the CDN. MCP skills that generate absolute URLs — for password reset emails, OAuth redirect URIs, canonical link tags, or Open Graph URLs — sometimes read this header to construct the base URL. If X-Forwarded-Host is not validated against an allowlist, an attacker can send a request with a crafted value like X-Forwarded-Host: evil.com. If the CDN caches the resulting response (which contains evil.com in all absolute URLs), subsequent users who receive that cached response will see links pointing to the attacker's domain.
// VULNERABLE: X-Forwarded-Host used in OG URL generation without validation
app.get('/audit/:id/badge', async (req, res) => {
const audit = await db.audits.findOne({ id: req.params.id, public: true });
if (!audit) return res.status(404).end();
// VULNERABLE: host derived from X-Forwarded-Host without validation
const host = req.headers['x-forwarded-host'] || req.headers.host;
const badgeUrl = `https://${host}/audit/${req.params.id}/badge.svg`;
// Response is public (no auth) → CDN may cache it
// Attacker sends request with X-Forwarded-Host: evil.com
// Cached badge page contains evil.com in OG image URL
res.send(``);
});
// FIXED: host derived from environment config, never from request headers
const APP_ORIGIN = process.env.APP_ORIGIN || 'https://skillaudit.dev'; // Set in .env
app.get('/audit/:id/badge', async (req, res) => {
const audit = await db.audits.findOne({ id: req.params.id, public: true });
if (!audit) return res.status(404).end();
// FIXED: absolute URL built from trusted env variable, not request headers
const badgeUrl = `${APP_ORIGIN}/audit/${req.params.id}/badge.svg`;
// If you must accept forwarded host, validate against allowlist:
// const ALLOWED_HOSTS = new Set(['skillaudit.dev', 'www.skillaudit.dev']);
// const fwdHost = req.headers['x-forwarded-host'];
// const host = fwdHost && ALLOWED_HOSTS.has(fwdHost) ? fwdHost : 'skillaudit.dev';
res.set('Cache-Control', 'public, max-age=300, stale-while-revalidate=60');
res.send(``);
});
req.headers['x-forwarded-host'] without validating against an allowlist; an attacker can inject an arbitrary host value that is embedded in the publicly cached response, poisoning the CDN cache with attacker-controlled URLs visible to all subsequent users. Fix: derive base URL from a trusted environment variable (APP_ORIGIN); if X-Forwarded-Host is required, validate against a Set of known-good hostnames before use. Detection: SkillAudit flags response bodies that interpolate req.headers['x-forwarded-host'] or req.headers['x-forwarded-proto'] into URLs returned in HTML or JSON.CACHEPOISON-003 — Unkeyed query parameter reflected in cached response
UTM and tracking query parameters (?utm_source=, ?ref=, ?campaign=) are commonly added to URLs for marketing attribution. CDNs typically strip or ignore these parameters when computing the cache key — they cache /blog/security-tips and treat /blog/security-tips?utm_source=twitter as the same resource. If the Node.js application reflects the utm_source parameter in the response body (in an analytics script, in a "share this link" button, or in a redirect URL), the response body will differ across requests with different UTM values. The CDN stores the first version it sees (with utm_source=twitter) and serves it to all subsequent requesters — including those who arrive via organic search and would not normally receive a Twitter-attributed response.
// VULNERABLE: utm_source from query string reflected in response body
app.get('/blog/:slug', async (req, res) => {
const post = await db.posts.findOne({ slug: req.params.slug });
if (!post) return res.status(404).end();
const utmSource = req.query.utm_source || '';
// VULNERABLE: utm_source reflected in response body — CDN doesn't key on it
// CDN caches /blog/webauthn-passkey?utm_source=evil as the canonical response
// All subsequent /blog/webauthn-passkey requests receive the poisoned version
res.send(`
${post.content}
`);
});
// FIXED: UTM parameters never reflected in server-rendered response
// Tracking parameters handled client-side from window.location.search only
app.get('/blog/:slug', async (req, res) => {
const post = await db.posts.findOne({ slug: req.params.slug });
if (!post) return res.status(404).end();
// UTM params stripped from server response — read by analytics client-side:
// analytics.track({ source: new URLSearchParams(location.search).get('utm_source') })
res.set('Cache-Control', 'public, max-age=3600, stale-while-revalidate=300');
// If using Cloudflare: set Page Rule to strip tracking params from cache key
res.send(`${post.content}`);
});
utm_source, ref, campaign) in server-rendered response bodies; CDNs typically omit these parameters from cache keys so the first request's reflected value is cached and served to all subsequent requesters, poisoning the response with an attacker-controlled attribution value. Fix: never reflect UTM/tracking parameters in server-rendered responses; handle them client-side only from window.location.search; in Cloudflare, use Transform Rules to remove tracking query params from the cache key. Detection: SkillAudit flags server-side route handlers that interpolate req.query.utm_* or req.query.ref into rendered response bodies.CACHEPOISON-004 — CDN caches GET with request body
REST convention reserves GET for idempotent reads and POST for mutations. Some MCP skill search and filter APIs accept GET requests with significant JSON bodies for filter parameters, treating them as POST-style operations because the URL is then shareable. CDNs key on method + URL and do not include the request body in the cache key (HTTP caching semantics define GET as not having a meaningful body). If the application generates different responses for different request bodies on the same URL, the CDN stores the first response and serves it to all subsequent requests regardless of body content. An attacker who sends a crafted request body first can poison the cache for all subsequent users of that endpoint.
// VULNERABLE: GET endpoint with meaningful request body — CDN ignores body in cache key
app.get('/api/audits/search', requireAuth, async (req, res) => {
// Accepts filter criteria in request body (non-standard)
const { repoPattern, minGrade, dateRange } = req.body;
const results = await db.audits.search({ repoPattern, minGrade, dateRange });
// CDN keys on GET /api/audits/search only
// First request body wins — all subsequent users get the same filtered results
res.json({ results });
});
// FIXED: use POST for requests with meaningful bodies; GET uses query params only
// Option A: convert to POST (not cacheable by default)
app.post('/api/audits/search', requireAuth, async (req, res) => {
res.set('Cache-Control', 'private, no-store'); // POST is not cached by CDN
const { repoPattern, minGrade, dateRange } = req.body;
const results = await db.audits.search({ repoPattern, minGrade, dateRange });
res.json({ results });
});
// Option B: encode filters in query params (GET remains cacheable per user)
// GET /api/audits/search?pattern=github.com%2F*&grade=B&from=2026-01-01
app.get('/api/audits/search', requireAuth, async (req, res) => {
res.set('Cache-Control', 'private, no-store'); // User-specific — not for CDN
const { pattern, grade, from } = req.query;
const results = await db.audits.search({ repoPattern: pattern, minGrade: grade });
res.json({ results });
});
Cache-Control: private, no-store on all authenticated search/filter endpoints. Detection: SkillAudit flags GET route handlers that read req.body for filter or query parameters.SkillAudit detection summary — SA-SKL-CACHEPOISON
| Pattern ID | Severity | What SkillAudit flags | Fix |
|---|---|---|---|
| CACHEPOISON-001 | HIGH | Authenticated route handlers returning JSON/HTML without Cache-Control: private or no-store | res.set('Cache-Control', 'private, no-store') on all authenticated routes |
| CACHEPOISON-002 | HIGH | Response bodies that interpolate req.headers['x-forwarded-host'] into URLs | Derive base URL from APP_ORIGIN env var; validate forwarded host against allowlist |
| CACHEPOISON-003 | MEDIUM | Server-side route handlers that interpolate req.query.utm_* into rendered response bodies | Handle UTM params client-side only; strip from server responses |
| CACHEPOISON-004 | MEDIUM | GET route handlers that read req.body for filter or query parameters | Use POST for body-driven queries; encode GET filters as query strings |
Related patterns: For cross-user data leakage via in-memory or Redis cache without user-scoped keys, see SA-SKL-MEMCACHE. For CORS misconfiguration that allows cross-origin requests to read cached responses, see SA-SKL-CORS2.