Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example to only use last part of filename #8007

Merged
merged 1 commit into from Nov 10, 2017

Conversation

gmethvin
Copy link
Member

@gmethvin gmethvin commented Nov 9, 2017

Fixes #8000


// only get the last part of the filename
// otherwise someone can send a path like ../../home/foo/bar.txt to write to other files on the system
val filename = Paths.get(picture.filename).getFileName
Copy link
Contributor

@NathanC NathanC Nov 10, 2017

Choose a reason for hiding this comment

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

What do you think about making it so that request.body.file("foo") does this by default internally? Are there any valid use-cases for file uploads containing actual path fragments? Path traversal vulnerabilities can be pretty messy, and a secure-by-default solution seems preferable.

(If that's not feasible because of backwards compatibility, what about adding a sanitizedFileName method to the FilePart case class, that automatically does this?)

Copy link
Member Author

@gmethvin gmethvin Nov 10, 2017

Choose a reason for hiding this comment

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

@PainterAndHacker I was thinking that as well. I wanted to get this documentation fix in first so we can apply it to older branches of Play, but I do think we should have a way to access a sanitized version in Play's API. I opened issue #8008 for this.

Copy link
Contributor

@shkhln shkhln Nov 11, 2017

Choose a reason for hiding this comment

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

Are there any valid use-cases for file uploads containing actual path fragments?

There is https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory.

@gmethvin gmethvin merged commit fe18c5d into playframework:master Nov 10, 2017
@gmethvin gmethvin deleted the filename-fix branch November 10, 2017 23:05
gmethvin added a commit to gmethvin/playframework that referenced this pull request Nov 10, 2017
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.

None yet

3 participants