Rendering defenses can fail independently
A safe text renderer is the primary control, but a future component change may introduce an unsafe insertion. CSP can reduce some consequences by limiting executable and embeddable resources. The policy must fit your own application and be tested rather than copied blindly.
What to do next
- 01
Inventory required capabilities
List scripts, styles, media sources and embeds required by the preview. Avoid granting arbitrary origins simply because generated text might mention them, and keep private preview resources under explicit delivery routes.
- 02
Roll out with evidence
Test a restrictive policy in a controlled environment or report-only stage as appropriate. Review violations for real application needs and unexpected content-driven requests before enforcing the final policy.
- 03
Keep primary rendering controls
Continue escaping text, disabling unsafe Markdown features and sanitizing any intentionally supported HTML. Test that a generated script or iframe is inert even without relying solely on the policy's current browser enforcement.
A concrete example
Illustrative example: a generated answer includes an external iframe. The renderer rejects the element, and the page's frame policy independently disallows arbitrary embedded origins. The app does not broaden CSP to make the unexpected iframe appear.
Before you call it ready
- CSP origins follow application needs.
- Violations are reviewed before broadening policy.
- Safe rendering remains independently tested.
When to stop or choose another method
Stop presenting CSP as permission to insert arbitrary generated HTML into the application page.
