October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

What Is a Content Security Policy (CSP)? Definition and How It Works

A content security policy (CSP) is a set of browser-enforced rules that controls what a web page can load or execute. Learn how directives work and what CSP can—and cannot—protect against.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A content security policy (CSP) is a set of rules that a website sends to a browser to control which resources a page can load or execute and how the page may behave. Browsers commonly receive it in the Content-Security-Policy HTTP response header. CSP can reduce the damage caused by injected content, including some cross-site scripting attacks, but it is a layer of defense—not a replacement for secure coding.

What does content security policy mean?

Content Security Policy, usually shortened to CSP, is a browser-enforced security mechanism. A site defines its policy; the browser applies those rules to the page, such as whether it may load scripts, images, or other resources from particular sources.

As an Amazon Associate I earn from qualifying purchases.

CSP is not simply a list of trusted programs. It is a collection of directives that govern specific resource types or behaviors. The W3C Content Security Policy specification describes CSP as a way for developers to control what a page fetches or executes. MDN’s CSP guide explains it as instructions from a website to a browser that restrict what the site’s code may do.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How is a CSP written?

A policy consists of directives separated by semicolons. A directive names the kind of resource or behavior it governs, and its value specifies the sources or rules that apply. For example:

Content-Security-Policy: default-src 'self'; img-src 'self' example.com

In this example, default-src 'self' sets a fallback for fetch directives that do not have their own rule. The img-src directive separately allows images from the site’s own origin and the named host. The source expression 'self' refers to the protected site’s own origin.

Common directives include script-src for scripts, img-src for images, and object-src for plugin content. The default-src directive can serve as a fallback for fetch directives, but a policy can also set specific rules for individual resource types.

How does a website deliver its policy?

The usual method is an HTTP response header named Content-Security-Policy. A page can also declare a policy using a <meta http-equiv="Content-Security-Policy"> element, but that method does not support every CSP feature. For a site-wide policy or when full feature support matters, use the response header as the basis for configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A browser can apply multiple policies to a protected resource. Adding another policy can only further restrict what that resource is allowed to do; it does not loosen the restrictions already in place.

What is CSP used for?

  • Limit resource sources: Directives can restrict where a page loads scripts, images, and other resources from.
  • Reduce some injection risks: Script rules can make it harder for injected content to execute, helping limit the impact of cross-site scripting.
  • Restrict embedding: The frame-ancestors directive can limit which sites are allowed to embed a page, helping defend against clickjacking.
  • Upgrade insecure requests: The upgrade-insecure-requests directive can instruct the browser to upgrade insecure resource requests.
  • Require trusted types: CSP can require trusted types in supported contexts, helping constrain certain ways that potentially unsafe data reaches DOM injection sinks.

What CSP does not do

The W3C specification states, “CSP is not intended as a first line of defense against content injection vulnerabilities.” CSP is best treated as defense in depth: it can reduce the harm an injection causes, but it does not remove the underlying vulnerability or make unsafe input safe.

Sites still need careful input validation, output encoding, and appropriate sanitization. A policy that blocks some unwanted scripts cannot compensate for weaknesses in how an application handles data.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What do report-only and enforced policies mean?

An enforced CSP blocks actions that violate the policy. A report-only policy, delivered through Content-Security-Policy-Report-Only, lets a site observe policy violations without applying those restrictions. MDN recommends starting in report-only mode, reviewing what would be blocked, and addressing legitimate site behavior before switching to enforcement.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This gradual approach matters because a restrictive policy can also block scripts, styles, or dependencies that a site actually needs. Strict policies commonly use nonce- or hash-based rules for scripts and/or styles, and existing inline code or third-party dependencies may need adjustment. There is no single policy that fits every site.

Best Value
Sale
The Web Application Hacker's Handbook: Finding and Exploiting Security Flaws
  • Comes with secure packaging
  • It can be a gift item
  • Easy to read text

When should a site use CSP?

CSP is useful as one part of a broader web security strategy, especially when a site wants to constrain script execution and resource loading or control which pages can embed it. The W3C CSP Level 3 page identifies a Working Draft version dated September 16, 2026, and links to the latest published version. Because CSP syntax, reporting features, and browser behavior can evolve, check current standards and browser support before deploying a policy.

Quick Recap

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.