From 611e0f6ea91c80265869e1de4865081a82185376 Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Fri, 12 Dec 2014 22:58:06 +0100 Subject: [PATCH] Apply network block middleware on all POSTs --- dpaste/middleware.py | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)