Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions django/core/checks/security/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@
id='security.W006',
)

W007 = Warning(
"Your SECURE_BROWSER_XSS_FILTER setting is not set to True, "
"so your pages will not be served with an "
"'X-XSS-Protection: 1; mode=block' header. "
"You should consider enabling this header to activate the "
"browser's XSS filtering and help prevent XSS attacks.",
id='security.W007',
)

W008 = Warning(
"Your SECURE_SSL_REDIRECT setting is not set to True. "
"Unless your site should be available over both SSL and non-SSL "
Expand Down Expand Up @@ -162,15 +153,6 @@ def check_content_type_nosniff(app_configs, **kwargs):
return [] if passed_check else [W006]


@register(Tags.security, deploy=True)
def check_xss_filter(app_configs, **kwargs):
passed_check = (
not _security_middleware() or
settings.SECURE_BROWSER_XSS_FILTER is True
)
return [] if passed_check else [W007]


@register(Tags.security, deploy=True)
def check_ssl_redirect(app_configs, **kwargs):
passed_check = (
Expand Down
3 changes: 2 additions & 1 deletion docs/ref/checks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ The following checks are run if you use the :option:`check --deploy` option:
set to ``True``, so your pages will not be served with an
``'X-XSS-Protection: 1; mode=block'`` header. You should consider enabling
this header to activate the browser's XSS filtering and help prevent XSS
attacks.
attacks. *This check is removed in Django 3.0 as the ``X-XSS-Protection``
header is no longer honored by modern browsers.*
* **security.W008**: Your :setting:`SECURE_SSL_REDIRECT` setting is not set to
``True``. Unless your site should be available over both SSL and non-SSL
connections, you may want to either set this setting to ``True`` or configure
Expand Down
4 changes: 4 additions & 0 deletions docs/ref/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2182,6 +2182,10 @@ Default: ``False``
If ``True``, the :class:`~django.middleware.security.SecurityMiddleware` sets
the :ref:`x-xss-protection` header on all responses that do not already have it.

Modern browsers don't honor ``X-XSS-Protection`` HTTP header anymore. Although
the setting offers little practical benefit, you may still want to set the
header if you support older browsers.

.. setting:: SECURE_CONTENT_TYPE_NOSNIFF

``SECURE_CONTENT_TYPE_NOSNIFF``
Expand Down
32 changes: 0 additions & 32 deletions tests/check_framework/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,38 +402,6 @@ def test_with_content_type_nosniff(self):
self.assertEqual(self.func(None), [])


class CheckXssFilterTest(SimpleTestCase):
@property
def func(self):
from django.core.checks.security.base import check_xss_filter
return check_xss_filter

@override_settings(
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
SECURE_BROWSER_XSS_FILTER=False,
)
def test_no_xss_filter(self):
"""
Warn if SECURE_BROWSER_XSS_FILTER isn't True.
"""
self.assertEqual(self.func(None), [base.W007])

@override_settings(MIDDLEWARE=[], SECURE_BROWSER_XSS_FILTER=False)
def test_no_xss_filter_no_middleware(self):
"""
Don't warn if SECURE_BROWSER_XSS_FILTER isn't True and
SecurityMiddleware isn't in MIDDLEWARE.
"""
self.assertEqual(self.func(None), [])

@override_settings(
MIDDLEWARE=["django.middleware.security.SecurityMiddleware"],
SECURE_BROWSER_XSS_FILTER=True,
)
def test_with_xss_filter(self):
self.assertEqual(self.func(None), [])


class CheckSSLRedirectTest(SimpleTestCase):
@property
def func(self):
Expand Down