Skip to content

fix the CSRF token on delete files and directories#2829

Open
samialfattani wants to merge 14 commits into
pallets-eco:masterfrom
samialfattani:fix/csrf-fileadmin
Open

fix the CSRF token on delete files and directories#2829
samialfattani wants to merge 14 commits into
pallets-eco:masterfrom
samialfattani:fix/csrf-fileadmin

Conversation

@samialfattani
Copy link
Copy Markdown
Contributor

@samialfattani samialfattani commented Mar 11, 2026

CSRF token is not generated in the file/list.html page for both file and directory delete <form>. This PR uses csrf_token() to generate the token and put them in a hidden field to be submitted within the delete action.

Why this PR: it supports CSRF in file/list.html if the user useed flask_wtf.csrf.CSRFProtect

Test: This PR adds many test cases that covers all pages of FileAdmin() including list, rename, upload, ...etc. also there are some tests that include the csrf_token in the post request and assert the response to be 200 not 400.

@samialfattani samialfattani marked this pull request as ready for review March 18, 2026 17:53
samialfattani added a commit to samialfattani/flask-admin that referenced this pull request Apr 1, 2026
- fix the CSRF token on delete files and directories pallets-eco#2829
@samialfattani samialfattani mentioned this pull request Apr 1, 2026
9 tasks
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.

Why this edit?

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.

why this edit?


client = app.test_client()

assert "dummy.txt" in client.get(
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.

what are we testing for here?

samialfattani and others added 2 commits April 28, 2026 22:36
Co-authored-by: Copilot <copilot@github.com>
@samialfattani
Copy link
Copy Markdown
Contributor Author

could any one review this ? i think everything is ready here

{% if delete_form.csrf_token is defined and delete_form.csrf_token %}
{{ delete_form.csrf_token }}
{{ delete_form.csrf_token }}
{% elif csrf_token is defined and csrf_token %}
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.

Why this change?

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.

2 participants