node-formidable / node-formidable/formidable

Formidable detects MIME-type according to the file extension and not by the real content

Open
#749 18 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area: files Priority: High Status: Accepted Status: In Progress Type: Enhancement
Dominant language
JavaScript
Stars
7.2k
Forks
689
Avg merge
3d 7h
Merged PRs (30d)
2

Description

Support plan
  • which support plan is this issue covered by? (e.g. Community, Sponsor, or
    Enterprise): Community
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes
Context
  • node version: 16.4.2
  • module (formidable) version: 3.0.0-canary.20210428
  • environment (e.g. node, browser, native, OS): Node.js
  • used with (i.e. popular names of modules):
  • any other relevant information:
    Formidable detects MIME-type according to the file extension and not by the real content. Which means that user can fake the file MIME by changing file's extension and as a result to upload to the server not allowed file types.

BTW, multer detects file's MIME not by the extension only.

What are you trying to achieve or the steps to reproduce?
  1. Given JPG file tst.jpg
  2. Rename it to tst.pdf
  3. Set a break point inside of uploader.parse(req, async (err, fields, files) => {…}
  4. Try to upload tst.pdf
uploader.parse(req, async (err, fields, files) => {
	if (err) {
		reject(err);
	} else {…}
});
What was the result you got?

mimetype = application/pdf

11_010801

What result did you expect?

mimetype = image/jpeg
Since this file is actually JPG file but with a from extension.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how uploader.parse assigns the uploaded file's MIME type during multipart parsing. Reproduce the tst.jpg-to-tst.pdf case, then inspect existing upload-related tests and the MIME-detection path. Done means the reported MIME type reflects the file content rather than only its extension, with coverage for the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.