Lesson 12 of 19 · 18m
CORS, Redirects, and Other Origin Confusion
Reflected Access-Control-Allow-Origin with credentials, prefix-checked redirect_uris, '//evil.com' open redirects, and postMessage('*').
Your API reads the incoming Origin header and writes it back out as Access-Control-Allow-Origin, plus Access-Control-Allow-Credentials: true. It works in dev, it works in staging, every origin "just works" — and you have now told every website on the internet that they may issue authenticated cross-origin requests through your users' browsers and read the responses. The CORS spec forbids Access-Control-Allow-Origin: * combined with credentials for exactly this reason, so developers "fix" the preflight failure by reflecting the origin instead — which is the same bug wearing a workaround.
The wrong mental model: CORS is a security boundary. It is not — it is a read permission the browser enforces on JavaScript. Simple requests (form posts, plain GETs, requests without custom headers) are sent cross-origin whether the server grants permission or not; the response just can't be read by the page. The actual security model is a two-part question: can the request be sent (CSRF, SameSite, token checks — the previous lesson) and can the response be read (CORS). Misconfigured CORS answers the second part wrongly.
The misconfigurations that matter
# Request: Origin: https://evil.com
# Response you shipped:
Access-Control-Allow-Origin: https://evil.com
Access-Control-Allow-Credentials: trueAny script running anywhere now reads your authenticated API through the victim's session. The rule is boring: compare Origin against an explicit allowlist of exact origins — https://app.example.com, https://staging.example.com — and set Vary: Origin so caches don't serve one origin's CORS grant to another. Two traps inside that rule:
- The
nullorigin. Sandboxed iframes,file://pages, and redirects can legitimately sendOrigin: null. Apps add"null"to the allowlist to make local tooling work, and then any attacker who wraps their page in a sandboxed iframe inherits it. If anullorigin appears in production, something is misconfigured; never allowlist it. - Regex on strings instead of host comparison.
origin.endsWith("example.com")acceptsnotexample.com. Parse the URL, compare scheme + host + port.
Redirect validation is the same bug one layer up
An open redirect — GET /login?next=//evil.com followed by a naive Location: header — is not only a phishing vector. It becomes lethal when it sits inside an auth flow, because OAuth callbacks carry codes and tokens in URLs. The redirect_uri parameter in OAuth exists to contain this, and RFC 6749 §3.1.2 is blunt about how: the authorization server must compare the client's redirect_uri against registered values — exact string match, not prefix, not suffix, not substring. redirect_uri.startsWith("https://app.example.com") accepts https://app.example.com.evil.com. Parse and compare exactly, or maintain an exact-match allowlist table.
Then the paired trap: next = "/dashboard"-style parameters inside your own app. The junior fix is next.startswith("/") — and //evil.com sails through, because it is scheme-relative. Browsers resolve //evil.com/path to https://evil.com/path. The correct check is next.startswith("/") and not next.startswith("//") — or better, parse the URL and require an empty host, or map the destination through an internal route table.
postMessage is the third door
iframe.contentWindow.postMessage(token, "*") sends that token to whatever origin is in the frame — including the attacker's page after a redirect, a hijacked ad frame, or a swapped URL. The second argument is the target origin and it exists for a reason: spell it — "https://embed.example.com" — and on the receiving side always check event.origin against your own allowlist before reading event.data.
Try this
curl -i -H 'Origin: https://evil.com' https://your-api/endpoint and look at what comes back in Access-Control-Allow-Origin. If it echoes the request's origin with Allow-Credentials: true, that is the finding, not the setup step. Then try https://your-app/login?next=//evil.com and ?next=https://app.example.com.evil.com — does the redirect fire?
Pitfalls
- "Preflight passed" is not a defense. Simple requests never preflight; they just can't be read.
Vary: Originmissing lets a shared cache hand one origin's permissive CORS headers to every other origin.- Redirect_uri "validated by contains" —
in/contains/startsWithall fold under attacker-registered subdomains or path tricks. - Reflecting
Originto fix a dev-time preflight error — the fix that ships forever. postMessagewith"*"on both ends — any frame in the window can claim the message.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Building a Production REST API With Node.js and Express
Build a REST API in Node.js and Express the way production systems need: input validation, JWT auth, refresh token rotation, status codes, rate limiting, idempotency keys, and centralized error handling.
Node.js Fixed 16 Flaws in One Release. Most of Them Live in HTTP/2 and TLS.
The November 11 Node.js security releases fix 16 CVEs across the 26, 24 and 22 lines, seven of them rated high. Nearly all sit in HTTP/2 and TLS, where a remote client can crash a server, leak memory, or get past per-host client-certificate checks.
Next.js Shipped Seven Advisories and Six of Them Are the Cache
The November 2026 Next.js security release patches seven issues, and six live in the new Cache Components layer, the feature meant to make your app faster by remembering more. Three hit self-hosted next start specifically: the ones Vercel's own platform quietly absorbs.
Forum Archaeology: Nulled vBulletin, XenForo, and the Missing Footer
I could spot a nulled forum in about four seconds, and it never stopped being funny. Here's why the copyright line gives it away, what a measured 97% of nulled add-ons actually contain, and why MyBB quietly became the smart choice for everyone who wanted the look without the paper trail.