mirror of
https://github.com/django/django.git
synced 2025-10-28 16:16:12 +00:00
[1.9.x] Fixed #25302 (again) -- Ignored scheme when checking for bad referers.
The check introduced in4ce433ewas too strict in real life. The poorly implemented bots this patch attempted to ignore are sloppy when it comes to http vs. https. Backport of11f10b7from master
This commit is contained in:
@@ -383,11 +383,20 @@ class BrokenLinkEmailsMiddlewareTest(SimpleTestCase):
|
||||
self.req.META['HTTP_REFERER'] = self.req.path
|
||||
BrokenLinkEmailsMiddleware().process_response(self.req, self.resp)
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
# URL with scheme and domain should also be ignored
|
||||
self.req.META['HTTP_REFERER'] = 'http://testserver%s' % self.req.path
|
||||
BrokenLinkEmailsMiddleware().process_response(self.req, self.resp)
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
# URL with a different scheme should be ignored as well because bots
|
||||
# tend to use http:// in referers even when browsing HTTPS websites.
|
||||
self.req.META['HTTP_X_PROTO'] = 'https'
|
||||
self.req.META['SERVER_PORT'] = 443
|
||||
with self.settings(SECURE_PROXY_SSL_HEADER=('HTTP_X_PROTO', 'https')):
|
||||
BrokenLinkEmailsMiddleware().process_response(self.req, self.resp)
|
||||
self.assertEqual(len(mail.outbox), 0)
|
||||
|
||||
def test_referer_equal_to_requested_url_on_another_domain(self):
|
||||
self.req.META['HTTP_REFERER'] = 'http://anotherserver%s' % self.req.path
|
||||
BrokenLinkEmailsMiddleware().process_response(self.req, self.resp)
|
||||
|
||||
Reference in New Issue
Block a user