Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow removing the X_FRAME_OPTIONS header or setting it from a view (fix #103) #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ override it at your proxy server, or you can set the environment variable of
``PLONE_X_FRAME_OPTIONS`` to whatever value you'd like plone.protect to set
this to globally.

You can opt out of this by making the environment variable empty.
You can opt out of this by making the environment variable empty, which will
remove the header entirely. Setting a custom value in a custom view will
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever.

override the environment variable.


Disable All Automatic CSRF Protection
Expand Down
11 changes: 10 additions & 1 deletion plone/protect/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,17 @@ def transformUnicode(self, result, encoding):
def transformIterable(self, result, encoding):
"""Apply the transform if required"""
# before anything, do the clickjacking protection
if X_FRAME_OPTIONS and not self.request.response.getHeader("X-Frame-Options"):
current_x_frame_options = self.request.response.getHeader("X-Frame-Options")
empty = ("", "None", None)

if X_FRAME_OPTIONS in empty and current_x_frame_options in empty:
self.request.response.headers.pop("x-frame-options", None)
elif X_FRAME_OPTIONS not in empty and current_x_frame_options is None:
# env var is set and header is not, set it
self.request.response.setHeader("X-Frame-Options", X_FRAME_OPTIONS)
else:
# Header present, leave it be regardless of env var
assert current_x_frame_options or current_x_frame_options == ""

if CSRF_DISABLED:
return
Expand Down