codekingpro/portable-devtools
114k
1##########################################################################2#3# pgAdmin 4 - PostgreSQL Tools4#5# Copyright (C) 2013 - 2024, The pgAdmin Development Team6# This software is released under the PostgreSQL Licence7#8#########################################################################9 10from flask_wtf.csrf import CSRFProtect11from flask import request, current_app12 13 14class _PGCSRFProtect(CSRFProtect):15 def __init__(self, *args, **kwargs):16 super().__init__(*args, **kwargs)17 18 def init_app(self, app):19 super().init_app(app)20 self._pg_csrf_exempt(app)21 22 def _pg_csrf_exempt(self, app):23 """Exempt some of the Views/blueprints from CSRF protection24 """25 26 exempt_views = [27 'flask.app.<lambda>',28 'flask.scaffold.send_static_file', # For Flask 2.*29 'flask.blueprints.send_static_file',30 'flask_security.views.login',31 'flask_security.views.logout',32 'pgadmin.tools.translations',33 app.blueprints['redirects'],34 'pgadmin.browser.server_groups.servers.supported_servers-js',35 'pgadmin.tools.sqleditor.initialize_sqleditor',36 'pgadmin.tools.datagrid.panel',37 'pgadmin.tools.sqleditor.panel',38 'pgadmin.tools.debugger.initialize_target',39 'pgadmin.tools.debugger.direct_new',40 'pgadmin.tools.schema_diff.panel',41 'pgadmin.tools.schema_diff.ddl_compare',42 'pgadmin.authenticate.login',43 'pgadmin.tools.erd.panel',44 'pgadmin.tools.psql.panel',45 'pgadmin.preferences.get_all_cli',46 ]47 48 for exempt in exempt_views:49 self.exempt(exempt)50 51 52pgCSRFProtect = _PGCSRFProtect()53 