Skip to content

fix(web): highlight code in diffs and answers on app.fctl.sh - #387

Merged
kalaspuff merged 2 commits into
mainfrom
fctl/693-fix-so-that-typescript-files-gets-syntax
Nov 5, 2026
Merged

kalaspuff merged 2 commits into
mainfrom
fctl/693-fix-so-that-typescript-files-gets-syntax

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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-src now also allows 'wasm-unsafe-eval'. That lets the app's own scripts compile WebAssembly; eval(), new Function and inline scripts stay refused. docs/security.md says 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:

Before After
Before: money.ts's diff in plain text After: money.ts's diff highlighted

A TSX file's diff (shop#219's src/components/BoxItem.tsx), light:

Before After
Before: BoxItem.tsx's diff in plain text After: BoxItem.tsx's diff highlighted

A Rust file's diff (platform#437's src/billing/charge.rs), after, dark:

After: charge.rs's diff highlighted

Worth confirming

  • Decision: I loosened the policy rather than switch Shiki to its JavaScript regex engine, which needs no WebAssembly but matches some grammars differently from Oniguruma. '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 eval and 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-src in web/public/_headers now also allows 'wasm-unsafe-eval', and docs/security.md and a comment in theme.js say 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

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.
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner November 5, 2026 21:09
@fctl-review

This comment has been minimized.

Comment thread web/public/_headers Resolved
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
kalaspuff merged commit bb13249 into main Nov 5, 2026
12 checks passed
@kalaspuff
kalaspuff deleted the fctl/693-fix-so-that-typescript-files-gets-syntax branch November 5, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant