Skip to content

Commit

Permalink
Disable CSP on admin views
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosenpfand committed Aug 16, 2023
1 parent e05eb74 commit 3c5e7f8
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions app/extended_security/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
from flask import abort, current_app
from flask_admin.form import SecureForm
from flask_admin.contrib.sqla import ModelView
from flask_admin.base import AdminIndexView
from flask_admin.base import AdminIndexView, expose
from flask_security import current_user

# Note: flask-admin templates do not support strict CSP, so we need to disable it here


class AdminSecurityMixIn:
def is_accessible(self) -> bool:
Expand All @@ -23,8 +25,37 @@ class AdminModelView(AdminSecurityMixIn, ModelView):
column_hide_backrefs = False
can_view_details = True
can_export = True
form_base_class = SecureForm
# TODO: CSRF validation fails!
# form_base_class = SecureForm

@expose("/")
def index_view(self):
return super().index_view()

index_view.talisman_view_options = {"content_security_policy": None}

@expose("/new/", methods=("GET", "POST"))
def create_view(self):
return super().create_view()

create_view.talisman_view_options = {"content_security_policy": None}

@expose("/edit/", methods=("GET", "POST"))
def edit_view(self):
return super().edit_view()

edit_view.talisman_view_options = {"content_security_policy": None}

@expose("/details/")
def details_view(self):
return super().details_view()

details_view.talisman_view_options = {"content_security_policy": None}


class ExtendedAdminIndex(AdminSecurityMixIn, AdminIndexView):
pass
@expose()
def index(self):
return super().index()

index.talisman_view_options = {"content_security_policy": None}

0 comments on commit 3c5e7f8

Please sign in to comment.