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
- 1Never let user input flow into cookie names.
- 2Hard-code __Host-/__Secure- cookie names on the server; never derive them from request data.
- 3Audit subdomain takeover surface and co-tenanted subdomains.
Code examples
Validate cookie names server-side
// 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.
More cookies checks
- LowCookie Domain Attribute Is Too Broad
- LowCookie Missing Secure Attribute
- InfoThird-Party Cookie Missing Partitioned Attribute
- High__Host- Prefix Cookie Missing Secure Attribute
- High__Host- Prefix Cookie with Non-Root Path
- High__Secure- Prefix Cookie Missing Secure Attribute
- LowCookie Expires/Max-Age Exceeds 1 Year
- InfoCookie Name Leaks Framework or Language
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.