Repository navigation
fix(web): highlight code in diffs and answers on app.fctl.sh - #387
Merged
kalaspuff merged 2 commits intoNov 5, 2026
Merged
Conversation
Shiki matches grammars with Oniguruma, compiled from WebAssembly, and the app's Content Security Policy (web/public/_headers) allowed scripts from 'self' only, which browsers take to refuse compiling WebAssembly. So on app.fctl.sh every highlight failed, quietly: diffs and code blocks showed as plain text in every language. Vite's dev server sends no such policy, so it highlighted there. script-src now allows 'wasm-unsafe-eval', which lets the app's scripts compile WebAssembly and nothing more: eval() and inline scripts stay refused. A test checks the policy keeps it, and that Shiki colors TypeScript, TSX and Rust. In Chromium, a build of the app's highlighter served with the old policy failed with "WebAssembly.instantiate(): ... 'unsafe-eval' is not an allowed source of script", and with the new one colored all three.
This comment has been minimized.
This comment has been minimized.
docs/security.md described the policy as script-src 'self' alone; it now also allows 'wasm-unsafe-eval' for syntax highlighting, while eval and inline scripts stay refused. theme.js's comment said the same.
kalaspuff
approved these changes
Nov 5, 2026
kalaspuff
deleted the
fctl/693-fix-so-that-typescript-files-gets-syntax
branch
November 5, 2026 21:15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On app.fctl.sh no code was highlighted: the diff dialog, the transcript's edits and code blocks in answers showed plain text in TypeScript, TSX, Rust and every other language. Shiki matches grammars with Oniguruma, compiled from WebAssembly, and the app's Content Security Policy (
web/public/_headers) allowed scripts from'self'only, which browsers take to refuse compiling WebAssembly. The highlighter's error was caught quietly, so the code was left plain. Vite's dev server sends no such policy, which is why it highlighted in development and in #386's screenshots.script-srcnow also allows'wasm-unsafe-eval'. That lets the app's own scripts compile WebAssembly;eval(),new Functionand inline scripts stay refused.docs/security.mdsays so. A new test checks that the policy keeps it and that Shiki colors TypeScript, TSX and Rust. In Chromium, a build of the app's highlighter served with the old policy failed with "WebAssembly.instantiate(): … 'unsafe-eval' is not an allowed source of script", and with the new policy it colored all three. The standalone server doesn't send_headers, so it already highlighted, and this changes nothing there.Screenshots
The web app built from this branch, served with main's policy (before) and this branch's (after), against
cargo xtask demo.A TypeScript file's diff (shop#231's
src/lib/money.ts), dark:A TSX file's diff (shop#219's
src/components/BoxItem.tsx), light:A Rust file's diff (platform#437's
src/billing/charge.rs), after, dark:Worth confirming
'wasm-unsafe-eval'widens what a script already running on the page can do (compile WebAssembly), not which scripts may run.fctl session
Note
Low risk. It adds one source to the web app's script policy and a test; no application code changes, and the policy still refuses
evaland inline scripts.What it does. Syntax highlighting was silently failing on app.fctl.sh because Shiki's WebAssembly regex engine could not compile under a
script-src 'self'policy.script-srcinweb/public/_headersnow also allows'wasm-unsafe-eval', anddocs/security.mdand a comment intheme.jssay so. A new test checks that Shiki colors TypeScript, TSX and Rust and that the policy keeps the allowance without'unsafe-eval'.Loosened Content-Security-Policy.
'wasm-unsafe-eval'widens what a script already running on the page can do (compile WebAssembly), not which scripts may run; the alternative was Shiki's JavaScript regex engine, which matches some grammars differently.fctl review's first look at
7912ed9· 4 files, +47 −7 · Review agent settings