How to fix: document.domain Reassigned to Relax the Same-Origin Policy
The page assigns document.domain to a literal string value. This is the standard API for deliberately relaxing the Same-Origin Policy so pages on different subdomains of that value can script each other directly.
Why it matters
Once document.domain is set, every subdomain that also sets the same value can read and write this page's DOM, cookies, and JavaScript state directly: no postMessage, no origin check. If any sibling subdomain is lower-trust or compromised (a marketing microsite, a staging environment, an old abandoned project), it gains full script access to this page.
document.domain relaxation is a legacy pre-postMessage technique for cross-subdomain scripting. It's deprecated in modern browsers (removal is underway behind Origin-keyed Agent Clusters) and widens the origin boundary from a specific subdomain to the entire parent domain, so trust in one subdomain implies trust in all of them.
How to fix it
- 1Replace document.domain-based cross-subdomain scripting with window.postMessage and explicit origin validation.
- 2If cross-subdomain state sharing is required, use a cookie scoped to the parent domain plus a server-side session, not direct DOM access.
- 3Audit every subdomain under the relaxed domain: a single compromised one now has full script access to this page.
Code examples
Use postMessage instead of domain relaxation
// Bad: opens this page to every sibling subdomain
document.domain = 'example.com';
// Good: explicit, origin-checked messaging
const ALLOWED = new Set(['https://accounts.example.com']);
window.addEventListener('message', (event) => {
if (!ALLOWED.has(event.origin)) return;
handle(event.data);
});References
Detected automatically by VulnRadar. The check id is cs-document-domain-relaxation, stable across every scan so you can filter or diff on it.
More client-side checks
- HighCSP Allows 'unsafe-inline' Scripts
- MediumCSP Allows 'unsafe-eval'
- HighpostMessage Without Origin Validation
- HighSensitive Data Stored in localStorage
- HighDOM XSS via location.hash Assignment
- Highdocument.write() in Page Scripts
- Higheval() in Client-Side JavaScript
- MediumExternal Script Without Subresource Integrity
Questions
- How severe is document.domain Reassigned to Relax the Same-Origin Policy?
- VulnRadar rates this medium severity in the client-side 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 cs-document-domain-relaxation, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does document.domain Reassigned to Relax the Same-Origin Policy map to?
- It maps to CWE-346. In the OWASP Top 10 it falls under A05: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.