Summary
Twenty CRM's file serving endpoints deliver uploaded content without specifying key HTTP response headers, causing uploaded HTML files to be rendered directly in the browser.
An authenticated attacker can upload a malicious HTML file with JavaScript that, when opened by another user, executes in the context of the Twenty CRM domain, potentially enabling session hijacking, account takeover, and sensitive data theft.
Affected context
This vulnerability appears in Twenty CRM deployments that allow users to upload files via the /files/* and /file/:fileFolder/:id endpoints.
It is most relevant when:
- Users can upload arbitrary file types (including
.htmlor content interpreted as HTML by browsers). - Download or view links to uploaded files are shared or accessible to other authenticated users.
- The CRM is accessed through standard web browsers that execute JavaScript for responses served under the application's domain.
Exploit preconditions
- Attack surface: Authenticated HTTP endpoints responsible for uploading and serving files.
- Required access: Attacker must have a valid account or otherwise be able to upload files to the CRM.
- Trigger point: Another user (or the attacker themselves) opens or directly navigates to the uploaded file's URL, such as
/files/*or/file/:fileFolder/:id. - Why exploitation is possible: The server streams file content with
fileStream.pipe(res)without settingContent-Type,Content-Disposition, orX-Content-Type-Optionsheaders. Browsers may interpret uploaded content as active HTML/JavaScript, causing it to execute within the origin of the Twenty CRM application.
Why this happens
The core issue stems from improper output handling for user-supplied files.
Instead of treating all uploaded content as opaque downloadable data, the application streams it back to the browser without explicit response headers controlling how the browser should interpret the content.
When HTML or HTML-like content is served without a restrictive Content-Type or X-Content-Type-Options: nosniff, browsers may render it as a full HTML document, executing embedded scripts in the application's origin.
This maps to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting), where attacker-supplied content is returned to clients and executed in a trusted context.
Potential impact
- Attackers may execute arbitrary JavaScript in the victim's browser under the Twenty CRM origin.
- Session tokens and authentication credentials could be stolen, enabling account takeover.
- Sensitive CRM data (contacts, deals, notes, emails, etc.) can be read or exfiltrated via script.
- Actions may be performed on behalf of victims (e.g., creating or modifying records) via forged requests.
- Malicious content can be used as a foothold for broader phishing or social engineering campaigns against CRM users.
General mitigation guidance
Effective mitigation focuses on treating uploaded files as untrusted and controlling how they are presented to clients:
- Serve all user-uploaded files with explicit, restrictive
Content-Typeheaders matching their intended media type and avoid generic types that browsers treat as HTML. - Use
Content-Disposition: attachmentfor files that should not be rendered inline, forcing download instead of in-browser execution where appropriate. - Set
X-Content-Type-Options: nosniffto prevent browsers from content-sniffing and reinterpreting file types as HTML or script. - Maintain a strict allowlist of permitted file types and reject or sanitize uploads that could be interpreted as active content (e.g., HTML, SVG with scripts).
- Isolate file delivery on a separate, cookieless domain or subdomain where feasible, so that even if HTML executes, it lacks access to CRM session cookies and sensitive APIs.
- Apply least-privilege principles to any components handling file uploads and serving responses, and avoid tying them directly to authenticated application state where possible.
How teams detect issues like this
Organizations can identify similar issues through a combination of review and automated checks:
- Static analysis and code review: Look for file-serving logic (e.g.,
stream.pipe(res),res.sendFile, or direct filesystem reads) where response headers are not explicitly set and user-controlled files are returned. - Security testing: Use browser-based testing to upload HTML or script-containing files and observe how they are rendered; note any execution within the main application origin.
- Policy enforcement: Establish coding guidelines that require setting
Content-Type,Content-Disposition, andX-Content-Type-Optionsfor file responses, enforced via linters or custom checks in CI pipelines. - Logging and monitoring: Track unusual access patterns to uploaded file URLs, particularly those with file extensions commonly associated with active content, and correlate with anomalous user actions.

