Stored XSS in as_link field view via unvalidated javascript: href
Description
The String type field view as_link renders a stored field value directly into an anchor href with no URL-scheme validation. A user who can write the field stores javascript:<payload> as the value, and when another user opens a Show, List, or Feed view that renders the field with as_link, the rendered response contains <a href="javascript:...">. Clicking the link runs the script in the Saltcorn origin. Saltcorn sends no Content-Security-Policy header, so execution is unconstrained.
The value passes through text(), the js-xss HTML filter, which neutralizes a dangerous URL scheme only when it appears inside a parsed HTML tag. A bare URL string carries no tag, so the filter returns it unchanged, and the markup attribute serializer escapes only ", <, and >. No code path validates the scheme.
Write access can be anonymous: a public Edit view backed by a table whose min_role_write is set to the public role accepts unauthenticated submissions. An administrator who later opens the view and clicks the link runs the attacker's JavaScript in an authenticated admin session.
Result: an anonymous user stores a javascript: payload through a public form, and it executes in an administrator's session on click, yielding account takeover through the user-administration endpoints.
Affected
saltcorn/saltcorn, package @saltcorn/data, version 1.6.0 (current latest as of 2026-06-27; identical code on main HEAD 3fc68f9). Any application where a String field is rendered with the as_link field view and a lower-privileged or anonymous role can write that field (a public submission form, link directory, or a profile "website" field). The default configuration sends no Content-Security-Policy header, so the injected javascript: URL executes without restriction. Not affected: fields rendered with the default as_text field view, which HTML-escapes the value.
Root cause
The as_link field view builds a({ href: text(s || "") }, ...) from the stored value s at packages/saltcorn-data/base-plugin/types.ts:1058-1067 (the href assignment is line 1062). text() is the js-xss filter at packages/saltcorn-markup/extra_tags.ts:47, which strips a javascript: scheme only inside a recognized HTML tag attribute, so a bare URL string passes through unchanged. The attribute serializer escAttrVal escapes only ", <, and > at packages/saltcorn-markup/mktag.ts:62-63, leaving javascript: intact. No code path on the render produces scheme validation, so javascript:alert(document.domain) reaches the DOM verbatim as the href. Write authorization for the value is governed by the table's min_role_write (packages/saltcorn-data/models/table.ts:2345), which defaults to admin (table.ts:780) but which an operator sets to the public role for any public-facing form, admitting anonymous submissions.
Reproduction
saltcorn/saltcorn:1.6.0 Docker with a PostgreSQL backend, default config (no Content-Security-Policy header).
- As admin, create a table with a String field, set the table
min_role_writeandmin_role_readto the public role, add a public Edit view (the submission form) and a public Show view that renders the field with theas_linkfield view. - As an anonymous user (unauthenticated session,
_csrfread from the form), submit the form with the field set to ajavascript:URL.
POST /view/<form> HTTP/1.1
Content-Type: application/x-www-form-urlencoded
_csrf=<csrf>&url=javascript:fetch('/useradmin',{method:'POST'})
HTTP/1.1 302 Found
Location: /- As any viewer, including an administrator, open the Show view; the response contains the unescaped href.
GET /view/<show>?id=1 HTTP/1.1
<a href="javascript:fetch('/useradmin',{method:'POST'})">Live-verified: an anonymous submission stored the javascript: value through a public form, and the Show view served <a href="javascript:..."> to a separate cookieless request; in a browser the payload executes in the Saltcorn origin on click (DOM write observed, no CSP).
Impact
- Script execution in the Saltcorn origin in the viewer's authenticated session, with no Content-Security-Policy to constrain it.
- Account takeover when an administrator views and clicks the link: the script reads the in-page CSRF token and posts to
/useradminto grant admin or create users. - Stored and persistent: the payload replays to every viewer of the view and survives restarts.
- Reachable by an anonymous user when a public submission form feeds an
as_linkfield, in the default no-CSP configuration.
Credit
Jan Kahmen, turingpoint (jan@turingpoint.de)