Security Headers and CORS: What the Least Dangerous Item on the List Actually Stops

Headers are last on every security list because alone they fix nothing. Set on an app whose bug we left in place, they stopped three separate attacks.

The same app served with no security headers let a stored comment run in the page, let a page on another origin read an authenticated response containing an e-mail address, a plan and a balance, and let that page embed the app in a frame, while with four headers set the comment did not run, the cross-origin read was blocked by the browser and the framing was refused

This is the finding every scanner reports and nobody acts on. Your app is missing security headers, your CORS is open to everything, and the report is four pages long.

Headers are last on every list because none of them fixes a bug. They decide what happens afterwards, when a bug you did not know about is already in your app. Which is the normal state of an app.

So we built an app with a real vulnerability in it, left the vulnerability exactly where it was, and changed nothing but the headers.

Watch it instead

Missing headers and open CORS is number 10 in our countdown of the security holes that turn up most often in apps built with AI.

Video: 31,000 AI-Built Apps Scanned: The 10 Security Holes That Actually Get You Hacked.
Watch it instead 31,000 AI-Built Apps Scanned: The 10 Security Holes That Actually Get You Hacked.
From the Back4app channel. This guide is the long version of its tenth position. Open on YouTube →

What changed when only the headers changed?

Three attacks stopped working, on an app that is still exactly as broken as it was:

The same app measured with and without four security headers: without them a stored comment containing markup ran in the page, a page on another origin read an authenticated response containing an e-mail address a plan and a balance, and another page embedded the app in a frame, while with the headers set the comment did not run, the cross-origin read was blocked and the framing was refused

The comment in that first row is the same one that read a session token out of local storage in our injection lab. The page that renders it unsafely is unchanged in both columns.

How we measured: three local Node servers — your app, your API, and a page on a different origin — opened in headless Chrome, with every answer read back out of the resulting DOM. Identical across two clean runs — the lab is in the repo.

What does a Content Security Policy actually block?

The execution, not the bug. Our page still builds its comment list with innerHTML, still stores markup, still hands the browser a tag with an event handler on it:

  no headers        a stored comment on the page:   the comment ran
  four headers set  a stored comment on the page:   the comment did not run

The policy is one line, and script-src 'self' is the part doing the work: an event handler written into the markup is not a script from your own origin, so it does not run.

content-security-policy: default-src 'self'; script-src 'self'; frame-ancestors 'none'

The header did not fix the vulnerability. It was the thing still standing when the vulnerability shipped.

That is the honest case for headers, and it is a better case than the usual one. They are not a fix and they are not a formality — they are the layer that assumes you were wrong about something.

Why is a reflected CORS origin worse than an asterisk?

Because a wildcard cannot carry credentials and a reflection can. This is what a configuration written to make the error message go away looks like:

// Stack: Node 22 | File: server.mjs — the version that leaks
h['access-control-allow-origin'] = origin || '*';   // whatever asked
h['access-control-allow-credentials'] = 'true';

A page on an entirely different origin then fetched our API with the visitor’s credentials and read the answer:

another origin reading your API:   read: {"email":"[email protected]","plan":"pro","balanceCents":128400}

Replacing the reflection with one explicit origin changed that to blocked by the browser, with no change to the API’s logic. The data was never protected by the API; it was protected by nothing, and then by a list.

How do you test whether framing is blocked?

Not with the iframe’s load event, which was wrong in our first run and would have published a wrong number. A frame that the headers refused still fires load, because the browser loads an error page in it.

The reliable check is whether the embedded page’s own script runs:

// Stack: browser JavaScript | File: server.mjs
if (window.parent !== window) window.parent.postMessage('app-loaded-in-a-frame', '*');

A blocked frame never executes that line, so no message arrives. With that fix, the result flipped from “the app loaded inside this page” to “not framed” once X-Frame-Options: DENY was set — and our first, wrong version had reported success in both columns.

The same app, four headers apart
0 of 4security headers sent by default
→
3separate attacks that stopped working
0lines of application code changed between the two runs
Measured with Node 22 and headless Chrome on macOS, 29 October 2026, across three local origins. Identical across two clean runs.

Where do you set them?

Wherever the response is produced, which is the practical difference between hosting options. If a server of yours is serving the files — a container, a Node process, a reverse proxy — the headers go in one block of configuration and apply to everything it serves from then on.

On a static host the mechanism varies: a headers file, a dashboard section, an edge configuration. All of them work, and all of them share one failure mode, which is that the setting exists and the response does not carry it.

So the step that matters is the last one: request your own page afterwards and read the headers that came back. The configuration is a claim; the response is the evidence.

When is a strict policy the wrong move?

When it breaks your app at the worst possible moment, which a tight Content Security Policy will do on a page that uses inline scripts, an analytics snippet, an embedded video or a font from somewhere else. Each of those needs a deliberate exception, and a policy shipped without testing those paths takes the site down for everybody.

The sensible order is to deploy the policy in report-only mode first, read what it would have blocked, and then enforce. That turns a risky change into a boring one, and it is the difference between a policy you keep and a policy you revert on the first support ticket.

Open CORS has a legitimate version too. A genuinely public, unauthenticated API — a price list, a status endpoint, public documentation — is reasonably readable from anywhere, and locking it down buys nothing. What is never reasonable is the combination of any origin and credentials, because that is not a public API, it is a private one with the door held open.

What should you check before your next deploy?

Request your own homepage and look at the response headers. Four lines tell you where you stand, and most apps send none of them.

Then make the same request to your API with an Origin header naming somebody else’s site. If the answer comes back with that origin reflected and credentials allowed, you have found the one in this post that leaks real data rather than merely allowing an attack to be easier.

Tagssecurityheaderscspcorsclickjackingdeployment

Frequently asked questions

Do security headers actually prevent anything?

Not on their own, and that is why they rank last. But set on an app whose vulnerability we deliberately left in place, they stopped three separate attacks: a stored comment stopped running, a page on another origin stopped reading an authenticated response, and the app could no longer be embedded in a frame.

What does a Content Security Policy stop?

Inline script, among other things, which is what most stored cross-site scripting relies on. Our page still contained the bug that renders a comment as markup; with a policy of script-src 'self' the comment no longer executed. The app was not changed between the two runs.

What is a CORS misconfiguration and why is reflecting the origin bad?

Reflecting whatever origin asked, while also allowing credentials, means any website can make your visitor's browser fetch your API as them and read the answer. Ours returned an e-mail address, a plan and a balance to a page on a different origin, which an allowlist of one origin then blocked.

Is an asterisk in Access-Control-Allow-Origin dangerous?

Less than reflecting the origin, because browsers refuse to send credentials to a wildcard. The genuinely dangerous combination is echoing the request's origin back together with allow-credentials, which is exactly what a config written to make the error go away produces.

How do I stop my site being embedded in someone else's page?

Send X-Frame-Options: DENY, or frame-ancestors 'none' in your Content Security Policy. Worth knowing how to test it: an iframe fires its load event even when the embed was refused, so the only reliable check is whether the embedded page's own script runs.

Where do I set security headers if I do not run a server?

In whatever serves your files. A container gives you the server config, so the headers are set once and apply to everything it serves. A static host usually has a headers file or a dashboard section; the thing to verify afterwards is the response itself, not the setting.

Further reading

Reviewed & verified by Back4app Engineering, Editorial review at Back4app

Tested Oct 29, 2026 — Local: macOS, arm64 · Node 22.21.1, no dependencies · Chrome headless · three local servers.

More from Back4app Engineering

Containers · tutorial

How to Host a Static Website on Back4app Containers With Docker and nginx [Full Repo]

Containers · tutorial

How to Deploy a Node.js App With Docker and a Database, Without Managing a Server [Full Repo]

Backend · tutorial

Your Frontend Talks Straight to the Database. Here Is How to Lock It Down [Full Repo]