Referer and Origin Validation Bypasses

Failures of header-based CSRF defenses (Origin, Referer, Sec-Fetch-Site): fail-open on a missing header, substring/regex matching, exempt entry points, trusting same-site, and browser behaviors that put the target’s own origin into an attacker-triggered request’s Referer.

How it works

Origin, Referer and Sec-Fetch-* are forbidden headers, so page JS cannot forge them — the defense is sound only if the comparison is an exact origin match and absence fails closed. Practical gaps:

  • Absence. Browsers omit Referer under Referrer-Policy: no-referrer / <meta name="referrer" content="no-referrer"> (or legacy never) / referrerpolicy attributes; Origin is missing on many same-origin GETs and some form posts, and Origin: null appears under no-referrer in Chromium form POSTs. Missing or null is not evidence of same-origin.
  • Loose matching. includes/startsWith/unanchored regex accept https://target.com.evil.tld, https://evil.tld/?target.com, https://evil.tld/target.com.
  • Site vs origin. Sec-Fetch-Site: same-site is honest for sibling subdomains; policies that trust same-site (or only reject cross-site) inherit every sibling’s XSS, upload and takeover risk.
  • Header not evaluated. Middleware that skips the check for some content types (text/ping), routes (exemption lists) or “index” pages.
  • Referer = target via sub-resources. Under default strict-origin-when-cross-origin, a request initiated by a stylesheet or JS module hosted on the target carries the target’s origin as Referer, even when the attacker’s page linked that resource.

Techniques / payloads

Suppress Referer:

<meta name="referrer" content="no-referrer">
<form action="https://target/admin.php?action=installmodule" method="POST"
      referrerpolicy="no-referrer" enctype="multipart/form-data">…</form>

Launder the trusted string into the Referer (substring checks):

<meta name="referrer" content="unsafe-url"> <!-- default policy strips the query -->
<script>history.pushState('', '', '/?target.com'); document.forms[0].submit()</script>

Sub-resource Referer (afine research): upload a file served as text/css whose url() points at a GET mutation on the target; link it from the attacker page with <link rel=stylesheet> — the resulting request’s Referer is the target. Only text/css works for stylesheets; cookies are not attached cross-site, so it becomes useful when linked from a same-site context. The JS-module variant has the same Referer behavior and accepts more content types but needs credentialed CORS for cookies.

Checklist:

  1. Remove Referer; remove Origin; send Origin: null.
  2. Lookalike prefix/suffix domains and query/path embedding.
  3. HTTP vs HTTPS and port variants (exact origin includes scheme and port).
  4. From a sibling subdomain: does Sec-Fetch-Site: same-site pass?
  5. Find entry points exempt from the check (index pages, OAuth/webhook routes) that redirect or chain into setters.
  6. Loopback/local services: missing Origin/Host checks enable DNS rebinding and browser-to-localhost CSRF.

Notable cases

Defenses

  • Exact match of Origin against an allow-list of full origins; fall back to Referer origin only when Origin is absent; reject when neither yields a trusted origin (and reject null).
  • Sec-Fetch-Site: allow same-origin (and none for user-typed navigations); treat same-site as untrusted unless every sibling is trusted; fall back to Origin checks when Sec-Fetch-* is missing. Go 1.25 http.CrossOriginProtection implements this.
  • Apply checks independent of content type, route and method; anchor any exemption.
  • Use as a layer with tokens, not instead — the afine sub-resource behavior shows Referer-only defenses are weaker than they appear.
  • Localhost services: validate Host and Origin.

Sources