Menu

CSP and Third-Party AI Widgets: Copilot, Chat, and Scripts
📰

CSP and Third-Party AI Widgets: Copilot, Chat, and Scripts

DEV Community: nextjs·Ganesh Joshi·15 days ago
#wwEousMW
#devtonextjs#devto#dev#widget#vendor
Reading 0:00
15s threshold

This post was created with AI assistance and reviewed for accuracy before publishing.

Adding a vendor's AI chat widget is a two-line change to your HTML and a much larger change to your security posture. The script runs with the same privileges as your own code: it can read the DOM, read localStorage , and make requests as the logged-in user.

Content Security Policy is how you bound that. The catch is that most widget install guides ask you to weaken exactly the directives that were doing the work.

The install instructions are the problem

Vendor docs commonly suggest one of these:

script-src 'self' 'unsafe-inline' 'unsafe-eval' https://widget.vendor.com;

Enter fullscreen mode

Exit fullscreen mode

Each addition removes a specific protection. 'unsafe-inline' allows any injected <script> tag to execute, which is the primary thing CSP exists to prevent. 'unsafe-eval' allows strings to be compiled into code, re-opening a class of injection that is otherwise dead.…

Continue reading — create a free account

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