Skip to content

Commit

Permalink
Reduced nesting of CSP_MODE
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Bartlett committed May 15, 2015
1 parent a85949f commit 2029174
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions security/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,20 +662,16 @@ def __init__(self):
csp_dict = getattr(django.conf.settings, 'CSP_DICT', None)
err_msg = 'Middleware requires either CSP_STRING or CSP_DICT setting'

if not csp_mode:
if not csp_mode or csp_mode == 'enforce':
self._enforce = True
elif csp_mode == 'report-only':
self._enforce = False
else:
mode = csp_mode
if mode == 'enforce':
self._enforce = True
elif mode == 'report-only':
self._enforce = False
else:
logger.warn(
'Invalid CSP_MODE {0}, "enforce" or "report-only" allowed'
.format(mode),
)
raise django.core.exceptions.MiddlewareNotUsed
logger.warn(
'Invalid CSP_MODE {0}, "enforce" or "report-only" allowed'
.format(csp_mode),
)
raise django.core.exceptions.MiddlewareNotUsed

if not (csp_dict or csp_string):
logger.warning('{0}, none found'.format(err_msg))
Expand Down

0 comments on commit 2029174

Please sign in to comment.