Frontend Security

XSS, CSRF, the same-origin policy, CORS, CSP, clickjacking, third-party scripts and supply chain — the browser-side half of a problem the server cannot solve alone.

The Browser Security Model

The origin as the unit of trust, the renderer as a sandbox, and four separate mechanisms answering four separate questions — mixing them up is why security fixes so often do nothing.

Q · What does the browser actually enforce on my behalf, and which mechanism answers which question?
The Same-Origin Policy

Embedding is allowed, reading is not — and the gap between "the request was sent" and "your code may see the answer" is where most browser security confusion lives.

Q · What exactly is my page prevented from doing to another origin, and what is it still perfectly free to do?
Cross-Site Scripting

Untrusted content becomes executable content. Your framework already escapes text interpolation — so every XSS in a modern application is at the exact place someone opted out.

Q · Which places in my UI turn data into code, and what is my framework already doing about it?
Sanitization and Trusted HTML

Escaping and sanitization are different operations solving different problems — and when you genuinely must render HTML, allowlist it, at render time, with something you did not write.

Q · I actually need to render HTML from an untrusted source. What is the correct way to do that?
Cross-Site Request Forgery

The browser attaches credentials to requests automatically, including ones another site caused. That helpfulness is the vulnerability, and it is why the defence has to be explicit.

Q · Why can another site make my API call succeed, and which defence matches my architecture?
CORS

A browser policy about whether script may read a cross-origin response. Not authentication, not a firewall, and not relevant to anything that is not a browser — plus the error message that lies to you.

Q · What is CORS actually deciding, and why does my console blame it for a server error?
Content Security Policy

A browser-enforced allowlist for what your page may execute and load. It caps the damage of an injection you missed — and `unsafe-inline` in the script directive turns the whole thing off.

Q · What can a Content Security Policy actually stop, and how do I ship one without breaking the application?
Clickjacking and Framing

Your interface, rendered inside someone else's page, with their content on top. The defence is one response header — and the wrong version of it locks out keyboard users instead.

Q · Who is allowed to put my page in a frame, and what can they do to a user who clicks in it?
Third-Party Scripts and the Supply Chain

A script tag grants full authority over your page. There is no partial trust, and the dependency you never chose is running in the same context as your login form.

Q · What am I actually granting when I add someone else's code to my page?