2019-05-28 00:29:51 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2023-01-02 00:23:55 -06:00
|
|
|
# Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2019-05-28 00:29:51 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
#########################################################################
|
|
|
|
|
|
|
|
from flask_wtf.csrf import CSRFProtect
|
|
|
|
from flask import request, current_app
|
|
|
|
|
|
|
|
|
|
|
|
class _PGCSRFProtect(CSRFProtect):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2022-11-18 22:43:41 -06:00
|
|
|
super().__init__(*args, **kwargs)
|
2019-05-28 00:29:51 -05:00
|
|
|
|
|
|
|
def init_app(self, app):
|
2022-11-18 22:43:41 -06:00
|
|
|
super().init_app(app)
|
2019-05-28 00:29:51 -05:00
|
|
|
self._pg_csrf_exempt(app)
|
|
|
|
|
|
|
|
def _pg_csrf_exempt(self, app):
|
|
|
|
"""Exempt some of the Views/blueprints from CSRF protection
|
|
|
|
"""
|
|
|
|
|
|
|
|
exempt_views = [
|
2021-11-24 05:52:57 -06:00
|
|
|
'flask.app.<lambda>',
|
|
|
|
'flask.scaffold.send_static_file',
|
2019-05-28 00:29:51 -05:00
|
|
|
'flask_security.views.login',
|
|
|
|
'flask_security.views.logout',
|
|
|
|
'pgadmin.tools.translations',
|
|
|
|
app.blueprints['redirects'],
|
|
|
|
'pgadmin.browser.server_groups.servers.supported_servers-js',
|
2022-04-07 07:06:56 -05:00
|
|
|
'pgadmin.tools.sqleditor.initialize_sqleditor',
|
2019-05-28 00:29:51 -05:00
|
|
|
'pgadmin.tools.datagrid.panel',
|
2022-04-07 07:06:56 -05:00
|
|
|
'pgadmin.tools.sqleditor.panel',
|
2019-05-28 00:29:51 -05:00
|
|
|
'pgadmin.tools.debugger.initialize_target',
|
|
|
|
'pgadmin.tools.debugger.direct_new',
|
2020-01-10 04:09:32 -06:00
|
|
|
'pgadmin.tools.schema_diff.panel',
|
|
|
|
'pgadmin.tools.schema_diff.ddl_compare',
|
2021-01-16 05:36:50 -06:00
|
|
|
'pgadmin.authenticate.login',
|
|
|
|
'pgadmin.tools.erd.panel',
|
2021-05-25 09:42:57 -05:00
|
|
|
'pgadmin.tools.psql.panel',
|
2019-05-28 00:29:51 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
for exempt in exempt_views:
|
|
|
|
self.exempt(exempt)
|
|
|
|
|
|
|
|
|
|
|
|
pgCSRFProtect = _PGCSRFProtect()
|