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

filename '.ext' seen as a valid file extension #465

Open
jkittner opened this issue Aug 12, 2021 · 2 comments
Open

filename '.ext' seen as a valid file extension #465

jkittner opened this issue Aug 12, 2021 · 2 comments

Comments

@jkittner
Copy link
Contributor

When using flask_wtf.file.FileAllowed to validate that a file has the correct file extension, a file named '.ext' is seen as having the correct file extension. For me this behavior was a little unexpected and I was wondering if this is intentional/correct.

  • on the one hand it does end with .ext so it is valid
  • on the other hand is this actually the file extension or the filename e.g. like a hidden file without an extension?

os.path.splitext('.ext') returns ('.ext', '') so it treats it as the filename, not the extension. Would it be consistent/more correct to replace the .endswith here with a comparision to os.path.splitext()[1]?

if any(filename.endswith("." + x) for x in self.upload_set):

a fix could be something like this maybe?:
https://github.com/theendlessriver13/flask-wtf/blob/741aa2ed138e3b821b364b41496d4af91aec1e9b/src/flask_wtf/file.py#L84-L87

Any thoughts on this? I think an (explicit) workaround would be to add a separate custom validator checking the filename itself?

@jkittner
Copy link
Contributor Author

Mhm I though a little more on this an my solution would not allow e.g. tar.gz (would become gz only), so a different approach would be necessary to solve both cases...

@PeterDaveHello
Copy link

PeterDaveHello commented Aug 16, 2021

If the filename is tar.gz or example.tar.gz, treat gz as its extension seems to be reasonable, you can and should be able to unzip it to tar or example.tar, and example.tar will be able to be un-tared.

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

No branches or pull requests

2 participants