<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Azeez Israel (Adordev)</title>
    <description>The latest articles on DEV Community by Azeez Israel (Adordev) (@yungstarry).</description>
    <link>https://dev.to/yungstarry</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1907785%2F27873be1-d5f9-4a73-a525-3b0e4ea7c71b.jpeg</url>
      <title>DEV Community: Azeez Israel (Adordev)</title>
      <link>https://dev.to/yungstarry</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yungstarry"/>
    <language>en</language>
    <item>
      <title>How I Hardened a React + Cloudflare Pages SaaS App to an A+ SecurityHeaders Grade (With Paystack &amp; Meta Pixel)</title>
      <dc:creator>Azeez Israel (Adordev)</dc:creator>
      <pubDate>Sun, 06 Dec 2026 10:25:13 +0000</pubDate>
      <link>https://dev.to/yungstarry/how-i-hardened-a-react-cloudflare-pages-saas-app-to-an-a-securityheaders-grade-with-paystack--248g</link>
      <guid>https://dev.to/yungstarry/how-i-hardened-a-react-cloudflare-pages-saas-app-to-an-a-securityheaders-grade-with-paystack--248g</guid>
      <description>&lt;p&gt;When launching a commercial web app that handles real customer payments and private user data, shipping features is only half the job. Before going live with two SaaS apps at &lt;a href="https://linktr.ee/Adordev" rel="noopener noreferrer"&gt;Adordev Tech&lt;/a&gt;, I wanted our production domains to score an &lt;strong&gt;A+ on SecurityHeaders.com&lt;/strong&gt;—without breaking third-party payment popups (&lt;strong&gt;Paystack&lt;/strong&gt;) or analytics scripts (&lt;strong&gt;Meta Pixel&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Most tutorials tell you to slap &lt;code&gt;unsafe-inline&lt;/code&gt; and &lt;code&gt;unsafe-eval&lt;/code&gt; onto your &lt;code&gt;Content-Security-Policy&lt;/code&gt; (CSP) the moment a third-party script complains. That immediately downgrades your security posture.&lt;/p&gt;

&lt;p&gt;Here is the exact build-time approach we used to keep a strict, zero-&lt;code&gt;unsafe-inline&lt;/code&gt; CSP on &lt;strong&gt;React + Vite + Cloudflare Pages&lt;/strong&gt; while keeping payments and conversion tracking working cleanly.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Why Static &lt;code&gt;_headers&lt;/code&gt; Falls Short for Dynamic Builds
&lt;/h2&gt;

&lt;p&gt;Cloudflare Pages supports a &lt;code&gt;public/_headers&lt;/code&gt; file out of the box, which works great for static rules like &lt;code&gt;Strict-Transport-Security&lt;/code&gt;, &lt;code&gt;X-Frame-Options&lt;/code&gt;, and &lt;code&gt;Permissions-Policy&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;However, when your &lt;code&gt;Content-Security-Policy&lt;/code&gt; needs environment-aware domains (like Supabase API endpoints, Paystack checkout frames, or conditional analytics scripts), maintaining a hardcoded static file becomes error-prone.&lt;/p&gt;

&lt;p&gt;Instead, we generate &lt;code&gt;_headers&lt;/code&gt; dynamically during our production build step (&lt;code&gt;node scripts/security-headers.mjs &amp;amp;&amp;amp; vite build&lt;/code&gt;).&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Core Security Headers for an A+ Grade
&lt;/h2&gt;

&lt;p&gt;To hit &lt;strong&gt;A+&lt;/strong&gt; on SecurityHeaders.com, every response from Cloudflare Pages needs six baseline headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(self "https://paystack.co")
  Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
  Content-Security-Policy: default-src 'self'; ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice &lt;code&gt;Permissions-Policy&lt;/code&gt;: explicitly granting &lt;code&gt;payment=(self "https://paystack.co")&lt;/code&gt; locks down hardware APIs while ensuring browser payment requests from Paystack aren't blocked.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Allowing Paystack &amp;amp; Meta Pixel Without &lt;code&gt;unsafe-inline&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Third-party scripts are usually where strict CSPs fall apart. By auditing the exact network requests made during checkout and page views, we whitelisted only the required origins per directive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// scripts/security-headers.mjs&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'node:fs'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'node:path'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cspDirectives&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="s2"&gt;"default-src 'self'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// Vite bundles JS into hashed files in dist/, so no 'unsafe-inline' is needed for scripts&lt;/span&gt;
  &lt;span class="s2"&gt;"script-src 'self' https://paystack.co https://facebook.net"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// Allow Paystack inline checkout modal &amp;amp; Meta Pixel beacon connections&lt;/span&gt;
  &lt;span class="s2"&gt;"connect-src 'self' https://paystack.co https://facebook.com https://*.supabase.co"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// Paystack renders its checkout overlay inside an iframe&lt;/span&gt;
  &lt;span class="s2"&gt;"frame-src 'self' https://paystack.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"img-src 'self' data: https://facebook.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"style-src 'self' 'unsafe-inline'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"font-src 'self' data:"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"object-src 'none'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"base-uri 'self'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"form-action 'self'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"frame-ancestors 'none'"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="s2"&gt;"upgrade-insecure-requests"&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;headersContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`/*
  X-Frame-Options: DENY
  X-Content-Type-Options: nosniff
  Referrer-Policy: strict-origin-when-cross-origin
  Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(self "https://paystack.co")
  Strict-Transport-Security: max-age=63072000; includeSubDomains; preload
  Content-Security-Policy: ${cspDirectives.join('; ')}
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;mkdirSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'public'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;recursive&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'public'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'_headers'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headersContent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'utf8'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Generated strict production _headers'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Two Key Details That Prevented Production Bugs:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;No Inline Bootstrapping Scripts in &lt;code&gt;index.html&lt;/code&gt;:&lt;/strong&gt; Instead of pasting Meta's raw &lt;code&gt;&amp;lt;script&amp;gt;...&amp;lt;/script&amp;gt;&lt;/code&gt; snippet directly into &lt;code&gt;index.html&lt;/code&gt; (which forces you to allow &lt;code&gt;unsafe-inline&lt;/code&gt; or manage script hashes on every edit), we load the pixel inside a bundled TypeScript module gated by &lt;code&gt;import.meta.env.VITE_META_PIXEL_ID&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Idempotent Server-Side Webhook Verification:&lt;/strong&gt; Client-side checkout callbacks are great for UI feedback, but fulfillment only unlocks after our server-side webhook verifies the Paystack HMAC-SHA512 signature and checks that the transaction hasn't already been processed.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  4. Verifying Locally Before Pushing
&lt;/h2&gt;

&lt;p&gt;Before deploying to Cloudflare Pages, you can validate your generated headers locally using &lt;code&gt;wrangler pages dev dist&lt;/code&gt; and inspecting the response headers via &lt;code&gt;curl -I http://localhost:8788&lt;/code&gt;, followed by a live scan on &lt;strong&gt;SecurityHeaders.com&lt;/strong&gt; after deployment.&lt;/p&gt;

&lt;p&gt;If you're shipping React apps on Cloudflare Pages, generating &lt;code&gt;_headers&lt;/code&gt; at build time gives you clean version-controlled security without sacrificing third-party integrations.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;What security headers or CSP edge cases have tripped you up in production? Let me know in the comments!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>security</category>
      <category>react</category>
      <category>cloudflare</category>
    </item>
  </channel>
</rss>
