Skip to content

Commit b926504

Browse files
andreituicuCopilot
andcommitted
feat: sanitise uploaded HTML and SVG
Every HTML and SVG document written through da-admin is now reduced to the DA/Helix document format and stripped of XSS vectors before it is stored or forwarded. - src/utils/sanitize.js: parse5-based (hast-util-from-html) sanitiser with a DA allowlist (hast-util-sanitize) derived from da-parser's schema. Enforces the DA structure (header/main sections/footer, da-metadata), keeps the head subset html2md ingests, and returns the original bytes when nothing changed, so collab output, ETags and the empty-doc restore point are unaffected. SVG is re-serialised from an allowlist without scripts, handlers, animation, foreignObject or external references; CSS loses @import and external url(). - Hooks: POST/PUT /source (incl. collab and the HLX6 dual-write), HLX6 saveSource before forwarding, and POST /media for SVG. Mismatched extension/content type -> 415, oversize -> 413. Changed collab writes are logged but collab is not reset. - daResp: Content-Security-Policy (default-src 'none'; img-src 'self' https: data:; sandbox) and X-Content-Type-Options: nosniff on every response. - DA_SANITIZE=off kill switch; OpenAPI docs updated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 29c883e commit b926504

15 files changed

Lines changed: 1870 additions & 77 deletions

File tree

‎docs/openapi/source-api.yaml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ source:
4141
target already has a stored identifier that differs from `guid`, the request is rejected with
4242
a 409 response. When omitted, the service generates a UUID.
4343
44+
HTML (`.html` or `text/html`) and SVG (`.svg` or `image/svg+xml`) content is sanitised before it
45+
is stored. Markup outside the DA document format (scripts, event handlers, styles, unsafe URLs,
46+
unknown elements and attributes) is removed silently. HTML is normalised to the DA structure
47+
(`header`, `main` with section `div`s, `footer`, optional `da-metadata`), and content that is
48+
already clean is stored byte for byte. A file extension that does not match the content type
49+
is rejected with a 415 response; HTML over 10 MB or SVG over 5 MB is rejected with a 413 response.
50+
4451
**Important:** For files, the `path` parameter must include the file extension (e.g., `myfile.html`, `data.json`).
4552
For folders, omit the extension (e.g., `myfolder`).
4653
parameters:
@@ -72,6 +79,10 @@ source:
7279
$ref: "./responses.yaml#/401"
7380
'409':
7481
$ref: "./responses.yaml#/409"
82+
'413':
83+
description: The HTML or SVG content exceeds the size limit.
84+
'415':
85+
description: The content type does not match the file extension.
7586
'500':
7687
$ref: "./responses.yaml#/500"
7788
post:
@@ -91,6 +102,13 @@ source:
91102
target already has a stored identifier that differs from `guid`, the request is rejected with
92103
a 409 response. When omitted, the service generates a UUID.
93104
105+
HTML (`.html` or `text/html`) and SVG (`.svg` or `image/svg+xml`) content is sanitised before it
106+
is stored. Markup outside the DA document format (scripts, event handlers, styles, unsafe URLs,
107+
unknown elements and attributes) is removed silently. HTML is normalised to the DA structure
108+
(`header`, `main` with section `div`s, `footer`, optional `da-metadata`), and content that is
109+
already clean is stored byte for byte. A file extension that does not match the content type
110+
is rejected with a 415 response; HTML over 10 MB or SVG over 5 MB is rejected with a 413 response.
111+
94112
**Important:** For files, the `path` parameter must include the file extension (e.g., `myfile.html`, `data.json`).
95113
For folders, omit the extension (e.g., `myfolder`).
96114
Examples:
@@ -125,6 +143,10 @@ source:
125143
$ref: "./responses.yaml#/401"
126144
'409':
127145
$ref: "./responses.yaml#/409"
146+
'413':
147+
description: The HTML or SVG content exceeds the size limit.
148+
'415':
149+
description: The content type does not match the file extension.
128150
'500':
129151
$ref: "./responses.yaml#/500"
130152
delete:

0 commit comments

Comments
 (0)