Skip to content

prevent XSS in renaming dirs/files#2794

Open
samialfattani wants to merge 2 commits into
pallets-eco:masterfrom
samialfattani:fix/mkdir
Open

prevent XSS in renaming dirs/files#2794
samialfattani wants to merge 2 commits into
pallets-eco:masterfrom
samialfattani:fix/mkdir

Conversation

@samialfattani

Copy link
Copy Markdown
Contributor

Fixes #1506

This PR to prevent XSS security issue on renaming dirs or files

@samialfattani samialfattani marked this pull request as ready for review February 14, 2026 15:50
@ElLorans

Copy link
Copy Markdown
Contributor

LGTM, will wait a couple of days before merging in case somebody wants to chime in.

@samuelhwilliams samuelhwilliams left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this does any damage, but I don't think it's fair to say it fixes #1506 really. If there's any bad data already in someone's system then this won't help them.

We should make sure that we treat filenames as dangerous input everywhere they're rendered, and make sure they're escaped appropriately.

If #1506 is talking about this code, then we should run it through Jinja2's escape filter or similar.

For some reason I thought that would be on by default but maybe it's not?

I think happy to merge this, but not to mark 1506 as fixed.

@ElLorans

ElLorans commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for the input. @samialfattani , can you move to using something like werkzeug.secure_filename ? Hopefully you can replace a part of your code.

@ElLorans

ElLorans commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Sorry for not being clear, but I was thinking of replacing the regex with a check between the input and the result of secure_filename. Replacing the validator with secure_filename like you are doing represents a breaking change since you are silently renaming the file. Do we think this is a problem?

@samialfattani

Copy link
Copy Markdown
Contributor Author

Sorry for not being clear, but I was thinking of replacing the regex with a check between the input and the result of secure_filename. Replacing the validator with secure_filename like you are doing represents a breaking change since you are silently renaming the file. Do we thing this is a problem?

oh !! i spend a lot of time to replace the regex i hope this will not go for nothing. anyway i don't think that renaming the filename or directory is a breaking change since this technique is actually used in /rename and other places in the project. that's why i thought it is better to use the same way.

Comment thread flask_admin/contrib/fileadmin/__init__.py Outdated
@samialfattani

Copy link
Copy Markdown
Contributor Author

any thing i can do from my side ?

Comment thread flask_admin/contrib/fileadmin/azure.py
use `secure_filename()`

fix

fix typing

move `secure_filename` to be a filter of the StringField
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Stored Self XSS

3 participants