Posts

Showing posts with the label Web Security

Writing Content Security Policy Headers With LLMs in November 2026: Start in Report-Only, Use Nonces Instead of unsafe-inline, and Tighten One Directive at a Time

Image
Ask an LLM to "add a Content Security Policy to my app" and you will usually get one of two results. The first is a policy so loose it does nothing: script-src * 'unsafe-inline' 'unsafe-eval' , which lets almost any script run. The second is a policy so strict it breaks your site the moment you deploy it, because the model never saw your analytics snippet, your inline event handlers, or the third-party widget on the checkout page. A good CSP sits between those two, and getting there is a process rather than a one-shot prompt. This guide shows how to use an LLM to help you write, test, and tighten a Content Security Policy without locking out your own users. What a CSP actually does A Content Security Policy is an HTTP response header that tells the browser which sources of scripts, styles, images, frames, and other content a page is allowed to load. If an attacker manages to inject a <script> tag into your page through a cross-site scripting (XSS)...