Stored XSS in attachment-display exploitable through SameSite
The compose attachment preview endpoint streamed uploaded HTML files inline without a restrictive Content Security Policy, so embedded JavaScript ran in the Roundcube origin. Because the endpoint needs a session key tied to a specific compose, an attacker could only reach a victim by tossing cookies from another same-site service and redirecting them to the crafted URL, leading to account takeover.
Originally disclosed on HackerOne
- Disclosed after 41 days
Summary:
The compose attachments preview endpoint renders user-uploaded HTML files inline without a restrictive Content Security Policy, allowing JavaScript execution. By uploading an HTML file and opening it via display-attachment, the script runs in the Roundcube origin. Attacking a user is only possible by setting cookies on the domain, which can be done from any subdomain of the site where Roundcube is hosted.
Steps To Reproduce:
- Set up a local Roundcube instance on an IP address (eg. 127.0.0.1)
- Edit
C:\Windows\System32\drivers\etc\hostson Windows or/etc/hostson Unix to contain the following entries:
127.0.0.1 mail.target.local
127.0.0.1 xss.target.local
(This simulates a single domain hosting both Roundcube and another service vulnerable to XSS)
- Log in to Roundcube on http://mail.target.local as the victim
- As the attacker, fill
USERNAMEandPASSWORDin (Attachment on the original report: poc.py) and run it
$ python3 poc.py
{'roundcube_sessid': '1798cbb4c1d7c7f9ca26069b52aac1aa', 'roundcube_sessauth': 'GfNmiyX5brPm4l814QUx62l5gsJKBXfU-1773063000'}
compose_id='183727919869aecb6499f76'
{"action":"upload","exec":"this.add2attachment_list(\"rcmfile11773063013009066400\",{\"html\":\"<a href=\\\"#load\\\" class=\\\"filename\\\" onclick=\\\"return rcmail.command('load-attachment','rcmfile11773063013009066400', this, event)\\\"><span class=\\\"attachment-name\\\">xss.html</span><span class=\\\"attachment-size\\\">(30 B)</span></a><a href=\\\"#delete\\\" onclick=\\\"return rcmail.command('remove-attachment','rcmfile11773063013009066400', this, event)\\\" title=\\\"Delete\\\" class=\\\"delete\\\" aria-label=\\\"Delete xss.html\\\"></a>\",\"name\":\"xss.html\",\"mimetype\":\"text/html\",\"classname\":\"text html\",\"complete\":true},\"u128763271\");\nthis.auto_save_start(false);\n"}
att_id='11773063013009066400'
----------------------------------------------------------------------------------------------------
document.cookie='roundcube_sessid=1798cbb4c1d7c7f9ca26069b52aac1aa; Path=/index.php/xss; Domain=.target.local'
document.cookie='roundcube_sessauth=GfNmiyX5brPm4l814QUx62l5gsJKBXfU-1773063000; Path=/index.php/xss; Domain=.target.local'
location.href = 'http://mail.target.local/index.php/xss?_task=mail&_action=display-attachment&_id=183727919869aecb6499f76&_file=rcmfile11773063013009066400';
- Copy the JavaScript code under the
-----line and open http://xss.target.local. Open DevTools and paste the copied JavaScript into the Console (in a real scenario you would do this through a real XSS vulnerability on whatever application runs underxss.target.local) - After pressing ENTER, notice the XSS popup from
mail.target.tldproving the XSS on a different origin was abused to get XSS on Roundcube:

Supporting Material/References:
Roundcube's compose flow lets users upload attachments and preview them through the mail/attachment_display action, which calls rcube_uploads::display_uploaded_file(). For HTML attachments, this path sets only Content-Type and streams the file body directly without the defensive handling used by the general attachment viewer (mail/get.php), which correctly wraps HTML in a safe container and sets CSP (script-src 'none'). As a result, when a user uploads an HTML file (e.g., xss.html) and clicks the attachment preview link (display-attachment), the browser executes the embedded script under the Roundcube origin. This is distinct from viewing HTML attachments in received messages, where CSP is explicitly enforced. The issue manifests in the compose attachment display flow, specifically the display-attachment endpoint, which does not add CSP headers or force safe download for active content types.
This vulnerable endpoint requires a specific key in $SESSION to be able to access a certain compose file due to a check in init(). This is only set randomly whenever a new mail is composited, so an attacker cannot prepare this payload for a victim directly. They need to have specific cookies to be authorized to view the XSS payload.
To overcome this, an attacker can make use of other services external to Roundcube that live on the same site (domain). These can all set cookies over the whole site, not just their origin, in a technique called "Cookie Tossing". All it takes is one vulnerable service on the same site to execute arbitrary JavaScript, which can then write to document.cookie with a domain of .target.local. All subdomains (including Roundcube) will then use that cookie. Then they can redirect to the vulnerable XSS URL on Roundcube to trigger the final XSS.
To preserve the original user's session, an attacker can use a specific Path= attribute on the cookie so any fetches to / will still use the victim's session, completely taking over their account.
In the DevTools it becomes clear how the cookies look combined in the end. Note the .target.local domains are the attacker's cookies, specific to the /index.php/xss path. And the other cookies were already there from the victim being logged in before the attack.

Impact
An attacker who has an account on Roundcube, and can find any XSS vulnerability on a same-site service next to Roundcube, can prepare a an attack that takes over the victim's Roundcube account. With this they can read all emails (eg. take over accounts through password resets), send emails from the victim's account, and make any changes to the settings.
In summary, the security of Roundcube now relies on the security of every other hosted application under the same domain.
Fix
Apply the same CSP rules as other attachment view endpoints so that HTML content cannot execute arbitrary JavaScript.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The display-attachment endpoint set only Content-Type and streamed HTML bodies directly, unlike the general attachment viewer which wraps HTML safely and sets a script-blocking CSP.
Impact
An attacker with a Roundcube account who finds any XSS on a same-site service could take over a victim's account, reading emails, sending mail and changing settings; the exploit depends on that second same-site XSS and on cookie tossing.
What the attacker needed
An account on Roundcube; an XSS on another same-site service; victim logged in to Roundcube; victim's browser loads attacker script
The fix
The endpoint should apply the same CSP rules as other attachment view endpoints so HTML content cannot execute JavaScript.
How it was found
- Set up a local Roundcube instance and add hosts entries mapping a mail host and a second host to the same address.
- Log in to Roundcube as the victim.
- As the attacker, run the script that uploads an HTML attachment and prints the compose and attachment identifiers.
- Open the second host, paste the script into the browser console to set domain-wide cookies and redirect to the display-attachment URL.
- Observe the script from the uploaded HTML executing in the Roundcube origin.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you upload a file to a webmail and preview it, the server sends the file back to your browser. If that file is HTML and the server does not tell the browser to block scripts, any JavaScript inside it runs as if it were part of the webmail site. Here the preview endpoint lacked that protection, and an attacker could plant cookies from a neighbouring subdomain so the victim's browser would open the malicious preview.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.