Security rules

NGB030: Permissive referrer policy

Reports explicit referrer policies that send full URLs to other origins: unsafe-url (medium) and no-referrer-when-downgrade (low).

Property Value
Rule ID NGB030
Category Security configuration
Default severity medium
CWE CWE-200, CWE-598
Built-in presets recommended: warn, strict: error

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

What it checks

Reports explicit referrer policies that send full URLs to other origins: unsafe-url (medium) and no-referrer-when-downgrade (low). Looks at <meta name="referrer"> and referrerpolicy attributes in index.html, referrerpolicy attributes in Angular templates, referrerPolicy in fetch() options and on elements, setAttribute('referrerpolicy', …), Referrer-Policy headers set in TypeScript (SSR) and in hosting configs.

Why it matters

Browsers default to strict-origin-when-cross-origin, which only sends the origin to other sites. Weakening it leaks complete URLs — password-reset tokens, invite codes, search terms, internal IDs — to every third-party image, script, iframe and link target through the Referer header. NGB017 reports secrets placed in URLs; this rule reports the setting that broadcasts them.

Detection behavior and supported patterns

  • <meta name="referrer" content="unsafe-url"> and <a|img|iframe|script|link referrerpolicy="…"> in index.html
  • Static referrerpolicy="…" attributes in component templates
  • fetch(url, { referrerPolicy: 'unsafe-url' }), el.referrerPolicy = '…', el.setAttribute('referrerpolicy', '…')
  • res.setHeader('Referrer-Policy', '…') / { 'Referrer-Policy': '…' } with constant values, and headers in firebase.json, vercel.json, staticwebapp.config.json, _headers
  • Comma-separated fallback lists are evaluated by their last token, as browsers do

Example

TypeScript
<meta name="referrer" content="unsafe-url">

Safer alternative

TypeScript
<meta name="referrer" content="strict-origin-when-cross-origin">

Remediation

Remove the override (the browser default strict-origin-when-cross-origin is safe), or set strict-origin-when-cross-origin, same-origin or no-referrer. Do not put secrets in URLs in the first place (NGB017).

False-positive considerations

  • An unsafe-url policy on a single element whose destination is your own origin leaks nothing; it is still reported because the setting is fragile.

Known limitations

  • Headers configured outside the repository (CDN, reverse proxy) are not visible; no finding is produced for them.
  • Dynamic policy values are not evaluated.

References

Run it

Shell
ngbastion explain NGB030