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

Added Filepath.getSanitizedFilename, deprecated getFilename #12183

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

alexdboxall
Copy link
Contributor

Pull Request Checklist

Helpful things

Fixes

Fixes #8008

Purpose

Provides a new way of getting sanitized filepaths from a FilePart, via the getSanitizedFilename method, as discussed in #8007 and #8008. Also deprecates the old getFilename method that returns the raw path.

Background Context

In #8000, it was found that Play used a raw filepath in an insecure way. This particular case was fixed in #8007, but @gmethvin suggested a reusable method should be added for doing this, instead of just once-off fixes.

This change uses the builtin Java functionality in Path.normalize to do most of the processing, as suggested by @wsargent. It then uses getFileName to return the last part of the path.

Also checks for empty filepaths and unresolvable .. paths and throws a runtime error - there is no good way to sanitize these into a valid filepath.

Tests have also been written in SanitizedFilenameTest.java to check that it works correctly.

References

#8007 and #8008

@mkurz mkurz added this to the 2.9.1 / 3.0.1 milestone Nov 21, 2023
@mkurz mkurz modified the milestones: 2.9.1 / 3.0.1, 2.9.2 / 3.0.2 Dec 7, 2023
@mkurz mkurz modified the milestones: 2.9.2 / 3.0.2, 2.9.3 / 3.0.3 Feb 27, 2024
@mkurz mkurz modified the milestones: 3.0.3, 2.9.4 / 3.0.4 May 6, 2024
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.

Provide safer API for getting filenames of uploaded files
2 participants