Course contentsShow
← Security
Lesson 880 of 3,05218. Web Security - CSRF and Request ForgeryFree lesson

Pre-Domain Wildcard and Null Origin Attacks

Leveraging null origin contexts and pre-domain wildcards to bypass CORS restrictions.

Pre-Domain Wildcard and Null Origin Attacks

What you'll learn: How attackers exploit wildcard patterns and null origins to bypass CORS restrictions even when servers think they're being careful.

The Core Idea

When servers try to validate origins for CORS, they sometimes use pattern matching that can be tricked. Two common bypass techniques are:

  1. Pre-domain wildcard attacks: The server checks if the origin ends with a trusted domain (like .trusted.com) but doesn't verify what comes before it.
  2. Null origin attacks: Some contexts (like sandboxed iframes or file:// protocols) send Origin: null, and some servers mistakenly allow this.

Pre-Domain Wildcard Bypass

Imagine a server that checks: "Does the origin end with bank.com?"

The developer might write code that accepts anything matching *.bank.com, but the validation is flawed. An attacker could register evilbank.com or notbank.com and pass the check if the server only validates the suffix without checking for proper subdomain structure.

Example scenario:

  • Trusted origin: https://accounts.bank.com
  • Attacker registers: https://accounts.bank.com.evil.com
  • Poorly written validation accepts it because it "contains" the trusted domain

Null Origin Exploitation

Some browsers send Origin: null in special contexts:

  • Sandboxed iframes with specific flags
  • Local file:// access
  • Redirected requests in certain scenarios

If a server has this in its allowed origins list or doesn't properly reject null origins, an attacker can create a sandboxed iframe on their malicious site that sends requests with Origin: null.

<iframe sandbox="allow-scripts allow-same-origin" src="data:text/html,<script>/* attack code */</script>">

Prevention

Always use exact origin matching, never substring matching. Never allowlist null as an origin.

Key Takeaway: Wildcard and null origin bypasses exploit loose pattern matching in CORS validation—always use exact, explicit origin checks and reject null origins entirely.