<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Csp on Commentary of Takao</title><link>https://takao.blog/en/tags/csp/</link><description>Recent content in Csp on Commentary of Takao</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Commentary of Takao</copyright><lastBuildDate>Sat, 13 Jun 2026 23:11:50 +0900</lastBuildDate><atom:link href="https://takao.blog/en/tags/csp/index.xml" rel="self" type="application/rss+xml"/><item><title>Designing Modern Content Security Policies for Hugo blogs</title><link>https://takao.blog/en/web/hugo-latest-csp-best-practices-2026/</link><pubDate>Fri, 05 Jun 2026 00:00:00 +0900</pubDate><guid>https://takao.blog/en/web/hugo-latest-csp-best-practices-2026/</guid><description>&lt;img src="https://takao.blog/img/thumnail.webp" alt="Featured image of post Designing Modern Content Security Policies for Hugo blogs" /&gt;&lt;h2 id="why-csp-matters-for-static-sites"&gt;Why CSP Matters for Static Sites
&lt;/h2&gt;&lt;p&gt;Static sites built with Hugo are inherently more secure than dynamic applications, but they still execute third-party scripts for analytics, ads, and embeds. A &lt;strong&gt;Content Security Policy (CSP)&lt;/strong&gt; protects your visitors from XSS, data injection, and malicious script execution by controlling which resources can load.&lt;/p&gt;
&lt;h2 id="setting-csp-via-cloudflare-pages"&gt;Setting CSP via Cloudflare Pages
&lt;/h2&gt;&lt;p&gt;Cloudflare Pages supports custom &lt;code&gt;_headers&lt;/code&gt; files for controlling HTTP response headers:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-fallback" data-lang="fallback"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# static/_headers
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;/*
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; Content-Security-Policy: default-src &amp;#39;self&amp;#39;; script-src &amp;#39;self&amp;#39;; style-src &amp;#39;self&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For Hugo, place the &lt;code&gt;_headers&lt;/code&gt; file in your &lt;code&gt;static/&lt;/code&gt; directory so it gets copied to the output:&lt;/p&gt;</description></item><item><title>Testing CSP Rules Safely with Content-Security-Policy-Report-Only</title><link>https://takao.blog/en/web/security-content-security-policy-csp-report-only/</link><pubDate>Fri, 15 May 2026 00:00:00 +0900</pubDate><guid>https://takao.blog/en/web/security-content-security-policy-csp-report-only/</guid><description>&lt;img src="https://takao.blog/img/thumnail.webp" alt="Featured image of post Testing CSP Rules Safely with Content-Security-Policy-Report-Only" /&gt;&lt;h2 id="the-broken-widget-problem"&gt;The Broken-Widget Problem
&lt;/h2&gt;&lt;p&gt;Deploying a Content Security Policy is one of the strongest defenses against XSS attacks. But a single misconfigured directive can silently break inline scripts, block CDN resources, or disable analytics. If you apply CSP directly via the &lt;code&gt;Content-Security-Policy&lt;/code&gt; header and a critical script gets blocked, your production site breaks—often without an obvious error console notification.&lt;/p&gt;
&lt;p&gt;This is where &lt;strong&gt;Report-Only mode&lt;/strong&gt; saves the day.&lt;/p&gt;
&lt;h2 id="report-only-vs-enforced-mode"&gt;Report-Only vs Enforced Mode
&lt;/h2&gt;&lt;p&gt;CSP supports two headers:&lt;/p&gt;</description></item><item><title>Why and How to Adopt 'strict-dynamic' in CSP</title><link>https://takao.blog/en/web/security-csp-strict-dynamic-implementation/</link><pubDate>Sun, 15 Jun 2025 00:00:00 +0900</pubDate><guid>https://takao.blog/en/web/security-csp-strict-dynamic-implementation/</guid><description>&lt;img src="https://takao.blog/img/thumnail.webp" alt="Featured image of post Why and How to Adopt 'strict-dynamic' in CSP" /&gt;&lt;h2 id="introduction"&gt;Introduction
&lt;/h2&gt;&lt;p&gt;Implementing a &lt;strong&gt;Content Security Policy (CSP)&lt;/strong&gt; is a highly effective way to mitigate Cross-Site Scripting (XSS) risks. However, configuring and maintaining the policy can become a major headache.&lt;/p&gt;
&lt;p&gt;For websites utilizing third-party SDKs (such as Google Tag Manager, analytics beacons, payment widgets, or social sharing buttons), these scripts often dynamically load (inject) additional scripts from nested domains. This forces developers to maintain a long, fragile whitelist of external domains in the &lt;code&gt;script-src&lt;/code&gt; directive.&lt;/p&gt;</description></item></channel></rss>