diff --git a/dpaste/middleware.py b/dpaste/middleware.py index c8b5bb8..909dabc 100644 --- a/dpaste/middleware.py +++ b/dpaste/middleware.py @@ -1,4 +1,5 @@ import socket +from django.http import HttpResponseBadRequest tor_bl = ( '{remote_addr}.{server_port}.{server_ip}' @@ -6,6 +7,12 @@ tor_bl = ( open_proxy_bl = ('{remote_addr}.dnsbl.proxybl.org') rev_ip = lambda ip: '.'.join(reversed(ip.split('.'))) +response = """

Access denied

+

It appears you're requesting this page from an open proxy or +the TOR network. These networks are blocked due to numerous +statutory violation related posts in the past.

+

If you think this is wrong, file +a bug on Github please.

""" def in_blacklist(request, bl, ip=None): ip = ip or request.META['REMOTE_ADDR'] @@ -52,3 +59,6 @@ class SuspiciousIPMiddleware(object): return request.is_tor_exit_node() or request.is_open_proxy() request.is_suspicious = check_suspicious + + if request.method == 'POST' and request.is_suspicious(): + return HttpResponseBadRequest(response)