Skip to content

Conversation

@jazzyjackson
Copy link

Hi all, I found formidable to be a very useful library, but did not see a way to simply use the original filename as the destination pathname, so I am making that pull request in case you feel it can be included.

From what I can tell the code would otherwise use content-disposition headers if they carried filenames with them, but my barebones HTML form didn't send those headers, so I get the randomly generated hex filenames, even though the original name is sitting right on that File object (as .name).

Maybe I'm missing something simple in how to include filenames from the clientside, but either way, let me know!

Copy link
Collaborator

@xarguments xarguments left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Need to add this into the docs.
Could you please add it to the docs as well, so that could merge this?

@tania-dm
Copy link

Could somebody else add this to the docs? It's a nice-to-have feature :)

@reteps
Copy link

reteps commented Oct 13, 2019

i would love this option @xarguments

Copy link
Collaborator

@kvz kvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering about your usecase, how do you handle two users uploading the same avatar.jpg filename? Or even one user?

@reteps
Copy link

reteps commented Oct 14, 2019

@kvz this is a locally hosted web form so there is only 1 user. Keeping the file name
Would be a nice option.

@kvz
Copy link
Collaborator

kvz commented Oct 14, 2019 via email

@reteps
Copy link

reteps commented Oct 14, 2019

I agree, but I don’t have a good solution.

Copy link
Collaborator

@felixge felixge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch introduces an easily exploitable security hole.

IncomingForm.prototype._uploadPath = function(filename) {
var buf = crypto.randomBytes(16);
var name = 'upload_' + buf.toString('hex');
var name = this.keepFilenames ? filename : 'upload_' + buf.toString('hex');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging this patch would expose users of this flag to giving write access to their whole file system. 🤕

You can try for yourself:

curl  -F "upload=@$(pwd)/harmless.jpg;filename=../hahah.exploit" 'localhost:8080/upload'

Please don't merge this or similar patches. If somebody wants to use the original filenames, they can implement it themselves at their own risk.

@tunnckoCore
Copy link
Member

tunnckoCore commented Nov 28, 2019

Partly agree with @felixge. We will think something better for next minor or major release.

In reality, even if we merge it, code already in production env won't be vulnerable, until it enable it explicitly which won't happen until when they see that option was added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants