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

Set X-Frame-Options setting on a per-view basis #405

Merged
merged 2 commits into from
Jan 12, 2021
Merged
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
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ SETUP

- Please, read the [official v3.0 documentation](https://docs.djangoproject.com/en/3.0/topics/files/) for more details on file uploads.

5. If you're using Django 3.x with default SummernoteWidget, then

- Do not forget to set `X_FRAME_OPTIONS = 'SAMEORIGIN'` in your django settings.
- [Clickjacking Protection](https://docs.djangoproject.com/en/3.0/ref/clickjacking/)

6. Run database migration for preparing attachment model.
5. Run database migration for preparing attachment model.

python manage.py migrate

Expand Down Expand Up @@ -194,7 +189,7 @@ SUMMERNOTE_CONFIG = {

# Use proper language setting automatically (default)
'lang': None,

# Toolbar customization
# https://summernote.org/deep-dive/#custom-toolbar-popover
'toolbar': [
Expand Down
10 changes: 10 additions & 0 deletions django_summernote/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
else:
from django.utils.translation import ugettext as _
from django.views.generic import TemplateView
from django.utils.decorators import method_decorator
from django.views.decorators.clickjacking import xframe_options_sameorigin

from django_summernote.forms import UploadForm
from django_summernote.utils import get_attachment_model, using_config, \
Expand Down Expand Up @@ -44,6 +46,10 @@ def __init__(self):
+ static_default_js \
+ config['js']

@method_decorator(xframe_options_sameorigin)
def dispatch(self, *args, **kwargs):
return super(SummernoteEditor, self).dispatch(*args, **kwargs)

@using_config
def get_context_data(self, **kwargs):
context = super(SummernoteEditor, self).get_context_data(**kwargs)
Expand All @@ -65,6 +71,10 @@ def test_func(self):
def __init__(self):
super(SummernoteUploadAttachment, self).__init__()

@method_decorator(xframe_options_sameorigin)
def dispatch(self, *args, **kwargs):
return super(SummernoteUploadAttachment, self).dispatch(*args, **kwargs)

def get(self, request, *args, **kwargs):
return JsonResponse({
'status': 'false',
Expand Down