File tree 2 files changed +22
-3
lines changed
2 files changed +22
-3
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' ,
261
262
# Configured in etc/webfront/webfront.conf:
262
263
# [security]
263
264
# needs_tls = yes
265
+ # frames_allow = self
264
266
265
267
SECURE_BROWSER_XSS_FILTER = True # Does no harm
266
268
267
269
_websecurity_config = WebSecurityConfigParser ()
268
- _needs_tls = bool (_websecurity_config .getboolean ('security' , ' needs_tls' ))
270
+ _needs_tls = bool (_websecurity_config .getboolean ('needs_tls' ))
269
271
SESSION_COOKIE_SECURE = _needs_tls
272
+ X_FRAME_OPTIONS = _websecurity_config .get_x_frame_options ()
270
273
271
274
# Hack for hackers to use features like debug_toolbar etc.
272
275
# 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