{"id":518,"date":"2026-10-01T09:20:00","date_gmt":"2026-10-01T07:20:00","guid":{"rendered":"https:\/\/www.lukaswojcik.com\/?page_id=518"},"modified":"2026-11-18T12:38:53","modified_gmt":"2026-11-18T11:38:53","slug":"controlling-third-party-website-scripts-setting-up-a-content-security-policy","status":"publish","type":"post","link":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/","title":{"rendered":"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy"},"content":{"rendered":"<h2>What CSP protects and where protection ends<\/h2>\n<p>A Content Security Policy (CSP) defines which resources a browser may load and which scripts may execute for a document. Cross-site scripting means that injected code runs in a website&#8217;s page. A CSP makes some of these attacks harder. Allowed JavaScript still has access to the document, however. A compromised library on an allowed origin is not identified merely because a CSP exists.<\/p>\n<p>Escaping converts special characters so that text is not interpreted as code. Input validation checks whether submitted values meet expected rules. CSP supplements these measures and checks of the external libraries used by the site. A host allowlist names permitted source servers. It does not verify that each downloaded file is unchanged and trustworthy, or provide consent. Malicious scripts may still copy form entries (form skimming) or send data to allowed destinations. Page CSP is also not a reliable barrier against privileged browser extensions: Chrome separates isolated content scripts from the main world, where the page policy applies.<\/p>\n<figure class=\"lw-diagram\">\n<img loading=\"lazy\" decoding=\"async\" alt=\"Nginx or WordPress delivers the response policy. Report-Only observes; enforcement blocks disallowed resources. Allowed scripts still require trust.\" height=\"560\" src=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/diagrams\/quality-518-20261024.png\" width=\"1120\"\/><figcaption>Nginx or WordPress delivers the response policy. Report-Only observes; enforcement blocks disallowed resources. Allowed scripts still require trust.<\/figcaption><\/figure>\n<h2>1. Inventory of actual dependencies<\/h2>\n<p>The inventory covers scripts, styles, images, fonts, frames and connections after interaction. Relevant variations include page type, language, login, consent and form flows. A tag manager can load additional destinations, so its host alone is not a complete dependency list. Matomo Cloud requires the actual instance URLs rather than a generic matomo.cloud permission.<\/p>\n<p>&#8216;self&#8217; means the same origin, including scheme, host and port, not every subdomain or the same physical server. default-src provides a fallback for certain fetch directives, but not base-uri, form-action or frame-ancestors. connect-src governs browser connections such as fetch, XHR, sendBeacon and WebSocket. Browser CSP does not control onward requests from a server-side GTM container to advertising platforms.<\/p>\n<h2>2. An explicitly non-blocking starting policy<\/h2>\n<p>Each directive is a rule for a particular resource or action. For example, script-src controls scripts, form-action controls form submission destinations, and frame-ancestors controls which sites may embed the page. The following inventory policy is a Report-Only starting point for a test environment. Inline scripts and styles are written directly in the HTML instead of loaded as separate files. These and third-party resources have not yet been permitted. A typical WordPress site will therefore generate violations. This is not a production-ready policy without adaptation.<\/p>\n<pre class=\"wp-block-code\"><code>default-src 'self';\nscript-src 'self';\nstyle-src 'self';\nimg-src 'self' data:;\nfont-src 'self';\nconnect-src 'self';\nframe-src 'none';\nobject-src 'none';\nbase-uri 'self';\nform-action 'self';\nframe-ancestors 'self';<\/code><\/pre>\n<p>Delivered as Content-Security-Policy-Report-Only, the policy reports detected violations without blocking because of that policy. Any existing enforcing CSP still applies. Once required resources and flows have been checked, the agreed policy can be activated as Content-Security-Policy. &#8216;unsafe-inline&#8217; broadly permits inline scripts again and does not replace deliberate authorization of individual scripts.<\/p>\n<h2>3. Responsibility for header delivery<\/h2>\n<p>An HTTP response header carries instructions or information alongside the page content. Nginx can deliver a static policy in such a header. The following fragment belongs in the appropriate existing server or location context; TLS, proxying, PHP and other security headers remain part of the complete configuration. The header accompanies the response and is then evaluated by the browser. This neither prevents PHP execution nor detects attacks before PHP runs.<\/p>\n<pre class=\"wp-block-code\"><code>add_header Content-Security-Policy-Report-Only \"default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-src 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self';\" always;\n<\/code><\/pre>\n<p>Before a planned reload, nginx -t checks the complete configuration. A failed check must prevent the reload. The fragment passed syntax validation in a separate minimal configuration; that does not validate an existing production server configuration.<\/p>\n<pre class=\"wp-block-code\"><code>sudo nginx -t &amp;&amp; sudo systemctl reload nginx<\/code><\/pre>\n<p>Under default add_header inheritance, a child context with its own add_header lines stops inheriting the parent directives. always changes the covered response statuses, not inheritance. A shared include can keep relevant contexts consistent. Nginx 1.29.3 also introduced add_header_inherit merge; using that option requires a supporting version and checks for unintended duplicate headers.<\/p>\n<p>Where Nginx configuration is unavailable, a small site-specific WordPress plugin can add the Report-Only header to regular frontend responses. This is an alternative delivery path, not an automatic Nginx fallback. The example is not tied to WordPress 7.0.2 and does not automatically cover administration, login, REST or cache files served directly.<\/p>\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/** Plugin Name: Example CSP Report-Only *\/\nadd_action('send_headers', static function () {\n    if (is_admin() || headers_sent()) {\n        return;\n    }\n    $policy = \"default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-src 'none'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self';\";\n    header('Content-Security-Policy-Report-Only: ' . $policy);\n});\n<\/code><\/pre>\n<p>The send_headers hook can add outgoing headers. Prior output and upstream caches require attention. Multiple enforcing CSP headers apply together; permission in one does not override a restriction in another. Actual headers must therefore be checked across CDN, reverse proxy, web server and application.<\/p>\n<p><!-- lw-flux-illu 518-a4 --><\/p>\n<figure class=\"lw-illu\"><img src=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/illustrationen\/flux-518-a4-v8.webp\" width=\"1120\" height=\"630\" loading=\"lazy\" decoding=\"async\" alt=\"Only the two halves of a broken slate fit together along their edge; a sawn piece matches neither. Likewise, scripts inside the page code only run with a matching one-time code (nonce) or hash.\"><figcaption>Only the two halves of a broken slate fit together along their edge; a sawn piece matches neither. Likewise, scripts inside the page code only run with a matching one-time code (nonce) or hash.<\/figcaption><\/figure>\n<h2>4. Authorizing inline scripts with a nonce or hash<\/h2>\n<p>A nonce is a cryptographically random, unpredictable value for each new HTML response. The header and explicitly trusted script elements receive the same value. A WordPress action nonce is unsuitable for this purpose. A blanket HTML filter that marks every script could also authorize injected code. Caching and HTML generation must coordinate nonce handling.<\/p>\n<p>The following standalone PHP document demonstrates the relationship; it is not a complete WordPress patch. no-store prevents deliberate reuse of a cached response in this example. A real application must pass the nonce to every required trusted script deliberately.<\/p>\n<pre class=\"wp-block-code\"><code>&lt;?php\n$nonce = base64_encode(random_bytes(16));\nheader(\"Content-Security-Policy: default-src 'none'; script-src 'nonce-$nonce'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'\");\nheader('Cache-Control: no-store');\nheader('Content-Type: text\/html; charset=utf-8');\n?&gt;\n&lt;!doctype html&gt;&lt;html lang=\"en\"&gt;&lt;meta charset=\"utf-8\"&gt;\n&lt;title&gt;Nonce example&lt;\/title&gt;&lt;p id=\"result\"&gt;Pending&lt;\/p&gt;\n&lt;script nonce=\"&lt;?= htmlspecialchars($nonce, ENT_QUOTES, 'UTF-8') ?&gt;\"&gt;\ndocument.getElementById('result').textContent = 'Allowed script ran';\n&lt;\/script&gt;&lt;\/html&gt;\n<\/code><\/pre>\n<p>A hash is a calculated fingerprint of the script text. Hashes suit precisely known script contents: changes to content or whitespace can change the hash. A nonce on a script element does not authorize inline event attributes such as onclick. &#8216;strict-dynamic&#8217; can delegate trust to dynamically loaded scripts and reduces the role of host lists in supporting browsers; this delegation requires explicit review. Google&#8217;s GTM guidance documents nonce-aware embedding and additional directives for particular tag features.<\/p>\n<h2>5. Separate checks of reports and functionality<\/h2>\n<p>The browser console is the message view in developer tools. Without a reporting destination, it is a local diagnostic source. Reporting-Endpoints and report-to can target a previously configured HTTPS collector, with report-uri as an older compatibility path where needed. Modern reporting and report-uri use different JSON formats. Delivery is not guaranteed: browser support, blockers and network failures limit coverage. URL data and possible script samples in reports require careful processing and bounded retention.<\/p>\n<pre class=\"wp-block-code\"><code>Reporting-Endpoints: csp=\"https:\/\/reports.example.com\/csp\"\nContent-Security-Policy-Report-Only: default-src 'self'; report-to csp; report-uri https:\/\/reports.example.com\/csp-legacy<\/code><\/pre>\n<p>These addresses are placeholders requiring actual collectors. A reported source should not automatically be allowed. Acceptance checks cover document response headers, redirects, error pages, cache hits, forms, media, consent changes and tracking requests. HTTP 200 alone proves neither correct event collection nor correct processing by the destination.<\/p>\n<div class=\"lw-faq\">\n<h2>Questions and answers<\/h2>\n<h3>Does connect-src prevent every data leak?<\/h3>\n<p>No. The directive controls particular connection types, not every output route or permitted destination. Other directives cover images and forms, for example. Already authorized code, compromised first-party endpoints and faulty application logic remain separate risks.<\/p>\n<h3>Can Report-Only be enabled through a meta element?<\/h3>\n<p>No. Report-Only uses an HTTP response header. Even enforcing CSP in a meta element does not support every header feature, including frame-ancestors. The actual document response header is the basis for a consistent deployment.<\/p>\n<\/div>\n<h2>Sources<\/h2>\n<p><a href=\"https:\/\/owasp.org\/www-project-top-ten\/\" rel=\"noopener noreferrer\" target=\"_blank\">OWASP Top 10<\/a> \u00b7 <a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/\" rel=\"noopener noreferrer\" target=\"_blank\">WordPress functions.php \/ hooks reference<\/a><\/p>\n<ul>\n<li><a href=\"https:\/\/www.w3.org\/TR\/CSP3\/\">CSP Level3 specification<\/a><\/li>\n<li><a href=\"https:\/\/cheatsheetseries.owasp.org\/cheatsheets\/Content_Security_Policy_Cheat_Sheet.html\">OWASP CSP Cheat Sheet<\/a><\/li>\n<li><a href=\"https:\/\/nginx.org\/en\/docs\/http\/ngx_http_headers_module.html\">Nginx headers module<\/a><\/li>\n<li><a href=\"https:\/\/developer.wordpress.org\/reference\/hooks\/send_headers\/\">WordPress send_headers<\/a><\/li>\n<li><a href=\"https:\/\/developers.google.com\/tag-platform\/security\/guides\/csp\">Google Tag Manager CSP integration<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Guides\/CSP\">MDN CSP guide<\/a><\/li>\n<li><a href=\"https:\/\/developer.chrome.com\/docs\/extensions\/develop\/concepts\/content-scripts\">Chrome content scripts<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introducing a Content Security Policy for WordPress and Nginx: inventory, Report-Only checks, nonce and hash authorization, and the limits of browser protection.<\/p>\n","protected":false},"author":1,"featured_media":32113,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[120],"tags":[91312,91516,91219,91115,91096],"class_list":["post-518","post","type-post","status-publish","format-standard","hentry","category-tutorials-en","tag-javascript","tag-tracking","tag-tutorial","tag-web-security","tag-wordpress"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Controlling Third-Party Website Scripts: Setting Up a Content Security Policy | Lukas Wojcik<\/title>\n<meta name=\"description\" content=\"Configure CSP for web and WordPress pages: inventory scripts, check Nginx and PHP headers and test violations in report-only mode.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy | Lukas Wojcik\" \/>\n<meta property=\"og:description\" content=\"Configure CSP for web and WordPress pages: inventory scripts, check Nginx and PHP headers and test violations in report-only mode.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/\" \/>\n<meta property=\"og:site_name\" content=\"Lukas Wojcik - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-01T07:20:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-18T11:38:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-518-518.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Lukas Wojcik\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lukas Wojcik\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/\"},\"author\":{\"name\":\"Lukas Wojcik\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"headline\":\"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy\",\"datePublished\":\"2026-10-01T07:20:00+00:00\",\"dateModified\":\"2026-11-18T11:38:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/\"},\"wordCount\":1168,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-518-518.png\",\"keywords\":[\"JavaScript\",\"Tracking\",\"Tutorial\",\"Web Security\",\"WordPress\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/\",\"name\":\"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy | Lukas Wojcik\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-518-518.png\",\"datePublished\":\"2026-10-01T07:20:00+00:00\",\"dateModified\":\"2026-11-18T11:38:53+00:00\",\"description\":\"Configure CSP for web and WordPress pages: inventory scripts, check Nginx and PHP headers and test violations in report-only mode.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-518-518.png\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/flux-voll2-518-518.png\",\"width\":1200,\"height\":630,\"caption\":\"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/en\\\/data-privacy\\\/tutorials-en\\\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/de\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/\",\"name\":\"Lukas Wojcik - Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/#\\\/schema\\\/person\\\/895f7604f9b6b71aad9bba33af28d0f9\",\"name\":\"Lukas Wojcik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"url\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"contentUrl\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\",\"width\":424,\"height\":636,\"caption\":\"Lukas Wojcik\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/07\\\/lw-x2.jpg\"},\"sameAs\":[\"https:\\\/\\\/www.lukaswojcik.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy | Lukas Wojcik","description":"Configure CSP for web and WordPress pages: inventory scripts, check Nginx and PHP headers and test violations in report-only mode.","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:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/","og_locale":"en_US","og_type":"article","og_title":"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy | Lukas Wojcik","og_description":"Configure CSP for web and WordPress pages: inventory scripts, check Nginx and PHP headers and test violations in report-only mode.","og_url":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/","og_site_name":"Lukas Wojcik - Blog","article_published_time":"2026-10-01T07:20:00+00:00","article_modified_time":"2026-11-18T11:38:53+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-518-518.png","type":"image\/png"}],"author":"Lukas Wojcik","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Lukas Wojcik","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#article","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/"},"author":{"name":"Lukas Wojcik","@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"headline":"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy","datePublished":"2026-10-01T07:20:00+00:00","dateModified":"2026-11-18T11:38:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/"},"wordCount":1168,"commentCount":0,"publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-518-518.png","keywords":["JavaScript","Tracking","Tutorial","Web Security","WordPress"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/","url":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/","name":"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy | Lukas Wojcik","isPartOf":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#primaryimage"},"image":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#primaryimage"},"thumbnailUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-518-518.png","datePublished":"2026-10-01T07:20:00+00:00","dateModified":"2026-11-18T11:38:53+00:00","description":"Configure CSP for web and WordPress pages: inventory scripts, check Nginx and PHP headers and test violations in report-only mode.","breadcrumb":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#primaryimage","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-518-518.png","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/11\/flux-voll2-518-518.png","width":1200,"height":630,"caption":"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy"},{"@type":"BreadcrumbList","@id":"https:\/\/www.lukaswojcik.com\/blog\/en\/data-privacy\/tutorials-en\/controlling-third-party-website-scripts-setting-up-a-content-security-policy\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.lukaswojcik.com\/blog\/de\/"},{"@type":"ListItem","position":2,"name":"Controlling Third-Party Website Scripts: Setting Up a Content Security Policy"}]},{"@type":"WebSite","@id":"https:\/\/www.lukaswojcik.com\/blog\/#website","url":"https:\/\/www.lukaswojcik.com\/blog\/","name":"Lukas Wojcik - Blog","description":"","publisher":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.lukaswojcik.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.lukaswojcik.com\/blog\/#\/schema\/person\/895f7604f9b6b71aad9bba33af28d0f9","name":"Lukas Wojcik","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","url":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","contentUrl":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg","width":424,"height":636,"caption":"Lukas Wojcik"},"logo":{"@id":"https:\/\/www.lukaswojcik.com\/blog\/wp-content\/uploads\/2026\/07\/lw-x2.jpg"},"sameAs":["https:\/\/www.lukaswojcik.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/comments?post=518"}],"version-history":[{"count":10,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/518\/revisions"}],"predecessor-version":[{"id":33784,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/posts\/518\/revisions\/33784"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media\/32113"}],"wp:attachment":[{"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/media?parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/categories?post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lukaswojcik.com\/blog\/wp-json\/wp\/v2\/tags?post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}