mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-17 07:39:39 +02:00
fix(csp): move jsdelivr allowlist to mana-web hooks (Vite SSR cache workaround)
The previous two attempts at allowlisting cdn.jsdelivr.net for transformers.js's onnxruntime-web loader landed in shared-utils security-headers.ts. The actual file change was correct (verified by grep), the commits got pushed, the live security-headers.ts on disk had the additions — but Vite's SSR module cache for cross-workspace- package imports kept serving the OLD compiled shared-utils to hooks.server.ts. Net effect: edits to hooks.server.ts hot-reloaded fine (proven by the *.hf.co connect-src additions showing up immediately) while edits to shared-utils/security-headers.ts did not. A dev server restart should clear it but I'd rather not depend on manual intervention every time we touch the shared CSP. Move the jsdelivr allowlist out of the shared default and into mana-web's hooks.server.ts via the existing scriptSrc + connectSrc options. hooks.server.ts is in the SvelteKit app's own source tree so it HMRs reliably, no SSR cache to fight. As a bonus this is also architecturally cleaner: cdn.jsdelivr.net is only needed by mana-web because mana-web is the only Mana app that bundles @mana/local-llm — other apps get a slightly tighter CSP for free. The pattern to remember: changes to packages/shared-utils that affect SSR (response headers, server hooks) require either a dev server restart OR a manual `rm -rf apps/.../node_modules/.vite` to take effect. Client-side changes hot-reload fine. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
96023394b5
commit
e4e3360ca8
2 changed files with 12 additions and 13 deletions
|
|
@ -103,6 +103,11 @@ window.__PUBLIC_GLITCHTIP_DSN__ = ${JSON.stringify(PUBLIC_GLITCHTIP_DSN)};
|
|||
|
||||
const isDev = process.env.NODE_ENV !== 'production';
|
||||
setSecurityHeaders(response, {
|
||||
// @huggingface/transformers (used by @mana/local-llm) lazy-loads the
|
||||
// onnxruntime-web WASM loader from jsDelivr at backend selection
|
||||
// time via a dynamic import(). Browsers route dynamic imports
|
||||
// through script-src.
|
||||
scriptSrc: ['https://cdn.jsdelivr.net'],
|
||||
connectSrc: [
|
||||
PUBLIC_MANA_AUTH_URL_CLIENT,
|
||||
PUBLIC_SYNC_SERVER_URL_CLIENT,
|
||||
|
|
@ -112,6 +117,11 @@ window.__PUBLIC_GLITCHTIP_DSN__ = ${JSON.stringify(PUBLIC_GLITCHTIP_DSN)};
|
|||
PUBLIC_MANA_EVENTS_URL_CLIENT,
|
||||
PUBLIC_MANA_API_URL_CLIENT,
|
||||
'wss://sync.mana.how',
|
||||
// transformers.js *also* fetch()es the .wasm binary and the .mjs
|
||||
// loader factory directly to pre-warm the runtime — those go
|
||||
// through connect-src, not script-src, so jsDelivr has to be in
|
||||
// both lists for the WebGPU backend resolver to succeed.
|
||||
'https://cdn.jsdelivr.net',
|
||||
// @mana/local-llm (transformers.js) pulls model config + ONNX
|
||||
// shards from the HuggingFace ecosystem. HF currently uses three
|
||||
// distinct CDN domains depending on file type and rollout state:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue