Skip to main content
HighCookiesOWASP A07:2021CWE-384

How to fix: Cookie Prefix Injection via User-Controlled Subdomain

If user-controlled values (subdomain names, host headers, redirect targets) flow into cookie names without validation, an attacker can craft __Host- or __Secure- prefixed cookies from a controlled subdomain, enabling cookie fixation attacks.

Why it matters

An attacker who controls a subdomain or can inject a Host header can set __Host- prefixed cookies, which may overwrite the application's legitimate __Host- session cookie and fix a known session ID for session hijacking.

User-controlled values should never be used as cookie names. An attacker who can set a cookie named __Host-session from a compromised subdomain can fix a session ID and wait for an admin to log in with that fixed session.

How to fix it

  1. 1Never let user input flow into cookie names.
  2. 2Hard-code __Host-/__Secure- cookie names on the server; never derive them from request data.
  3. 3Audit subdomain takeover surface and co-tenanted subdomains.

Code examples

Validate cookie names server-side

TypeScript
// Never dynamically derive cookie names from user input
const COOKIE_NAME = '__Host-session'; // Hard-coded constant

res.setHeader('Set-Cookie',
  `${COOKIE_NAME}=${sessionId}; Path=/; Secure; HttpOnly; SameSite=Lax`);

References

Detected automatically by VulnRadar. The check id is cookie-host-prefix-injection-subdomain, stable across every scan so you can filter or diff on it.

See every cookies check

Questions

How severe is Cookie Prefix Injection via User-Controlled Subdomain?
VulnRadar rates this high severity in the cookies category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id cookie-host-prefix-injection-subdomain, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Cookie Prefix Injection via User-Controlled Subdomain map to?
It maps to CWE-384. In the OWASP Top 10 it falls under A07:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for cookie prefix injection via user-controlled subdomain

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Cookie Prefix Injection via User-Controlled Subdomain | VulnRadar