Rocket.Chat icon indicating copy to clipboard operation
Rocket.Chat copied to clipboard

[BUG] File uploads with name as path fixed

Open knrt10 opened this issue 5 years ago • 9 comments

Closes #12723

When file was being uploaded, problem was

fileUrl = `/file-upload/${ file._id }/${ encodeURI(file.name) }`;

was taking file name too. And when router was listening to

WebApp.connectHandlers.use('/file-upload/', then path type file names like ../, .., ../../bla etc were not rendered, which was a problem, as only fileID was needed so fileName is removed from fileUrl

knrt10 avatar Mar 13 '19 18:03 knrt10

@tassoevan @ggazzo would you please review

knrt10 avatar Mar 13 '19 19:03 knrt10

Why are you even trying to accept filenames with ../? This will introduce path traversal vulnerability if not correctly handled.

lorek123 avatar Mar 15 '19 14:03 lorek123

@lorek123 exactly. This PR solves that problem

knrt10 avatar Mar 15 '19 14:03 knrt10

I personally like having the file name on the download URL, don't you? it helps when sharing links..

I would the fix the file name (removing unwanted characters) in this case, instead of removing it from the URL.. what do you think?

sampaiodiego avatar Apr 04 '19 19:04 sampaiodiego

Hmm, let me try it that way.

knrt10 avatar Apr 04 '19 19:04 knrt10

@sampaiodiego updated with file name in URL. Working now

knrt10 avatar Apr 10 '19 12:04 knrt10

Also, I had to install path on both server and client because meteor-node-stubs was not working. It was not able to require path package on the client side

knrt10 avatar Apr 10 '19 13:04 knrt10

@MarcosSpessatto updated the PR.

knrt10 avatar Jun 14 '19 20:06 knrt10

IMHO we should always use the file.name for the path, but then we should prevent filenames to be saved with path sections, almost like this solution but then we don't need to transform it at the client side and prevent adding this really old path library as well.

rodrigok avatar May 30 '20 15:05 rodrigok