Repository navigation
feat(http-web): serve the built editor with its response headers on every answer - #786
Merged
Merged
Conversation
…very answer A new crate, meldframe-http-web, serves apps/web/dist: a router of one fallback with a layer that sets the Content-Security-Policy, nosniff, Referrer-Policy and, on https, HSTS on every answer it makes, a path rule that never leaves the directory (strict per-segment decoding, canonicalisation, containment by components, no dotfiles, regular files only), content types, cache rules, ETag, one byte range and HEAD. The starting policy was checked against the real build in Chromium and needed no relaxation. Two changes to the page were required: the canvas imports pixi.js/unsafe-eval (Pixi builds shader code with new Function) and the theme script is a file. A browser check (csp-e2e.mjs) drives the editor, its dialogs and menus on the Svelte and React copies, tries eighteen things the policy must stop and shows that tightened policies fail. A lint test forbids raw HTML sinks in every front-end package. The crate is not wired into apps/server (slice 13a). Signed-off-by: Anaz S. Aji <12648688+ajianaz@users.noreply.github.com>
ajianaz
force-pushed
the
feat/serve-editor
branch
from
December 5, 2026 08:03
e56af9d to
e1cc9ef
Compare
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.
What
ADR-0022 slice 13b, serve the editor: a new crate
meldframe-http-webserves the files ofapps/web/distwith a Content-Security-Policy,X-Content-Type-Options: nosniff,Referrer-Policy: no-referrerand, on https,Strict-Transport-Securityon every answer it makes, and refuses every path that leaves the directory. The starting policy of the ADR was checked against the real build in Chromium. Refs the 13b entry of the Plan indocs/adr/0022-*.md; E2.1 stays unticked.Why
The editor and the API must share one origin (the
__Host-cookie, the exactOrigincheck), and agent-written text is shown in the editor, so a script that ran on that origin could call the approvals route as the person. The mitigations the ADR names are the policy, a lint that forbids{@html, and escaping; this slice builds the first two and measures the policy against the real page instead of assuming it.Size: one logical change, 38 files, about 3,900 lines of which the tests and the browser check are most (owner decision of 4 Dec 2026: no numeric limit). It cannot be split without a crate whose headers are not tested on the real page.
Changes
crates/integrations/meldframe-http-web(kind bin; depsaxum,tokio,futures-util,meldframe-textfor the hidden-character set).Site::open(dir, Headers),Site::router()(one fallback, forfallback_servicebehind the API routes),headers::layer(the same stamp on any router), theserveexample. One layer sets the four headers after the response is made, replacing a handler's value, so no path forgets them: 200, 206, 304, 400, 404, 405, 414, 416, 500 andHEAD..,.., empty, a hidden character,\,:, an encoded/, or bytes that are not UTF-8; a dotfile and a directory are 404; over 1,024 bytes or 16 segments is 414; then the path is canonicalised and must be inside the canonical directory by components (so a siblingdist-secretis outside), pass no dotfile, and be a regular file byfstatof the handle that is read..wasmasapplication/wasm),immutableonly for Vite'sassets/<name>-<8 char hash>.<ext>,no-cachefor the rest,no-storefor errors, strongETagand 304, onebytes=range withIf-Rangeand 416,HEAD, 64 KiB reads. Error bodies have the API's shape (docs/error-codes.md, "Static file codes").apps/web: the canvas importspixi.js/unsafe-eval, and the inline theme script ofindex.htmlis the filepublic/theme-init.js. These two are the only changes the policy needed; the policy itself is unchanged.packages/web-tools/scripts/html-sinks*.mjsand three fixtures: the{@htmllint (alsodangerouslySetInnerHTML,innerHTMLandouterHTMLassignments,insertAdjacentHTML,document.write) over every product file ofapps/weband the packages; its allow-list is empty and only goes down.packages/web-e2e/scripts/csp-*.mjs: the browser check, run by hand (not in CI).docs/epics.mdstatus,docs/architecture.md,docs/error-codes.md, three entries inAGENTS.mdwith what is not covered.index.html(the editor's pages are query strings of/); HSTSmax-age=31536000only;form-actionleft out of the policy on purpose (Chrome applies it to the redirect after a form post, and the sign-in post redirects to Gatehouse); compression,OPTIONSand TLS are the proxy's.apps/server: slice 13a ownsmain.rs. It mountsSite::open(dir, Headers::new(https))?.router()as thefallback_serviceand must not add a second, differentContent-Security-Policyto API answers (two headers are both enforced).No relaxation of the starting policy was needed, so none is written here. What it was found not to need, measured:
img-srcforblob:ordata:(Pixi fetches a texture and decodes it withcreateImageBitmap, covered byconnect-src 'self'),worker-src(no worker starts),style-src(styles are set through the CSSOM, which is not a violation, and the built CSS is a file).Testing
The first run of the real page under the starting policy failed (the canvas could not start and the theme script was refused), which is how the two page changes were found; the crate tests assert each behaviour listed above and the mutants below show they can fail.
cargo test -p meldframe-http-web: 76 tests (18 unit, 13 files, 10 headers, 9 methods, 11 ranges, 15 traversal), real listener and a raw HTTP client so paths reach the server as written. Corpus of 72 paths onGETandHEAD, every method, long and deep paths, symlinks (to a file, a directory,..,/, a sibling with the same prefix, a loop, a dangling link, a link into a dotfile, a build opened through a link), every header on every kind of answer on http and https...allowed, an encoded slash, a backslash, a control character, containment removed, containment by text prefix, no canonicalisation, the dotfile check in the path and in the resolved path, directories served, everything immutable, a range off by one, the method check removed, a 304 for any tag: all 18 killed (run before the hidden-character test moved tomeldframe_text::is_hidden_text; the corpus has U+202E, U+200B and U+FEFF as encoded bytes). One survived and is equivalent: the handler sending a body forHEAD(axum's router and hyper drop it; the test through the router alone cannot tell either). A{@htmladded to a package file fails the lint test.npm testinapps/web: 137 files, 1,780 tests, includinghtml-sinks.test.mjs(13, with three deliberate-violation fixtures),csp-lib.test.mjs(19) and the rewrittenindex-html.test.ts(6: no inline script, handler or style, no global leak).node packages/web-e2e/scripts/csp-e2e.mjs(Playwright's Chromium, software GL; realmeldframe-server, the crate'sserveexample on the realdist, a front proxy that makes one origin): 119 checks, 0 failed. 113 under the starting policy (the editor drawn with a frame, a rectangle, a text and an image from an uploaded asset, pixel probes; wasm served asapplication/wasmandimmutable; Inter asfont/woff2; the stored theme applied before the first paint; the gestures on the Svelte page and on the React copies, every dialog, menu, the palette, the shortcut sheet, tooltips, the Activity tab, Import, Manage and Export variables with a download and a copy, a text edit, the image picker; the design pages; the error page) with zerosecuritypolicyviolationevents, CSP console lines, blocked requests and workers, and every response of the static server carrying the headers. Eighteen attempts the policy must stop (inline script, handler,new Function,javascript:, foreignfetch, WebSocket, image, font, stylesheet, object, frame andbase,data:andblob:images, inline style element and attribute, a worker from ablob:URL, a framing page) are run as page code under the same headers and each is reported under the directive it breaks; a style set through the CSSOM reports nothing. Negative phase: three tightened policies (nowasm-unsafe-eval,connect-src 'none',default-src 'none') each produce a violation and the editor does not come up. Run by hand with--cspand a policy withoutwasm-unsafe-eval, the positive phases fail (9 passed, 4 failed, exit 1).cargo fmt --all --check,cargo clippy -p meldframe-http-web --all-targets -- -D warnings,cargo xtask deps-check,mm-check,size-check --base origin/develop,ui-literals,licences --check --main-only; inapps/webtypecheck,lint,boundaries,frozen,test,build,ui-literals,licences: all pass.git log origin/develop..HEAD --format=%B | sh scripts/ci/message-patterns.shprints nothing.Not run:
cargo deny check(cargo-deny is not installed here; the lock gains only the new crate, no new third-party crate, andlicences --checkpasses),cargo clippy --workspaceandcargo test --workspace(the crate and its dependants in the lock are untouched; CI runs them),sh scripts/ci/selftest.sh(no script changed).Not covered: Firefox and Safari; a real TLS connection (HSTS is read off the header); the policy behind a reverse proxy; the sign-in redirect (slice 11b does not exist); a request hyper refuses before the service sees it (a space or a backslash in the request line gets a bare 400 without the headers, so the reverse proxy must set them too); the window between the check of the resolved path and the open (a build directory that someone can write is out of scope); compression,
Last-Modified, several ranges; some gesture selectors of the browser check were found by reading markup, so a renamed control fails the check as "not found" and the script is fixed, not read as a violation; the Rune web client.Cora (agent, local): not independently reviewed. The deterministic pass
cora review --base origin/develop --no-llmis clean on the whole diff (its one finding, a hardcoded-secret rule on a per-run random token incsp-e2e.mjs, is a false positive and was avoided by moving the token into a function). The implementing agent cannot start an independent reviewer andcora mcpneeds one to judge, so there is no independent verdict, and a self-review of the Rust source found no defect.