Skip to content

Commit 459cb29

Browse files
authored
Create new config section for web security settings (#2815)
* Document the new config section * Add a link to the correct config-file from settings.py
1 parent ce80dcb commit 459cb29

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

NOTES.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ existing bug reports, go to https://github.com/uninett/nav/issues .
88
To see an overview of upcoming release milestones and the issues they resolve,
99
please go to https://github.com/uninett/nav/milestones .
1010

11+
NAV 5.9
12+
=======
13+
14+
Web security
15+
------------
16+
17+
While it is only relevant for older browsers, the HTTP header
18+
``X-XSS-Protection`` is set to ``1; mode=block``. It does not affect browsers
19+
that do not support it after all.
20+
21+
There's a new section in :file:`webfront/webfront.conf`, ``[security]``. When
22+
running in production with SSL/TLS turned on, there's a new flag ``needs_tls``
23+
that should also be toggled on. This'll turn on secure cookies (only sent over
24+
SSL/TLS). See also the new howto
25+
:doc:`Securing NAV in production </howto/securing-nav-in-production>`.
26+
1127
NAV 5.8
1228
=======
1329

doc/howto/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ Howtos
1919
setting-up-logging
2020
using_the_api
2121
api_parameters
22+
securing-nav-in-production
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
==========================
2+
Securing NAV in production
3+
==========================
4+
5+
Overview
6+
========
7+
8+
The default configuration of NAV is set up to work well during development, but
9+
needs to be tightened when running in production.
10+
11+
NAV consists of pages controlled by NAV itself, and pages served directly by
12+
the web server. Security features for NAV's own pages are controlled via the
13+
``[security]``-section in the file :file:`webfront/webfront.conf`, while
14+
security for the other pages are controlled directly by the web server.
15+
16+
17+
SSL/TLS
18+
=======
19+
20+
This needs to be turned on in the webserver itself. While there is no reason to
21+
serve any of NAV without SSL/TLS turned off, it is especially important for the
22+
pages controlled by NAV.
23+
24+
When the server serves NAV with SSL/TLS, ensure that the ``needs_tls``-flag in
25+
the ``[security]``-section is set to ``yes``. This explicitly turns on secure
26+
cookies, which is dependent on SSL being in use.

python/nav/django/settings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from nav.db import get_connection_parameters
3030
import nav.buildconf
3131
from nav.jwtconf import JWTConf
32+
from nav.web.security import WebSecurityConfigParser
3233

3334
ALLOWED_HOSTS = ['*']
3435

@@ -252,6 +253,21 @@
252253
'nav.web.info.searchproviders.UnrecognizedNeighborSearchProvider',
253254
]
254255

256+
## Web security options supported by Django
257+
# * https://docs.djangoproject.com/en/3.2/ref/middleware/#module-django.middleware.security
258+
# * https://docs.djangoproject.com/en/3.2/topics/http/sessions/
259+
# * https://docs.djangoproject.com/en/3.2/ref/clickjacking/
260+
#
261+
# Configured in etc/webfront/webfront.conf:
262+
# [security]
263+
# needs_tls = yes
264+
265+
SECURE_BROWSER_XSS_FILTER = True # Does no harm
266+
267+
_websecurity_config = WebSecurityConfigParser()
268+
_needs_tls = bool(_websecurity_config.getboolean('security', 'needs_tls'))
269+
SESSION_COOKIE_SECURE = _needs_tls
270+
255271
# Hack for hackers to use features like debug_toolbar etc.
256272
# https://code.djangoproject.com/wiki/SplitSettings (Rob Golding's method)
257273
if _config_dir:

python/nav/etc/webfront/webfront.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,9 @@ enabled = no
130130
# Some remote user systems need to be visited *after* NAV has logged the user
131131
# out. The default/unset value is "/"
132132
#post-logout-redirect-url=/magic/logout?nexthop=/
133+
134+
[security]
135+
# Whether NAV must be run under TLS or not. Toggling this to `yes` toggles web
136+
# security features that are only available with TLS/SSL enabled. In
137+
# development mode this defaults to `no`.
138+
# needs_tls = no

python/nav/web/security.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from pathlib import Path
2+
3+
from nav.config import NAVConfigParser
4+
5+
6+
class WebSecurityConfigParser(NAVConfigParser):
7+
DEFAULT_CONFIG_FILES = [str(Path('webfront') / 'webfront.conf')]
8+
DEFAULT_CONFIG = u"""
9+
[security]
10+
needs_tls=no
11+
"""

0 commit comments

Comments
 (0)