Summary
BookStack contains a stored cross-site scripting vulnerability in its drawing upload endpoint, where editor-level users can submit SVG content containing scripts. When the uploaded content is later accessed through the image gallery API, the script may execute in an administrator's browser because content is not sufficiently validated or protected by appropriate browser controls.
Affected context
The issue occurs in BookStack deployments where users with editor permissions can upload drawings through the affected endpoint. Risk increases when base64-encoded content is stored without inspection, SVG files are served without content-type enforcement, and gallery responses lack effective Content Security Policy protections.
Exploit preconditions
- Attack surface: Drawing upload and image gallery API functionality - Required access: An account with editor-level permissions or equivalent
upload capability
- Trigger point: An administrator or other privileged user accesses the
uploaded drawing through the gallery
- Why exploitation is possible: Unvalidated SVG content can be stored and
returned in a browser-executable context without adequate content-type or
script-execution restrictions
Why this happens
The vulnerability results from treating uploaded, base64-encoded content as trusted image data without validating its actual file type or inspecting active content. SVG files can contain script-capable markup, and serving them without appropriate response headers or browser isolation allows stored attacker-controlled content to execute in a victim's origin. This behavior maps to CWE-79, Improper Neutralization of Input During Web Page Generation, commonly known as cross-site scripting.
Potential impact
- An attacker may execute script in an administrator's browser context.
- The vulnerability could enable unauthorized actions using the victim's session.
- Sensitive information accessible to the victim may be exposed.
- Administrative settings or stored content may be modified.
- The application could be used to distribute persistent malicious content.
General mitigation guidance
Mitigation generally focuses on reducing trust in uploaded content and ensuring that user-controlled files cannot execute as active web content. Defensive patterns include decoding and validating uploads against a strict allowlist, rejecting script-capable formats when they are unnecessary, sanitizing SVG content with a well-maintained restrictive policy, and storing untrusted files outside the application origin where practical. Responses should enforce safe content types, prevent content sniffing, and apply a restrictive Content Security Policy. Upload and gallery capabilities should follow least privilege, with editor permissions limited to the smallest necessary scope.
How teams detect issues like this
Detection can include static analysis for upload handlers that persist user-controlled base64 data without file-type validation or sanitization. Code review should examine SVG handling, response Content-Type behavior, content-disposition settings, gallery API responses, and the presence of effective CSP policies. Dynamic testing can use benign marker files to verify that script-capable content is rejected or served as inert downloads. Policy enforcement may require approved file-type allowlists, centralized upload validation, and automated security checks in CI. Neutral automated code-review and dependency-analysis tools may help identify related patterns.

