Commit 9bdec32d authored by Elger Jonker's avatar Elger Jonker

Fix #125 take in account CSP header, but don't mandate it

Former-commit-id: 4e401a6a
parent 7c9ed9ca
......@@ -107,6 +107,8 @@ def security_headers_rating_based_on_scan(scan, header='Strict-Transport-Securit
Classified as: Ignored
todo: should be enabled(?)
todo: we're going to need to split this up per header, there are too many code paths forming.
high, medium, low = 0, 0, 0
......@@ -114,7 +116,9 @@ def security_headers_rating_based_on_scan(scan, header='Strict-Transport-Securit
# We add what is done well, so it's more obvious it's checked.
if scan.rating == "True":
explanation = header + " header present."
elif scan.rating == "Using CSP":
explanation = "Content-Security-Policy header found, which covers the security aspect of the %s header." \
% header
explanation = "Missing " + header + " header."
......@@ -87,11 +87,26 @@ def analyze_headers(result: requests.Response, endpoint):
egss.domain = endpoint.uri_url()
#125: CSP can replace X-XSS-Protection and X-Frame-Options. Thus if a (more modern) CSP header is present, assume
that decisions have been made about what's in it and ignore the previously mentioned headers.
We don't mandate CSP yet because it's utterly complex and therefore comes with an extremely low adoption ratio.
X-Frame-Options: SAMEORIGIN ➡ Content-Security-Policy: frame-ancestors 'self'
X-XSS-Protection -> ('unsafe-inline')
X-Content-Type-Options is not affected.
generic_check(endpoint, response.headers, 'X-XSS-Protection')
generic_check_using_csp_fallback(endpoint, response.headers, 'X-XSS-Protection')
generic_check(endpoint, response.headers, 'X-Frame-Options')
generic_check_using_csp_fallback(endpoint, response.headers, 'X-Frame-Options')
generic_check(endpoint, response.headers, 'X-Content-Type-Options')
......@@ -160,6 +175,27 @@ def generic_check(endpoint: Endpoint, headers, header):
"Security Header not present: %s" % header)
def generic_check_using_csp_fallback(endpoint: Endpoint, headers, header):
# this is case insensitive
if header in headers.keys():
log.debug('Has %s' % header)
EndpointScanManager.add_scan(header, endpoint, 'True', headers[header])
# CSP fallback:
if "Content-Security-Policy" in headers.keys():
header, endpoint, 'Using CSP',
"Content-Security-Policy header found, which can handle the security from %s. Value: %s." %
(header, headers["Content-Security-Policy"]))
log.debug('Has no %s' % header)
header, endpoint, 'False',
"Security Header not present: %s, alternative header Content-Security-Policy not present." % header)
def error_response_400_500(endpoint):
# Set all headers for this endpoint to 400_500, which are not shown in the report.
# These are not shown in the report anymore. Not using this
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment