Overview
| Artifact ID: | 3d485b4a3293ad35c5847bcd4055edecb2f0666532332374ef9df5497008127b |
|---|---|
| Ticket: | 6ff100027fb20471c973dcc2941412d6efd42f9a
Render embedded documentation instead of showing HTML source |
| User & Date: | dmestas on 2026-08-17 17:39:54 |
Changes
- comment changed to:
A repository's own documentation is currently unreadable: `/r/fossil/file/trunk/www/permutedindex.html` shows HTML source where fossil shows a rendered index. Fossil serves these through a separate `/doc/CHECKIN/FILE` route; quarry has no equivalent, so `file/` is the only view and it is a source view by design. ## How fossil does it `document_render()` (src/doc.c) dispatches on mimetype: - `text/x-fossil-wiki`, `text/x-markdown`, `text/x-pikchr` — through its converters - `text/html` — **only if** `doc_is_embedded_html()` passes, which requires the file to begin with `<div class='fossil-doc'>`. Fossil then wraps it in site chrome, lifts `data-title` as the page title, and pipes the body through `convert_href_and_output()` - anything else — the bare `else`: `cgi_set_content_type(zMime); cgi_set_content(pBody);`. Raw bytes, the file's own content type, no filtering Fossil does **not** sanitize embedded documents. Its gate is a CSP (src/style.c:631): default-src 'self' data:; script-src 'self' 'nonce-$nonce'; style-src 'self' 'unsafe-inline'; img-src * data: Inline script cannot run without the per-response nonce, which repository content cannot know. Note `script-src 'self'` still permits a committed `.js` referenced by `src`, so the model also leans on operator trust plus the `default-csp` setting. The wrapper is a real convention, not incidental: of the 10 `.html` files in fossil's tree, exactly 3 carry `class='fossil-doc'` — `www/permutedindex.html`, `www/caps/ref.html`, `www/server/index.html`. The other seven are meant to be served raw. Fossil never rewrites relative links. It does not need to: at `/doc/trunk/www/permutedindex.html` a bare `quickstart.wiki` href resolves to `/doc/trunk/www/quickstart.wiki` on its own. Only `$ROOT` and `$CURRENT` are expanded, and narrowly — inside a tag, after `href=` or `action=` only. That page uses `$ROOT` four times. ## What quarry already has `renderBody` (internal/api/register.go:1857) is already fossil's mimetype switch. `markup.Render` / `RenderFossilWiki` / `RenderPikchr` are the three converters. `file.get` already resolves symbolic versions like `trunk` through zit. A `/r/{repo}/doc/{version}/{path...}` route has the same shape as the existing file route, so relative links come free exactly as they do for fossil. ## What is missing 1. `/r/{repo}/doc/{version}/{path...}` route and a `doc.get` op 2. Embedded-HTML detection and title extraction (~40 lines; `doc_is_embedded_html` fully specifies it). The title must be read BEFORE sanitizing — the policy strips `class` and `data-title` from the wrapper div 3. `$ROOT` / `$CURRENT` expansion (~30 lines) 4. Raw passthrough for non-document types (images, CSS) so referenced assets resolve. This is where content-type and CSP decisions live, and it is a security decision rather than a rendering one ## Measured: the existing policy is nearly sufficient Running `markup.Sanitize` over `www/permutedindex.html` (8,754 bytes): - 125 of 126 links survive - all 126 list items survive - the `id` anchor survives - **lost**: the search `<form>`, and `class`/`data-title` on the wrapper div ## Decision to make Fossil's answer to hostile HTML is *no sanitizer, one CSP*. Quarry has *a sanitizer, no doc route*. Doing both is strictly stronger than fossil and costs nothing extra since the sanitizer is already written, fuzz-tested and corpus-gated — but some legitimate pages render degraded, such as losing that search form. Recommendation: ship sanitizer **and** CSP, then widen the policy from evidence. The corpus now carries fossil's, tk's and libspatialite's real doc trees to widen against, which beats widening from imagination. Estimate: about a day for the fossil-doc path (items 1–3), another day for raw passthrough (item 4). - status changed to: "Open"
- title changed to:
Render embedded documentation instead of showing HTML source