fix the CSRF token on delete files and directories#2829
Open
samialfattani wants to merge 2 commits into
Open
Conversation
13 tasks
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
ElLorans
reviewed
Apr 7, 2026
ElLorans
reviewed
Apr 7, 2026
ElLorans
reviewed
Apr 7, 2026
Contributor
Author
|
could any one review this ? i think everything is ready here |
ElLorans
reviewed
May 21, 2026
use SecureForm fix fix fix fix fix fix Azure initial files fix fix fix fix add comment Co-authored-by: Copilot <copilot@github.com>
43a56dc to
4d7712f
Compare
Contributor
|
I still do not understand what is happening here: is this coming from another part of the repo? Sorry for being dense |
Contributor
Author
it supports CSRF if the user used from flask import Flask
from flask_wtf import CSRFProtect
from flask_admin import Admin
from flask_admin.contrib.fileadmin import FileAdmin
from flask_sqlalchemy import SQLAlchemy
from flask_babel import Babel
app = Flask(__name__)
app.config["SECRET_KEY"] = "secret"
babel = Babel(app)
csrf = CSRFProtect(app)
admin = Admin(app,)
@app.route("/")
def index():
return '<a href="/admin/">Click me to get to Admin!</a>'
class MyFileAdmin(FileAdmin):
editable_extensions = ["txt", "html", "js", "css"]
if __name__ == "__main__":
admin.add_view(MyFileAdmin("files/", name="Local Files", category="Menu"))
app.run(debug=True)you will find the same logic is applied in : flask-admin/flask_admin/templates/bootstrap4/admin/model/list.html Lines 136 to 147 in fe3eec9 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CSRF token is not generated in the
file/list.htmlpage for both file and directory delete<form>. This PR usescsrf_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.htmlif the user useedflask_wtf.csrf.CSRFProtectTest: 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.