Menu

Why Astro's Native `security.csp` Breaks on Shiki
📰

Why Astro's Native `security.csp` Breaks on Shiki

DEV Community: astro·Evgenii Zinner·17 days ago
#ja6TJIOY
#devtoastro#devto#dev#inline#astro
Reading 0:00
15s threshold

Whenever I mention my astro-strict-csp package, the first question developers usually ask is: "Wait, doesn't Astro already have built-in security.csp in astro.config.mjs ?"

It does—and Astro's native security.csp is actually the exact reason I still needed to build astro-strict-csp .

If you enable Astro's built-in CSP on a real project that uses Markdown code blocks, <Image /> components, or UI islands, your pages immediately break or flood the browser console with Content Security Policy violations. When you check the official Astro documentation for how to fix it, the recommended workarounds are either switching your syntax highlighter from Shiki to Prism , or adding 'unsafe-inline' to style-src .

Here is why Astro's native CSP hits that wall, why switching from Shiki to Prism is a painful downgrade for a technical blog, and how extracting inline styles at build time solves both problems cleanly.

Why Native security.csp Stops at Inline Styles

Astro's built-in security.csp does a fine job computing…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.