Executing scripts on slack-files.com using SVG
Slack served user-uploaded SVG files from its file-hosting domain in a way that let scripts embedded in the SVG run in the browser. An attacker could upload a crafted SVG and get a victim to click it, executing script on the slack-files.com origin and enabling convincing phishing pages.
Originally disclosed on HackerOne
- Fixed in 2 months
- Disclosed after 3 months
Impact
Although slack-files.com is a sandbox domain, there are many ways to gain the victim's trust during phishing attack. For example, an attacker might render a fake log-in form with "You need to sign in to see this file" message and trick users into handing out their passwords.
Steps to reproduce
- Download attached to report or use the following code snippet to create SVG file:
<svg width="100%" height="100%" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" onload="alert('script')">
<script type="text/javascript"><![CDATA[
// some exploit code here
]]></script>
<circle cx="50" cy="50" r="50" fill="green" />
</svg>
A SVG script and other DOM elements is equivalent to the elements in HTML, so in the example above alert('script') will be executed on svg load event.
-
Upload constructed SVG file to some channel or dm in Slack.
-
Click on message with just uploaded file.
Observed
Clicking on message opens a new tab and navigates user to slack-files.com. Once SVG loaded the alert('script') is executing.
Also this file can be shared via public link. In this case victim should click on image preview to start script execute.
Expected
Users expect that after clicking on message with file they will see this file or file will be downloaded.
Possible fix
There are three ways:
-
If you want to continue render SVG files directly in users browsers, you should refuse executing inline scripts by serving attachments with
Content-Security-Policy: default-src 'none';header. For example GitHub uses this way (open dev console to observe CSP errors for SVG above: https://camo.githubusercontent.com/ce86214c84dcc6c0d85fc268c1c0b1a122fb37a0/687474703a2f2f6b616d696c2e6869736d2e72752f696d672f6578706c6f697461626c652e737667) But you need to be sure that users do not use deprecated browsers (see http://caniuse.com/#feat=contentsecuritypolicy) -
Do not use
image/svg+xmlContent-Type when serving files. Usetext/plain, so users will see just a raw inner of SVG file. -
Serve SVG files with
Content-Disposition: attachment;header. So browsers will start downloading attachment instead of render it in the browser.
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 host served uploaded SVG files with an image/svg+xml content type and no Content-Security-Policy or attachment disposition, so inline scripts inside the SVG executed in the browser.
Impact
Script execution on the slack-files.com origin could be used in phishing, for example by rendering a fake sign-in form to steal passwords; the domain is a sandbox, which limits what the script can reach.
What the attacker needed
A Slack account able to upload files; victim clicks the file message
The fix
Serve SVG attachments with a restrictive Content-Security-Policy, or as text/plain, or with a Content-Disposition attachment header so browsers download rather than render them.
How it was found
- Create an SVG file that contains an onload handler and a script block.
- Upload the SVG to a Slack channel or direct message.
- Click the message containing the uploaded file.
- The file opens in a new tab on slack-files.com and the script runs once the SVG loads.
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.
An SVG is an image format that can also contain scripts. If a website shows such a file directly in the browser instead of downloading it, the script inside the image runs as if it were part of that website. Here the file was hosted on a Slack domain, so the script ran there and could be used to show a fake login page.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.