Skip to content

Commit

Permalink
Added decorator exclude_xframe_options_header
Browse files Browse the repository at this point in the history
  • Loading branch information
jkfran committed Jan 15, 2021
1 parent 27762db commit 905a057
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
12 changes: 11 additions & 1 deletion canonicalwebteam/flask_base/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@


def set_security_headers(response):
response.headers["X-Frame-Options"] = "SAMEORIGIN"
add_xframe_options_header = True

# Check if view_function has exclude_xframe_options_header decorator
if flask.request.endpoint in flask.current_app.view_functions:
view_func = flask.current_app.view_functions[flask.request.endpoint]
add_xframe_options_header = not hasattr(
view_func, "_exclude_xframe_options_header"
)

if add_xframe_options_header and "X-Frame-Options" not in response.headers:
response.headers["X-Frame-Options"] = "SAMEORIGIN"

return response

Expand Down
3 changes: 3 additions & 0 deletions canonicalwebteam/flask_base/decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def exclude_xframe_options_header(func):
func._exclude_xframe_options_header = True
return func
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="canonicalwebteam.flask-base",
version="0.7.2",
version="0.7.3",
description=(
"Flask extension that applies common configurations"
"to all of webteam's flask apps."
Expand Down

0 comments on commit 905a057

Please sign in to comment.