Menu

CSP basics: allow only what you mean to run, not block everything
📰

CSP basics: allow only what you mean to run, not block everything

DEV Community: html·Masahiro Kurokawa·9 days ago
#OrdqGyQe
#devto2#devto#dev#script#policy
Long article (1729 words) — no AI summary yet.
Reading 0:00
15s threshold

Someone told you to add CSP, so you pasted the one line default-src 'self' . What actually changed? It is easy to end up with no idea.

CSP is not a way to block all scripts. It is an allowlist: you name what may run on the page, and everything else is stopped . Start from default-src 'self' and add only the sources you really use.

What CSP is

Picture the front desk at an event. There is a guest list, and only people on the list get in. Anyone else stays outside, even if they are standing at the door.

CSP (Content-Security-Policy) is one of the headers a server sends with its response. It tells the browser where this page may load scripts, styles, images, and frames from, and which inline code (written directly in the HTML) it may run.

Nothing about the page looks different. What changes is whether the browser runs or stops code you did not expect to be there.

Why it concerns you

A malicious script can be slipped into a form field on your page.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.