summaryrefslogtreecommitdiff
path: root/django/middleware
diff options
context:
space:
mode:
authorMaxime Lorant <maxime.lorant@gmail.com>2015-08-23 20:54:15 +0200
committerTim Graham <timograham@gmail.com>2015-08-24 19:35:49 -0400
commit4ce433e811763f29c32e0553fe1e0070fd14c6a2 (patch)
tree21bf711c2c7f5fe80479dd7edb4e3c52bd1a142f /django/middleware
parentd3fdaf907db6a5be4d0391532d7e65688c19e851 (diff)
Fixed #25302 -- Prevented BrokenLinkEmailsMiddleware from reporting 404s when Referer = URL.
Diffstat (limited to 'django/middleware')
-rw-r--r--django/middleware/common.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/django/middleware/common.py b/django/middleware/common.py
index 376e82b939..fa38c63a24 100644
--- a/django/middleware/common.py
+++ b/django/middleware/common.py
@@ -159,10 +159,17 @@ class BrokenLinkEmailsMiddleware(object):
def is_ignorable_request(self, request, uri, domain, referer):
"""
- Returns True if the given request *shouldn't* notify the site managers.
+ Return True if the given request *shouldn't* notify the site managers
+ according to project settings or in three specific situations:
+ - If the referer is empty.
+ - If a '?' in referer is identified as a search engine source.
+ - If the referer is equal to the current URL (assumed to be a
+ malicious bot).
"""
- # '?' in referer is identified as search engine source
+ full_url = "%s://%s/%s" % (request.scheme, domain, uri.lstrip('/'))
if (not referer or
- (not self.is_internal_request(domain, referer) and '?' in referer)):
+ (not self.is_internal_request(domain, referer) and '?' in referer) or
+ (referer == uri or referer == full_url)):
return True
+
return any(pattern.search(uri) for pattern in settings.IGNORABLE_404_URLS)