Skip to content

Commit 59428c4

Browse files
committed
fix(app): drop inline theme-preload substitution to satisfy CSP
The opencode-desktop:theme-preload vite plugin rewrote the canonical external `<script src="/oc-theme-preload.js">` form into an inline script at build time, trading a sub-millisecond round-trip on localhost for inline-script CSP friction. With our embedded server's strict CSP (`script-src 'self' 'wasm-unsafe-eval'`), the inline form is blocked at runtime: theme preload silently does not run, and the console shows "Executing inline script violates the following Content Security Policy directive". Drop the inline-substitution plugin. The source `index.html` already declares the external form on line 19, so removing the plugin lets that canonical form survive into `dist/index.html`. The external script still runs synchronously in <head> before the bundle, so theme load order is preserved; only the small fetch round-trip is added. Alternatives considered: - SHA-256 hash in CSP - brittle; any edit to the preload script silently breaks theme preload until the hash is regenerated, with no test that would catch it. - 'unsafe-inline' - defeats most of CSP's value. - Per-response nonce - requires server-side HTML rewriting on every GET; heavy for a tiny gain on a single-tenant tool. Refs upstream PR anomalyco#18985 (the inline substitution). Refs upstream issue anomalyco#18325 (the auth-loop bug that surfaced this CSP regression).
1 parent 4eb970c commit 59428c4

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

‎packages/app/vite.js‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { readFileSync } from "node:fs"
21
import solidPlugin from "vite-plugin-solid"
32
import tailwindcss from "@tailwindcss/vite"
43
import { fileURLToPath } from "url"
54

6-
const theme = fileURLToPath(new URL("./public/oc-theme-preload.js", import.meta.url))
7-
85
/**
96
* @type {import("vite").PluginOption}
107
*/
@@ -24,15 +21,13 @@ export default [
2421
}
2522
},
2623
},
27-
{
28-
name: "opencode-desktop:theme-preload",
29-
transformIndexHtml(html) {
30-
return html.replace(
31-
'<script id="oc-theme-preload-script" src="/oc-theme-preload.js"></script>',
32-
`<script id="oc-theme-preload-script">${readFileSync(theme, "utf8")}</script>`,
33-
)
34-
},
35-
},
24+
// Theme preload is served as an external file (`/oc-theme-preload.js`) so
25+
// the embedded server's strict CSP (`script-src 'self' 'wasm-unsafe-eval'`)
26+
// does not need a hash exception or `'unsafe-inline'`. The earlier
27+
// build-time inline substitution traded a sub-millisecond round-trip on
28+
// localhost for inline-script CSP friction; not worth the complexity.
29+
// Refs upstream PR anomalyco/opencode#18985, upstream issue
30+
// anomalyco/opencode#18325.
3631
tailwindcss(),
3732
solidPlugin(),
3833
]

0 commit comments

Comments
 (0)