Fixing Grade-D Storefront Security Headers + Building Zero-Login ZATCA TLV QR Invoices on Cloudflare Pages
When shipping lightweight SaaS apps and storefronts on Cloudflare Pages, two real-world traps routinely break trust and conversion: Missing Edge Security Headers quietly drop stores to a Grade C/D in automated audits
When shipping lightweight SaaS apps and storefronts on Cloudflare Pages, two real-world traps routinely break trust and conversion:
- Missing Edge Security Headers quietly drop stores to a Grade C/D in automated audits (even when HTTPS is green).
- Client-side Tax QR generation (ZATCA / JoFotara) breaks on UTF-8 Arabic business names if you pass raw JS string lengths instead of UTF-8 byte lengths.
Here is the exact checklist and production code we just shipped across our live Cloudflare Pages apps today.
1. Why _headers Disappears During Build Splits
On Cloudflare Pages, _headers must sit inside the exact output directory deployed to Pages (for example dist/_headers, not the repo root _headers). Today we moved _headers into dist/ across our production portals and watched our own checkout audit jump from Grade C (73/100) to Grade A+ (97/100):
/*
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
X-Content-Type-Options: nosniff
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
X-Frame-Options: SAMEORIGIN
You can verify your own storefront's headers, Payment SDKs, TTFB, and SEO tags in 2 seconds using our free StoreGuard Edge AI Scanner.
2. Zero-Dependency ZATCA / JoFotara TLV Base64 QR Encoder (UTF-8 Safe)
Middle East e-invoicing QR codes (ZATCA Phase-1 & JoFotara) encode 5 Tag-Length-Value (TLV) records in Base64:
- Tag 1: Seller Name (UTF-8)
- Tag 2: VAT / Tax Registration Number
- Tag 3: ISO-8601 Timestamp
- Tag 4: Invoice Total (with VAT)
- Tag 5: VAT Total
A common bug is writing value.length instead of TextEncoder().encode(value).length — which corrupts Arabic strings immediately. Here is the clean zero-backend helper we deployed in FatoraFlow:
function tlvChunk(tag, valueStr) {
const bytes = new TextEncoder().encode(valueStr || "");
const len = Math.min(bytes.length, 255);
const out = new Uint8Array(2 + len);
out[0] = tag;
out[1] = len;
out.set(bytes.slice(0, len), 2);
return out;
}
export function buildZatcaTlvBase64(seller, vatNo, isoDate, totalStr, vatStr) {
const chunks = [
tlvChunk(1, seller),
tlvChunk(2, vatNo),
tlvChunk(3, isoDate),
tlvChunk(4, totalStr),
tlvChunk(5, vatStr)
];
const merged = new Uint8Array(chunks.reduce((acc, c) => acc + c.length, 0));
let offset = 0;
for (const c of chunks) { merged.set(c, offset); offset += c.length; }
let bin = "";
for (let i = 0; i < merged.length; i++) bin += String.fromCharCode(merged[i]);
return btoa(bin);
}
Try Both Tools Live (Free, Zero Login)
- FatoraFlow (Bilingual Arabic RTL + English Tax Invoice, Quotation & TLV QR Builder): https://fatoraflow-pro.pages.dev/?lang=en
- StoreGuard Edge AI (Live Storefront Security, Checkout Trust & AI Conversion Audit): https://storeguard-pro.pages.dev/
Production Source-Code Starter Kits
If you want the full-stack source code for automated order workflows, Cloudflare Workers PayPal v2 settlement + SHA-256 digital delivery, or Chrome MV3 tooling, our verified commercial vaults are live with instant PayPal unlock:
- TabPilot MV3 Pro ($19) / CodeForge Edge SaaS Kit ($29) / 4-in-1 Full-Stack Commercial Vault ($59): https://storeguard-pro.pages.dev/?buy=sg_dev_bundle_4in1
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.