{"id":5184,"date":"2026-11-22T10:00:00","date_gmt":"2026-11-22T04:30:00","guid":{"rendered":"https:\/\/www.ogeninfo.com\/blog\/?p=5184"},"modified":"2026-11-20T21:56:20","modified_gmt":"2026-11-20T16:26:20","slug":"content-security-policy","status":"publish","type":"post","link":"https:\/\/www.ogeninfo.com\/blog\/content-security-policy\/","title":{"rendered":"Content Security Policy: Stop Third-Party Script Attacks"},"content":{"rendered":"<p>A Content Security Policy (CSP) is a set of rules your website sends to the browser, listing where scripts, styles, images and connections are allowed to come from. If a script tries to load from, or send data to, a place you have not approved, the browser blocks it. That matters because most business websites run code from other companies, such as analytics, chat widgets, testing tools and ad tags, and if one of those suppliers is compromised, its code runs on your pages with your visitors&#8217; trust. On 16 November 2026, Optimizely reported that an attacker inserted malicious JavaScript into some customers&#8217; Web Experimentation projects. A CSP would not have stopped every part of an attack like that, but it limits what injected code can do, and adding one is a modest amount of work.<\/p>\n<p><em>Last reviewed: 20 November 2026. Based on Optimizely&#8217;s status page, MDN Web Docs and the OWASP CSP Cheat Sheet; links are at the end. General information, not a security audit of your site.<\/em><\/p>\n<table>\n<thead>\n<tr>\n<th>Content Security Policy<\/th>\n<th>In short<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>What it is<\/td>\n<td>An HTTP response header listing which sources a page may load scripts and other resources from<\/td>\n<\/tr>\n<tr>\n<td>Main protection<\/td>\n<td>Cross-site scripting (XSS); also clickjacking, through the frame-ancestors directive<\/td>\n<\/tr>\n<tr>\n<td>Safe way to start<\/td>\n<td>Content-Security-Policy-Report-Only, which reports violations without blocking anything<\/td>\n<\/tr>\n<tr>\n<td>Recommended for scripts<\/td>\n<td>A nonce or hash, which MDN calls a &#8220;strict CSP&#8221;<\/td>\n<\/tr>\n<tr>\n<td>Companion check<\/td>\n<td>Subresource Integrity (SRI) for files loaded from a CDN that do not change<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>What happened with Optimizely?<\/h2>\n<p>According to Optimizely&#8217;s status page, on 16 November 2026 an unauthorised third party exploited a flaw in the Web Experimentation account signup flow, posed as users on some customer accounts, and added malicious JavaScript to those customers&#8217; projects. Optimizely says it detected the activity the same day, blocked delivery of the code, fixed the flaw within three hours of spotting it, and cleaned the injected code out of every affected project. It says the incident was limited to Web Experimentation, affected less than 5% of its customers, and was not a credentials breach.<\/p>\n<p>Tools like this work by loading a script from the supplier on every page of the customer&#8217;s site. That is what makes them useful, and also why a problem at the supplier can reach many customer websites at once, through a script each site had chosen to trust.<\/p>\n<h2>Why are third-party scripts a risk?<\/h2>\n<p>A script you load from another company runs with the same power as your own code. MDN describes what injected code can do in a cross-site scripting attack: anything the website&#8217;s own code could do. On a business site that can mean reading what visitors type into forms, changing payment or contact details shown on the page, or sending visitors elsewhere.<\/p>\n<p>It is worth checking how much third-party code your own pages load. A marketing site may have analytics, a tag manager, a chat widget, heatmaps, an A\/B testing tool, ad pixels and embedded videos, each loading further files of its own. Every one of them is a supplier you are trusting with your visitors.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/third-party-script-attack-csp.webp\" alt=\"How a third-party script attack reaches your visitors: your page loads a script from a supplier such as an analytics, chat or testing tool; an attacker changes the supplier's script; the changed script runs on your page and tries to load more code or send form data to an attacker's server; a Content Security Policy blocks requests to sources you have not approved\" width=\"1200\" height=\"330\" \/><figcaption>Where a CSP helps: it blocks loads and connections to sources you have not approved.<\/figcaption><\/figure>\n<h2>How does a Content Security Policy help?<\/h2>\n<p>MDN describes CSP as a set of instructions that a website gives the browser to limit what the page can do. Its main use is to control which resources, especially JavaScript, a page may load, as a defence against cross-site scripting. A simple policy looks like this:<\/p>\n<p><code>Content-Security-Policy: default-src 'self'; img-src 'self' https:\/\/images.example.com<\/code><\/p>\n<p>Here, <code>default-src 'self'<\/code> tells the browser to load resources only from your own domain unless another directive says otherwise, and <code>img-src<\/code> adds one approved image host.<\/p>\n<p>There is a limit. If you approve a supplier&#8217;s domain and the attacker changes the file on that same domain, the browser will still run it, because it comes from an approved source. What a CSP can still do is stop that code from loading more scripts from unapproved domains, or from sending data to them through <code>connect-src<\/code> and related rules. OWASP calls CSP a defence-in-depth measure: an extra layer on top of secure code and careful supplier choices.<\/p>\n<h2>How do you add a Content Security Policy without breaking your site?<\/h2>\n<ol>\n<li>List every script, style, font, image host, iframe and API your pages load. Your browser&#8217;s developer tools show them under the Network tab.<\/li>\n<li>Remove what you no longer use. Old pixels and abandoned widgets are common.<\/li>\n<li>Write a first policy that allows your own domain and the suppliers you keep.<\/li>\n<li>Send it as <code>Content-Security-Policy-Report-Only<\/code>. MDN explains that this header reports violations without enforcing the policy, so nothing breaks while you test. Add a <code>report-to<\/code> directive so reports are sent somewhere you can read them.<\/li>\n<li>Watch the reports for a week or two, including on forms, checkout and pages with embeds, and fix the policy.<\/li>\n<li>Switch to the enforcing <code>Content-Security-Policy<\/code> header.<\/li>\n<li>Move towards nonces or hashes for scripts. MDN calls a nonce &#8220;the recommended approach&#8221; for restricting scripts and styles: the server adds a fresh random value to each response, and only scripts carrying it run.<\/li>\n<li>Add <code>frame-ancestors<\/code> to control which sites may show your pages in a frame, which protects against clickjacking.<\/li>\n<\/ol>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/content-security-policy-8-steps.webp\" alt=\"Eight steps to add a Content Security Policy: list every script and resource, remove what you do not use, write a first policy, send it in report-only mode, read the reports and fix the policy, switch to enforcing mode, move to nonces or hashes for scripts, and add frame-ancestors against clickjacking\" width=\"1200\" height=\"400\" \/><figcaption>Start in report-only mode so nothing breaks while you learn what the site loads.<\/figcaption><\/figure>\n<h2>What is Subresource Integrity, and when should you use it?<\/h2>\n<p>Subresource Integrity (SRI) lets the browser check that a file it fetches, for example from a CDN, has not been changed. You add an <code>integrity<\/code> attribute with a cryptographic hash of the file to the <code>&lt;script&gt;<\/code> or <code>&lt;link&gt;<\/code> tag; MDN lists SHA-256, SHA-384 and SHA-512 as the allowed hash types. If the file does not match, the browser refuses to use it.<\/p>\n<p>SRI works best for fixed library versions, such as a specific release of a JavaScript library from a public CDN. It does not suit scripts that a supplier updates often by design, such as most testing, tag manager and chat snippets, because every legitimate update would change the hash and break the script. For those, rely on CSP, careful supplier choice and the steps below.<\/p>\n<h2>Checklist for third-party scripts on a business website<\/h2>\n<ul>\n<li>Keep a written list of every third-party script, who owns it inside your company, and why it is there.<\/li>\n<li>Load scripts only on the pages that need them; a chat widget does not need to run on your checkout page.<\/li>\n<li>Protect supplier accounts with strong passwords and two-factor sign-in, and remove staff who have left.<\/li>\n<li>Prefer suppliers that publish a status page and security contact, and subscribe to their incident alerts.<\/li>\n<li>After any supplier incident, check your site for unexpected scripts and review the supplier&#8217;s guidance.<\/li>\n<li>Review the list every quarter and remove what nobody uses.<\/li>\n<\/ul>\n<h2>How do you add a CSP on WordPress and other platforms?<\/h2>\n<p>A CSP is an HTTP header, so it is usually set on the web server (Apache or Nginx), on a CDN or reverse proxy, or by the application. On WordPress it can also be added with a security plugin or a few lines of server configuration. Test any change on a copy of the site first, because a policy that is too strict can stop forms, payment widgets or embedded videos from working.<\/p>\n<p>If you are not sure what your site loads, start with the list in step 1 above.<\/p>\n<h2>Getting help<\/h2>\n<p>Our <a href=\"https:\/\/www.ogeninfo.com\/website-development\/\">website development<\/a> page explains how we build sites with security headers in mind, and <a href=\"https:\/\/www.ogeninfo.com\/wordpress-development\/\">WordPress development<\/a> covers hardening and maintenance for WordPress sites. For apps built quickly with code-writing tools, see our guide to <a href=\"https:\/\/www.ogeninfo.com\/blog\/vibe-coding-security-risks\/\">security risks in quickly built apps<\/a>, and our older post on <a href=\"https:\/\/www.ogeninfo.com\/blog\/web-security-a-prime-concern\/\">web security<\/a> covers the basics.<\/p>\n<h2>Frequently asked questions<\/h2>\n<h3>What is a Content Security Policy?<\/h3>\n<p>It is an HTTP header that tells the browser which sources a page may load scripts, styles, images, fonts and connections from. The browser blocks anything not on the list, which mainly protects against cross-site scripting attacks.<\/p>\n<h3>Would a CSP have stopped the Optimizely attack?<\/h3>\n<p>Not entirely. If a site approved the supplier&#8217;s domain, code inserted into the supplier&#8217;s own file would still run. A CSP can still block that code from loading further scripts from, or sending data to, domains you have not approved.<\/p>\n<h3>Will a Content Security Policy break my website?<\/h3>\n<p>It can if the policy is too strict. Start with the Content-Security-Policy-Report-Only header, which reports violations without blocking anything, fix the policy based on the reports, then switch to enforcing mode.<\/p>\n<h3>What is the difference between CSP and SRI?<\/h3>\n<p>CSP controls where a page may load resources from. Subresource Integrity checks that a specific file has not changed by comparing it with a hash in the page. They work well together, but SRI suits only files that do not change often.<\/p>\n<h3>How do I add a CSP on WordPress?<\/h3>\n<p>Set the header in your web server or CDN configuration, or use a security plugin that adds headers. Begin in report-only mode and test forms, payments and embeds before enforcing it.<\/p>\n<h2>Sources<\/h2>\n<ul>\n<li><a href=\"https:\/\/status.optimizely.com\/history\" target=\"_blank\" rel=\"noopener\">Optimizely status page, Web Experimentation Security Incident, posted 17 November 2026 01:02 UTC (checked 20 November 2026)<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CSP\" target=\"_blank\" rel=\"noopener\">MDN Web Docs, Content Security Policy (CSP)<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Reference\/Headers\/Content-Security-Policy-Report-Only\" target=\"_blank\" rel=\"noopener\">MDN Web Docs, Content-Security-Policy-Report-Only header<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/Security\/Subresource_Integrity\" target=\"_blank\" rel=\"noopener\">MDN Web Docs, Subresource Integrity<\/a><\/li>\n<li><a href=\"https:\/\/cheatsheetseries.owasp.org\/cheatsheets\/Content_Security_Policy_Cheat_Sheet.html\" target=\"_blank\" rel=\"noopener\">OWASP, Content Security Policy Cheat Sheet<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.<\/p>\n","protected":false},"author":1,"featured_media":5185,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[485],"tags":[],"class_list":["post-5184","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-development"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.5.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"admin\"\/>\n\t<meta name=\"google-site-verification\" content=\"tbyWcItlzkiB8_1ks1vlBs9uiRNGQF7KYi0WR-52SIo\" \/>\n\t<meta name=\"msvalidate.01\" content=\"37DEBB35D2406D6C25D7B5DE135D5703\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.ogeninfo.com\/blog\/content-security-policy\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.5.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Blog - OGEN Infosystem\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Content Security Policy: Stop Third-Party Script Attacks\" \/>\n\t\t<meta property=\"og:description\" content=\"Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.ogeninfo.com\/blog\/content-security-policy\/\" \/>\n\t\t<meta property=\"fb:app_id\" content=\"170428330115947\" \/>\n\t\t<meta property=\"fb:admins\" content=\"790246117677304\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/content-security-policy.webp\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/content-security-policy.webp\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t\t<meta property=\"article:tag\" content=\"web development\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-11-22T04:30:00+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-11-20T16:26:20+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Ogeninfosystemofficial\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@ogeninfosystem\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Content Security Policy: Stop Third-Party Script Attacks\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@ogeninfosystem\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/content-security-policy.webp\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Content Security Policy: Stop Third-Party Script Attacks","description":"Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.","canonical_url":"https:\/\/www.ogeninfo.com\/blog\/content-security-policy\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"google-site-verification":"tbyWcItlzkiB8_1ks1vlBs9uiRNGQF7KYi0WR-52SIo","msvalidate.01":"37DEBB35D2406D6C25D7B5DE135D5703","miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"Blog - OGEN Infosystem","og:type":"article","og:title":"Content Security Policy: Stop Third-Party Script Attacks","og:description":"Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.","og:url":"https:\/\/www.ogeninfo.com\/blog\/content-security-policy\/","fb:app_id":"170428330115947","fb:admins":"790246117677304","og:image":"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/content-security-policy.webp","og:image:secure_url":"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/content-security-policy.webp","og:image:width":1200,"og:image:height":630,"article:tag":["web development"],"article:published_time":"2026-11-22T04:30:00+00:00","article:modified_time":"2026-11-20T16:26:20+00:00","article:publisher":"https:\/\/www.facebook.com\/Ogeninfosystemofficial","twitter:card":"summary_large_image","twitter:site":"@ogeninfosystem","twitter:title":"Content Security Policy: Stop Third-Party Script Attacks","twitter:description":"Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.","twitter:creator":"@ogeninfosystem","twitter:image":"https:\/\/www.ogeninfo.com\/blog\/wp-content\/uploads\/2026\/11\/content-security-policy.webp"},"aioseo_meta_data":{"post_id":"5184","title":"Content Security Policy: Stop Third-Party Script Attacks","description":"Content Security Policy explained: how it limits third-party script attacks like the Optimizely incident, how to add one safely, and when to use SRI.","keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2026-11-20 16:24:23","updated":"2026-11-20 16:24:23","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ogeninfo.com\/blog\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u2192<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.ogeninfo.com\/blog\/category\/web-development\/\" title=\"Web Development\">Web Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u2192<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tContent Security Policy: Stop Third-Party Script Attacks\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.ogeninfo.com\/blog\/"},{"label":"Web Development","link":"https:\/\/www.ogeninfo.com\/blog\/category\/web-development\/"},{"label":"Content Security Policy: Stop Third-Party Script Attacks","link":"https:\/\/www.ogeninfo.com\/blog\/content-security-policy\/"}],"_links":{"self":[{"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/posts\/5184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/comments?post=5184"}],"version-history":[{"count":1,"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/posts\/5184\/revisions"}],"predecessor-version":[{"id":5186,"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/posts\/5184\/revisions\/5186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/media\/5185"}],"wp:attachment":[{"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/media?parent=5184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/categories?post=5184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ogeninfo.com\/blog\/wp-json\/wp\/v2\/tags?post=5184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}