{"id":3620,"date":"2026-11-29T10:27:34","date_gmt":"2026-11-29T04:57:34","guid":{"rendered":"https:\/\/larapush.com\/blog\/?p=3620"},"modified":"2026-11-29T10:27:34","modified_gmt":"2026-11-29T04:57:34","slug":"web-push-content-security-policy","status":"publish","type":"post","link":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/","title":{"rendered":"How Do You Set Up Web Push With a Content Security Policy?"},"content":{"rendered":"\n<p><strong>To make web push work with a Content Security Policy (CSP), allow your service worker in worker-src (or script-src), allow your push SDK&#8217;s script host in script-src, and allow the API hosts it calls in connect-src. The service worker also gets its own policy from its HTTP headers, so check that response too.<\/strong><\/p>\n\n\n\n<p>A strict CSP is one of the best defences against cross-site scripting, and I&#8217;m always happy to see one. However, it&#8217;s also the reason many push setups fail quietly. The subscribe button does nothing, the console shows a &#8220;Refused to load&#8221; message, and nobody connects it to push. Here&#8217;s how to set up web push with a Content Security Policy without weakening it more than you need to.<\/p>\n\n\n\n<p>Key facts at a glance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>worker-src<\/strong> controls which URLs can be loaded as Worker, SharedWorker or ServiceWorker scripts, per <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Reference\/Headers\/Content-Security-Policy\/worker-src\" target=\"_blank\" rel=\"noreferrer noopener\">MDN&#8217;s worker-src page<\/a>.<\/li>\n\n\n\n<li><strong>Fallback:<\/strong> if worker-src is missing, browsers use child-src, then script-src, then default-src.<\/li>\n\n\n\n<li><strong>Separate policy:<\/strong> MDN&#8217;s <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Reference\/Headers\/Content-Security-Policy\" target=\"_blank\" rel=\"noreferrer noopener\">Content-Security-Policy reference<\/a> notes that workers aren&#8217;t governed by the CSP of the page that created them.<\/li>\n\n\n\n<li><strong>Same origin:<\/strong> service worker scripts must come from your own origin, so &#8216;self&#8217; is usually enough for worker-src.<\/li>\n\n\n\n<li><strong>Safe testing:<\/strong> the Content-Security-Policy-Report-Only header reports violations without blocking anything.<\/li>\n<\/ul>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_63 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#How_does_CSP_affect_web_push_notifications\" title=\"How does CSP affect web push notifications?\">How does CSP affect web push notifications?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#Which_CSP_directives_does_web_push_need\" title=\"Which CSP directives does web push need?\">Which CSP directives does web push need?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#Why_does_the_service_worker_need_its_own_policy\" title=\"Why does the service worker need its own policy?\">Why does the service worker need its own policy?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#How_do_you_find_which_CSP_rule_is_blocking_push\" title=\"How do you find which CSP rule is blocking push?\">How do you find which CSP rule is blocking push?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#Should_you_use_unsafe-inline_to_make_push_work\" title=\"Should you use unsafe-inline to make push work?\">Should you use unsafe-inline to make push work?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#Does_CSP_affect_web_push_on_WordPress\" title=\"Does CSP affect web push on WordPress?\">Does CSP affect web push on WordPress?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#Where_LaraPush_fits\" title=\"Where LaraPush fits\">Where LaraPush fits<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#Frequently_asked_questions\" title=\"Frequently asked questions\">Frequently asked questions<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_does_CSP_affect_web_push_notifications\"><\/span>How does CSP affect web push notifications?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>CSP affects web push at three points: loading the push SDK script, registering the service worker, and sending the subscription to your server. If any of those requests is blocked, the visitor never becomes a subscriber, even if they clicked Allow.<\/p>\n\n\n\n<p>Here&#8217;s the typical flow and the directive that controls each step:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Step<\/th><th>What happens<\/th><th>CSP directive on your page<\/th><\/tr><\/thead><tbody><tr><td>1. Load SDK<\/td><td>Your page loads the push provider&#8217;s JavaScript<\/td><td>script-src<\/td><\/tr><tr><td>2. Register worker<\/td><td>navigator.serviceWorker.register(&#8216;\/sw.js&#8217;)<\/td><td>worker-src (falls back to child-src, script-src, default-src)<\/td><\/tr><tr><td>3. Subscribe<\/td><td>The browser creates a push subscription<\/td><td>Not controlled by your CSP<\/td><\/tr><tr><td>4. Save subscription<\/td><td>Your code posts the endpoint to your server or panel<\/td><td>connect-src<\/td><\/tr><tr><td>5. Manifest<\/td><td>Browser fetches manifest.json, if you use one<\/td><td>manifest-src<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Step 3 is handled by the browser and its push service, not by a fetch from your page. So you don&#8217;t need to allow fcm.googleapis.com or Mozilla&#8217;s push host in connect-src just to subscribe. You only need them if your own code calls those hosts directly. My explainer on <a href=\"https:\/\/larapush.com\/blog\/how-do-push-notifications-work\/\">how push notifications work<\/a> covers the full flow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Which_CSP_directives_does_web_push_need\"><\/span>Which CSP directives does web push need?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Most setups need three changes: worker-src for the service worker, script-src for the SDK, and connect-src for the endpoint that stores subscriptions. Here&#8217;s an example for a site that self-hosts its push panel on a subdomain.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Content-Security-Policy:\n  default-src 'self';\n  script-src 'self' https:\/\/push.example.com;\n  worker-src 'self';\n  connect-src 'self' https:\/\/push.example.com;\n  img-src 'self' data: https:\/\/push.example.com;\n  manifest-src 'self';<\/code><\/pre>\n\n\n\n<p>Replace push.example.com with your panel or provider&#8217;s real host. If you load Firebase&#8217;s JavaScript SDK from Google&#8217;s CDN, you&#8217;d also add https:\/\/www.gstatic.com to script-src. And because Firebase&#8217;s SDK calls Google APIs to register the device, add the googleapis.com hosts it uses to connect-src. The fastest way to get the exact list is to read the blocked URLs in your console, rather than guessing.<\/p>\n\n\n\n<p>Keep img-src in mind if your subscribe widget or bell icon loads images from the provider. Otherwise, the prompt may appear without its icon.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Why_does_the_service_worker_need_its_own_policy\"><\/span>Why does the service worker need its own policy?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The service worker needs its own policy because workers don&#8217;t inherit your page&#8217;s CSP. Instead, a service worker is governed by the CSP header sent with the service worker script itself. So a strict page policy doesn&#8217;t automatically protect, or restrict, sw.js.<\/p>\n\n\n\n<p>This matters in two ways. First, if your server sends a strict CSP on every response, including sw.js, then importScripts() calls inside the worker must match that policy. A Firebase-based worker that imports scripts from www.gstatic.com will fail unless that host is allowed in the worker&#8217;s own script-src.<\/p>\n\n\n\n<p>Second, the worker&#8217;s fetch() calls follow its own connect-src. For example, if the worker reports click analytics to your panel, that host must be allowed in the policy on sw.js. My guide to <a href=\"https:\/\/larapush.com\/blog\/web-push-with-existing-service-worker\/\">adding web push to an existing service worker<\/a> shows how importScripts fits into a merged worker.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_find_which_CSP_rule_is_blocking_push\"><\/span>How do you find which CSP rule is blocking push?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Open your browser&#8217;s developer tools, reload the page, and click your subscribe button with the Console open. CSP violations appear as &#8220;Refused to load&#8221; or &#8220;Refused to connect&#8221; messages that name the blocked URL and the directive.<\/p>\n\n\n\n<p>Then follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Note each blocked URL and the directive named in the message.<\/li>\n\n\n\n<li>Check the Application panel to see if the service worker registered.<\/li>\n\n\n\n<li>If it didn&#8217;t, check the Network tab for sw.js and read its response headers.<\/li>\n\n\n\n<li>Add the blocked host to the right directive in a Report-Only header first.<\/li>\n\n\n\n<li>Test again, then move the change into the enforced policy.<\/li>\n<\/ol>\n\n\n\n<p>The Report-Only header is the safest way to test on a live site, because it logs violations without breaking anything. For other console checks, see my guide to <a href=\"https:\/\/larapush.com\/blog\/debug-web-push-in-chrome-devtools\/\">debugging web push in Chrome DevTools<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Should_you_use_unsafe-inline_to_make_push_work\"><\/span>Should you use unsafe-inline to make push work?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>No. Adding &#8216;unsafe-inline&#8217; to script-src removes most of the protection CSP gives you against cross-site scripting. If your push snippet is an inline script, use a nonce or a hash for that script, or move the code into an external file on your own domain.<\/p>\n\n\n\n<p>Here&#8217;s how I compare the options:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Option<\/th><th>Security<\/th><th>Effort<\/th><\/tr><\/thead><tbody><tr><td>&#8216;unsafe-inline&#8217; in script-src<\/td><td>Weak; allows any inline script<\/td><td>Lowest<\/td><\/tr><tr><td>Nonce per page load<\/td><td>Strong<\/td><td>Needs server-side templating<\/td><\/tr><tr><td>Hash of the inline snippet<\/td><td>Strong<\/td><td>Update the hash when the snippet changes<\/td><\/tr><tr><td>External script file on your domain<\/td><td>Strong<\/td><td>Move the code once<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>A nonce or hash keeps the policy strict while still running the one snippet you trust. However, many CMS caching setups make nonces awkward, so an external file is often the simplest fix. If you&#8217;re on WordPress, check whether your security plugin or host sets the CSP header, so you edit it in the right place.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Does_CSP_affect_web_push_on_WordPress\"><\/span>Does CSP affect web push on WordPress?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Yes, if your site sends a CSP header. WordPress itself doesn&#8217;t add one by default, but security plugins, hosting panels and CDNs often do. So start by finding out where your header comes from, then add the push hosts there.<\/p>\n\n\n\n<p>Also check that the service worker file is served from your site root with a JavaScript content type, because a misconfigured header or redirect can block registration too. My guides on <a href=\"https:\/\/larapush.com\/blog\/add-push-notifications-to-wordpress\/\">adding push notifications to WordPress<\/a> and <a href=\"https:\/\/larapush.com\/blog\/self-hosted-push-panel-behind-cloudflare\/\">running a self-hosted panel behind Cloudflare<\/a> cover related setup issues. If everything loads but alerts still don&#8217;t arrive, use my checklist for <a href=\"https:\/\/larapush.com\/blog\/web-push-notifications-not-showing\/\">web push notifications not showing<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_LaraPush_fits\"><\/span>Where LaraPush fits<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaraPush is a self-hosted web push panel, so the script and API hosts you add to your CSP are your own panel domain rather than a third-party SaaS. It delivers through Firebase Cloud Messaging, so Firebase hosts may also appear in your policy. Plans start from $499 one-time; see <a href=\"https:\/\/larapush.com\/pricing\/\">LaraPush pricing<\/a>, the <a href=\"https:\/\/larapush.com\/features\/\">features page<\/a>, and the <a href=\"https:\/\/larapush.com\/guide\/\">setup guide<\/a> for the snippet and service worker you&#8217;ll install. The trade-offs are no free plan, one server per licence, and a VPS you maintain.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_asked_questions\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1764404000000\"><strong class=\"schema-faq-question\">Which CSP directive controls service workers?<\/strong> <p class=\"schema-faq-answer\">The worker-src directive controls which URLs can be loaded as service worker scripts. If you don&#8217;t set worker-src, browsers fall back to child-src, then script-src, then default-src. Because service workers must be same-origin, worker-src &#8216;self&#8217; is usually all you need.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764404001111\"><strong class=\"schema-faq-question\">Do I need to allow fcm.googleapis.com in connect-src?<\/strong> <p class=\"schema-faq-answer\">Usually not for the subscription itself, because the browser talks to its push service directly. You only need Google hosts if your own code or an SDK calls them from the page, for example Firebase&#8217;s JavaScript SDK. Your console will name any host it blocks.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764404002222\"><strong class=\"schema-faq-question\">Why does my service worker ignore my page&#8217;s Content Security Policy?<\/strong> <p class=\"schema-faq-answer\">Workers aren&#8217;t governed by the CSP of the page that created them. A service worker uses the CSP header sent with the service worker script&#8217;s own response. So check the headers on sw.js separately, especially if it uses importScripts or fetch.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764404003333\"><strong class=\"schema-faq-question\">How can I test CSP changes without breaking push?<\/strong> <p class=\"schema-faq-answer\">Use the Content-Security-Policy-Report-Only header with your proposed policy. Browsers log or report violations but don&#8217;t block anything. Once the console stays clean while you subscribe and receive a test notification, move the same policy into the enforced header.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1764404004444\"><strong class=\"schema-faq-question\">Is it safe to add unsafe-inline for my push snippet?<\/strong> <p class=\"schema-faq-answer\">I don&#8217;t recommend it. Allowing &#8216;unsafe-inline&#8217; in script-src lets any inline script run, which defeats much of the protection against cross-site scripting. Use a nonce or hash for the snippet, or move it into an external JavaScript file on your domain.<\/p> <\/div><\/div>\n","protected":false},"excerpt":{"rendered":"Set up web push with a Content Security Policy: the worker-src, script-src and connect-src rules you need, and how to debug blocked requests.","protected":false},"author":7,"featured_media":3627,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":""},"categories":[68],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How Do You Set Up Web Push With a Content Security Policy?<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How Do You Set Up Web Push With a Content Security Policy?\" \/>\n<meta property=\"og:description\" content=\"Set up web push with a Content Security Policy: the worker-src, script-src and connect-src rules you need, and how to debug blocked requests.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/\" \/>\n<meta property=\"og:site_name\" content=\"LaraPush Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-29T04:57:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ritesh Das\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ritesh Das\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/\"},\"author\":{\"name\":\"Ritesh Das\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd\"},\"headline\":\"How Do You Set Up Web Push With a Content Security Policy?\",\"datePublished\":\"2026-11-29T04:57:34+00:00\",\"dateModified\":\"2026-11-29T04:57:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/\"},\"wordCount\":1476,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/larapush.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg\",\"articleSection\":[\"How to\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/\",\"url\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/\",\"name\":\"How Do You Set Up Web Push With a Content Security Policy?\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg\",\"datePublished\":\"2026-11-29T04:57:34+00:00\",\"dateModified\":\"2026-11-29T04:57:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404000000\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404001111\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404002222\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404003333\"},{\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404004444\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage\",\"url\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg\",\"contentUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg\",\"width\":1200,\"height\":675,\"caption\":\"Illustration of a web push Content Security Policy, a padlock shield guarding a browser window with a service worker gear and bell\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/larapush.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How Do You Set Up Web Push With a Content Security Policy?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/larapush.com\/blog\/#website\",\"url\":\"https:\/\/larapush.com\/blog\/\",\"name\":\"LaraPush Blog\",\"description\":\"Stay Ahead, Stay Notified with LaraPush!\",\"publisher\":{\"@id\":\"https:\/\/larapush.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/larapush.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/larapush.com\/blog\/#organization\",\"name\":\"LaraPush\",\"url\":\"https:\/\/larapush.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png\",\"contentUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png\",\"width\":280,\"height\":60,\"caption\":\"LaraPush\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd\",\"name\":\"Ritesh Das\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g\",\"caption\":\"Ritesh Das\"},\"url\":\"https:\/\/larapush.com\/blog\/author\/riteshdas\/\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404000000\",\"position\":1,\"url\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404000000\",\"name\":\"Which CSP directive controls service workers?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The worker-src directive controls which URLs can be loaded as service worker scripts. If you don't set worker-src, browsers fall back to child-src, then script-src, then default-src. Because service workers must be same-origin, worker-src 'self' is usually all you need.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404001111\",\"position\":2,\"url\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404001111\",\"name\":\"Do I need to allow fcm.googleapis.com in connect-src?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Usually not for the subscription itself, because the browser talks to its push service directly. You only need Google hosts if your own code or an SDK calls them from the page, for example Firebase's JavaScript SDK. Your console will name any host it blocks.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404002222\",\"position\":3,\"url\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404002222\",\"name\":\"Why does my service worker ignore my page's Content Security Policy?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Workers aren't governed by the CSP of the page that created them. A service worker uses the CSP header sent with the service worker script's own response. So check the headers on sw.js separately, especially if it uses importScripts or fetch.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404003333\",\"position\":4,\"url\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404003333\",\"name\":\"How can I test CSP changes without breaking push?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Use the Content-Security-Policy-Report-Only header with your proposed policy. Browsers log or report violations but don't block anything. Once the console stays clean while you subscribe and receive a test notification, move the same policy into the enforced header.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404004444\",\"position\":5,\"url\":\"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404004444\",\"name\":\"Is it safe to add unsafe-inline for my push snippet?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"I don't recommend it. Allowing 'unsafe-inline' in script-src lets any inline script run, which defeats much of the protection against cross-site scripting. Use a nonce or hash for the snippet, or move it into an external JavaScript file on your domain.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How Do You Set Up Web Push With a Content Security Policy?","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/","og_locale":"en_US","og_type":"article","og_title":"How Do You Set Up Web Push With a Content Security Policy?","og_description":"Set up web push with a Content Security Policy: the worker-src, script-src and connect-src rules you need, and how to debug blocked requests.","og_url":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/","og_site_name":"LaraPush Blog","article_published_time":"2026-11-29T04:57:34+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg","type":"image\/jpeg"}],"author":"Ritesh Das","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ritesh Das","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#article","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/"},"author":{"name":"Ritesh Das","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd"},"headline":"How Do You Set Up Web Push With a Content Security Policy?","datePublished":"2026-11-29T04:57:34+00:00","dateModified":"2026-11-29T04:57:34+00:00","mainEntityOfPage":{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/"},"wordCount":1476,"commentCount":0,"publisher":{"@id":"https:\/\/larapush.com\/blog\/#organization"},"image":{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg","articleSection":["How to"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/","url":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/","name":"How Do You Set Up Web Push With a Content Security Policy?","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage"},"image":{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg","datePublished":"2026-11-29T04:57:34+00:00","dateModified":"2026-11-29T04:57:34+00:00","breadcrumb":{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404000000"},{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404001111"},{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404002222"},{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404003333"},{"@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404004444"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/larapush.com\/blog\/web-push-content-security-policy\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#primaryimage","url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg","contentUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/web-push-content-security-policy.jpg","width":1200,"height":675,"caption":"Illustration of a web push Content Security Policy, a padlock shield guarding a browser window with a service worker gear and bell"},{"@type":"BreadcrumbList","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/larapush.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How Do You Set Up Web Push With a Content Security Policy?"}]},{"@type":"WebSite","@id":"https:\/\/larapush.com\/blog\/#website","url":"https:\/\/larapush.com\/blog\/","name":"LaraPush Blog","description":"Stay Ahead, Stay Notified with LaraPush!","publisher":{"@id":"https:\/\/larapush.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/larapush.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/larapush.com\/blog\/#organization","name":"LaraPush","url":"https:\/\/larapush.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png","contentUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png","width":280,"height":60,"caption":"LaraPush"},"image":{"@id":"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd","name":"Ritesh Das","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g","caption":"Ritesh Das"},"url":"https:\/\/larapush.com\/blog\/author\/riteshdas\/"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404000000","position":1,"url":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404000000","name":"Which CSP directive controls service workers?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The worker-src directive controls which URLs can be loaded as service worker scripts. If you don't set worker-src, browsers fall back to child-src, then script-src, then default-src. Because service workers must be same-origin, worker-src 'self' is usually all you need.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404001111","position":2,"url":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404001111","name":"Do I need to allow fcm.googleapis.com in connect-src?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Usually not for the subscription itself, because the browser talks to its push service directly. You only need Google hosts if your own code or an SDK calls them from the page, for example Firebase's JavaScript SDK. Your console will name any host it blocks.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404002222","position":3,"url":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404002222","name":"Why does my service worker ignore my page's Content Security Policy?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Workers aren't governed by the CSP of the page that created them. A service worker uses the CSP header sent with the service worker script's own response. So check the headers on sw.js separately, especially if it uses importScripts or fetch.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404003333","position":4,"url":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404003333","name":"How can I test CSP changes without breaking push?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Use the Content-Security-Policy-Report-Only header with your proposed policy. Browsers log or report violations but don't block anything. Once the console stays clean while you subscribe and receive a test notification, move the same policy into the enforced header.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404004444","position":5,"url":"https:\/\/larapush.com\/blog\/web-push-content-security-policy\/#faq-question-1764404004444","name":"Is it safe to add unsafe-inline for my push snippet?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"I don't recommend it. Allowing 'unsafe-inline' in script-src lets any inline script run, which defeats much of the protection against cross-site scripting. Use a nonce or hash for the snippet, or move it into an external JavaScript file on your domain.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3620"}],"collection":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/comments?post=3620"}],"version-history":[{"count":1,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3620\/revisions"}],"predecessor-version":[{"id":3628,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3620\/revisions\/3628"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media\/3627"}],"wp:attachment":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media?parent=3620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/categories?post=3620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/tags?post=3620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}