mirror of
https://github.com/mudler/LocalAI.git
synced 2026-10-28 17:18:49 -04:00
fix(ui): serve canvas HTML previews from a route with their own CSP External scripts in canvas previews (for example three.js from unpkg) were blocked. The preview used an iframe with srcdoc, which inherits the global Content-Security-Policy, and a meta tag can only tighten it. The UI now posts the HTML to POST /api/canvas/preview, gets a random id, and loads GET /api/canvas/preview/:id in the iframe. That response sets its own CSP that allows scripts from unpkg, jsdelivr, cdnjs, the Tailwind CDN and jQuery. The global CSP is unchanged. The iframe keeps sandbox="allow-scripts" without allow-same-origin. Previews are kept in memory for 10 minutes and are never written to disk. The GET route is public because the id is the capability and a frame navigation cannot send API key headers. Assisted-by: Claude:claude-haiku-5-5 [go test] [npm] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io>