File tree 2 files changed +21
-2
lines changed
2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 126
126
127
127
# Middleware
128
128
MIDDLEWARE = (
129
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware' ,
129
130
'django.middleware.common.CommonMiddleware' ,
130
131
'django.contrib.sessions.middleware.SessionMiddleware' ,
131
132
'nav.web.auth.middleware.AuthenticationMiddleware' ,
260
261
# Example conf:
261
262
# [security]
262
263
# needs_ssl = yes
264
+ # frames_allow = self
263
265
264
266
SECURE_BROWSER_XSS_FILTER = True # Does no harm
265
267
266
268
_websecurity_config = WebSecurityConfigParser ()
267
269
_needs_tls = bool (_websecurity_config .getboolean ('security' , 'needs_tls' ))
268
270
SESSION_COOKIE_SECURE = _needs_tls
271
+ X_FRAME_OPTIONS = _websecurity_config .get_x_frame_options ()
269
272
270
273
# Hack for hackers to use features like debug_toolbar etc.
271
274
# https://code.djangoproject.com/wiki/SplitSettings (Rob Golding's method)
Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
3
- from nav .config import NAVConfigParser
3
+ from nav .config import NavConfigParserDefaultSection
4
4
5
5
6
- class WebSecurityConfigParser (NAVConfigParser ):
6
+ class WebSecurityConfigParser (NavConfigParserDefaultSection ):
7
+ SECTION = "security"
7
8
DEFAULT_CONFIG_FILES = [str (Path ('webfront' ) / 'webfront.conf' )]
8
9
DEFAULT_CONFIG = u"""
9
10
[security]
10
11
needs_tls=no
12
+ allow_frames=self
11
13
"""
14
+ FRAMES_OPTION = 'allow_frames'
15
+ FRAMES_DEFAULT = 'self'
16
+
17
+ def __init__ (self ):
18
+ super ().__init__ (self .SECTION )
19
+
20
+ # clickjacking-settings
21
+
22
+ def get_x_frame_options (self ):
23
+ "Translate CSP frame ancestors to the old X-Frame-Options header"
24
+ frames_flag = self .get (self .FRAMES_OPTION ) or self .FRAMES_DEFAULT
25
+ if frames_flag == 'none' :
26
+ return 'DENY'
27
+ return 'SAMEORIGIN'
You can’t perform that action at this time.
0 commit comments