Skip to content
XSS Disclosed report Intermediate

Content-Security Policy bypass with File Uploads

The default Content-Security-Policy blocks inline scripts, but an attacker can bypass it by uploading a JavaScript file through the file-upload feature and referencing it in a script tag. The report also shows that script tags are filtered from messages, but an iframe with a srcdoc attribute can be used to load the uploaded script.

gronke Follow

Originally disclosed on HackerOne

High 8.3 View original
  • Triaged in 2 months
  • Fixed in 8 months
  • Disclosed after 2.8 years

Summary

The current default CSP header in Rocket.Chat prevents inline script execution, which can be bypassed by importing a script file uploaded via the Rocket.Chat file upload.

Description

The default CSP header blocks execution of inline-scripts. When a HTML injection vulnerability occurs though, that restriction can be bypassed by uploading a JavaScript file via the file-upload feature (with application/javascript or text/javascript content-type) to include it in a `<script src="<UPLOAD_URL></script>" tag.

It is worth noticing that script tags are removed from message content, but this filter can also be bypassed as following:

HTML
<iframe srcdoc="&#x3c;script src='/file-upload/<UPLOAD ID>/payload.js?download'></script>">

Releases Affected:

  • 4.0.3
  • 3.18.2

Steps To Reproduce (from initial installation to vulnerability):

  1. Upload payload as payload.js via File Upload feature
  2. Inject iframe with srcdoc via arbitary XSS

Suggested mitigation

  • Block script content-types from file-uploads
  • Filter frames from message body

Impact

The CSP unsafe-inline restriction can be bypassed by uploading script payload as File Upload.

The original report as published on HackerOne, by gronke. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

Likely the file-upload feature allows JavaScript content types and the message filter does not block iframe srcdoc attributes, so an attacker can host and load a script from the same origin.

Impact

The CSP restriction against inline scripts can be bypassed, allowing execution of attacker-supplied JavaScript when an HTML injection vulnerability is present.

What the attacker needed

HTML injection vulnerability present; File upload feature enabled

The fix

The report suggests blocking script content types from file uploads and filtering frames from the message body.

How it was found

  1. Upload a JavaScript file via the file upload feature.
  2. Inject an iframe with a srcdoc attribute that loads the uploaded script.

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.

A Content-Security-Policy (CSP) is a rule that tells the browser which scripts are allowed to run, and it often blocks scripts written directly in the page. This report shows that if an attacker can upload a JavaScript file to the site, they can load it as an external script and get around that rule. They also found a way to hide the script inside an iframe so that the site's filter does not remove it.

What is XSS?

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

More by gronke

View all

27 more disclosed reports, best first.

More from Rocket.Chat

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.