v0.6.402: security, stored files go out as user content (#1139) #1141

Merged
Cordy merged 4 commits from sx1139 into main 2026-11-07 03:24:40 +00:00
Owner

Fixes #1139 (stored XSS through plain-mode links) and a second route the sweep found (WebDAV GET with the browser session served .html as text/html).

  • One helper httpx.UserContent on every route that returns stored file bytes: nosniff, a sandboxing CSP (default-src 'none'; img-src 'self' data:; media-src 'self'; style-src 'unsafe-inline'; sandbox allow-downloads), active types (HTML, XHTML, SVG, XML, JavaScript, MHTML) always as attachment with application/octet-stream; passive PDFs keep inline without the sandbox (Chrome won't show a sandboxed PDF).
  • New plain (keyless) links need the API-only setting shareLinksPlainAllowed (off): otherwise 403 link-mode-plain-disabled. The web app always makes key links; existing plain links keep working with the safe headers.
  • Review: no blockers; fix round added allow-downloads, route tests for every path, the data export ZIP, fail-closed on unparsable types. Chromium check: top-level image, audio and text still work under the policy; Safari/Firefox on the #1005 list.
Fixes #1139 (stored XSS through plain-mode links) and a second route the sweep found (WebDAV GET with the browser session served `.html` as `text/html`). - One helper `httpx.UserContent` on every route that returns stored file bytes: `nosniff`, a sandboxing CSP (`default-src 'none'; img-src 'self' data:; media-src 'self'; style-src 'unsafe-inline'; sandbox allow-downloads`), active types (HTML, XHTML, SVG, XML, JavaScript, MHTML) always as attachment with `application/octet-stream`; passive PDFs keep inline without the sandbox (Chrome won't show a sandboxed PDF). - New plain (keyless) links need the API-only setting `shareLinksPlainAllowed` (off): otherwise 403 `link-mode-plain-disabled`. The web app always makes key links; existing plain links keep working with the safe headers. - Review: no blockers; fix round added `allow-downloads`, route tests for every path, the data export ZIP, fail-closed on unparsable types. Chromium check: top-level image, audio and text still work under the policy; Safari/Firefox on the #1005 list.
One helper, httpx.UserContent, for every response that carries stored
bytes: public plain links and their ZIPs, strong-link payloads, the raw
and versions endpoints, WebDAV GET (the session cookie works there too),
OCM grant reads, OCM fetch, WOPI GetFile and the signed-in ZIP. HTML,
SVG, XML and JavaScript (by stored type or by name) are always
attachments; a missing type is application/octet-stream instead of
net/http's sniff; every answer but a passive PDF carries
default-src 'none'; img-src 'self' data:; media-src 'self';
style-src 'unsafe-inline'; sandbox.

POST /api/v1/shares with mode plain answers 403 link-mode-plain-disabled
unless the admin policy shareLinksPlainAllowed (API only, default off)
allows it. Existing plain links keep serving, with the safe headers.

Tests that make plain links opt the policy in; the raw endpoint's SVG
tests now expect an attachment (SVG is active).
S1: UserContentCSP ends in "sandbox allow-downloads": the sandboxed
document may start a download (a media player's own download button);
no script, no same-origin access. The HTML standard takes a download's
permission from the initiating document, so this is a hedge.
N2: every WHATWG JavaScript MIME type essence is active; an active answer
is sent as application/octet-stream, so nosniff refuses it as a script.
N3: the personal data export downloads go through httpx.UserContent.
N4: a stored type that does not parse is active (fail closed).
N5: application/x-pdf is a PDF (no sandbox), sent as application/pdf.
S2: header assertions for versions/raw, /api/v1/zip/{id}, /s/?zip=1
plain and strong, the strong payload, the OCM grant GET, ocm/fetch (a
remote text/html), WOPI GetFile and the export download; a test that
PUT /api/v1/settings with shareLinksPlainAllowed is audited.

Existing tests changed: preview_test.go and preview1097_test.go checked
that the policy ends in "sandbox"; they now compare the exact policy.
Cordy merged commit 2f9025421a into main 2026-11-07 03:24:40 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#1141
No description provided.