Security rules

NGB050: document.domain relaxation

Reports assignments to document.domain and responses that opt back into it with the Origin-Agent-Cluster: ?0 header (in hosting configs, _headers files or server code)..

Property Value
Rule ID NGB050
Category iframe & cross-window communication
Default severity medium
CWE CWE-942, CWE-346
Built-in presets recommended: error, strict: error

Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.

What it checks

Reports assignments to document.domain and responses that opt back into it with the Origin-Agent-Cluster: ?0 header (in hosting configs, _headers files or server code).

Why it matters

Setting document.domain = 'example.com' lets every page on every subdomain that does the same script your page directly — the same-origin policy is reduced to the registrable domain, so an XSS on a forgotten blog.example.com becomes an XSS on app.example.com. Browsers are removing the feature (origin-keyed agent clusters make the setter a no-op by default), and Origin-Agent-Cluster: ?0 exists only to re-enable it.

Detection behavior and supported patterns

  • document.domain = value where document is the DOM Document (also via inject(DOCUMENT))
  • Origin-Agent-Cluster: ?0 in firebase.json, vercel.json, staticwebapp.config.json, _headers, or setHeader('Origin-Agent-Cluster', '?0')

Example

TypeScript
document.domain = 'example.com';

Safer alternative

TypeScript
parentWindow.postMessage({ type: 'resize', height }, 'https://www.example.com');

Remediation

Remove document.domain assignments and communicate between subdomains with postMessage (with strict origin checks, NGB007) or a shared backend. Do not send Origin-Agent-Cluster: ?0.

False-positive considerations

  • Legacy integrations that still require cross-subdomain scripting are reported; plan their migration to postMessage.

Known limitations

  • Third-party scripts that set document.domain are not visible.
  • Reading document.domain is not reported.

References

Run it

Shell
ngbastion explain NGB050