Project

General

Profile

Actions

Patch #23376

closed

Downloading of attachments with MIME type text/javascript fails

Added by Holger Just almost 8 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Category:
Attachments
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:

Description

Right now, if you try to download an attachment with content type text/javascript with Redmine 3, it will be blocked by the CSRF protection of Rails. The user-visible response will be an HTTP 422.

This is because Rails thinks that these attachments are dynamic JavaScript resources and thus have to fall under the same origin policy. Unless the request is an AJAX (hxr) request, the downloads are blocked by the verify_same_origin_request after filter which is part of the CSRF protection. This behavior was added to Rails 4.1 in https://github.com/rails/rails/pull/13345.

The attached patch excludes the AttachmentController#download action from this protection, allowing to download javascript attachments. This change won't cause an XSS vulnerability in Redmine but technically allows a specific attack of external sites:

  • Given the attacker (Mallory) knows the attachment download URL of a javascript attachment.
  • Given a user (Alice) is logged in to Redmine in their browser with permission to download the attachment.
  • If Mallory can trick Alice into visiting a Website which includes a <script> tag referencing the attachment, Alice's browser will download and execute the JS file as a classic CSRF. An attacker controlling the website might then be able to extract data from the executed script.

Unfortunately, there is not really a way around this if we want to support JS attachments (with the correct mime type) at all. Since JS attachments typically don't contain secrets though, this is probably acceptable. With the attached patch, we just fall back to the pre-Rails 4.1 behavior for attachments.

Note that this issue is not directly reproducible on Chrome as uploaded JS files are sent with application/javascript instead of text/javascript which doesn't trigger the rule in Rails.

The patch is only relevant for Redmine versions using Rails 4.1 or newer, i.e. Redmine 3. The issue was detected in Planio and fixed by our staff.


Files

Actions #1

Updated by Go MAEDA over 7 years ago

  • Target version set to Candidate for next minor release
Actions #2

Updated by Go MAEDA over 7 years ago

  • Target version changed from Candidate for next minor release to 3.3.1

I reproduced the problem by updating attachments table directly.
Setting target version to 3.3.1.

Actions #3

Updated by Jean-Philippe Lang over 7 years ago

  • Status changed from New to Resolved
  • Assignee set to Jean-Philippe Lang

Patch committed, thanks. Test changed to use its own attachment instead of a fixture.

Actions #4

Updated by Jean-Philippe Lang over 7 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF