Project

General

Profile

Actions

Defect #31968

open

MIME Content Type is not properly handled while attaching the files

Defect #31968: MIME Content Type is not properly handled while attaching the files

Added by Amit Mehendale over 7 years ago. Updated over 7 years ago.

Status:
Resolved
Priority:
Normal
Assignee:
-
Category:
Attachments
Target version:
-
Resolution:
Affected version:

Description

Recently upgraded to 4.0.4. While doing the Information security testing, Team raised a vulnerability
"The application does not validate the content type of file being uploaded. This would enable an adversary to upload a malicious file onto the server."

If I change the extension of a file from .com to .pdf, Redmine allows file upload in issues as attachment and stores contenttype as "*application/pdf*" in table.

Due to this issue we are unable to roll out new version.

Urgent help required.
Thanks


Files

WinSCP.pdf (286 KB) WinSCP.pdf This is a executable file and should not be allowed to upload Amit Mehendale, 2019-08-28 08:12
attachment.rb (16 KB) attachment.rb Amit Mehendale, 2019-08-28 14:41

Related issues 1 (1 open — 0 closed)

Related to Redmine - Feature #43473: Reject file uploads when actual MIME type does not match the file extensionNewActions

Updated by Go MAEDA over 7 years ago Actions #1

  • Category changed from Files to Attachments

Updated by Go MAEDA over 7 years ago Actions #2

What do you think about this workaround? It prevents web browsers from opening crafted PDF files inline.

diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index a334024b4..3ec3e0e69 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -249,7 +249,7 @@ class Attachment < ActiveRecord::Base
   end

   def is_pdf?
-    Redmine::MimeType.of(filename) == "application/pdf" 
+    Redmine::MimeType.of(filename) == "application/pdf" && MimeMagic.by_magic(File.open(diskfile)).type == 'application/pdf'
   end

   def is_video?

Updated by Amit Mehendale over 7 years ago Actions #3

Thanks for prompt help.

Made necessary Changes. Still file is getting uploaded in the system.

We need to block the upload itself if both types are not matching.

Updated by Amit Mehendale over 7 years ago Actions #4

added a new code in attachment.rb, en.yml(for custom error message).

Attaching new file for further reference.

Thanks for the help

Updated by Go MAEDA about 1 year ago Actions #5

  • Related to Feature #43473: Reject file uploads when actual MIME type does not match the file extension added
Actions

Also available in: PDF Atom