summaryrefslogtreecommitdiffhomepage
path: root/src/reqs.c
diff options
context:
space:
mode:
authorrofl0r <retnyg@gmx.net>2018-12-31 22:25:04 +0000
committerrofl0r <rofl0r@users.noreply.github.com>2019-12-21 00:43:45 +0000
commitcd005a94cec38e73ca796f1d142c193f48aaa27f (patch)
tree5d52094f8d2b207d5ae851fa86c1e86da498394d /src/reqs.c
parentf6d4da5d81694721bf50b2275621e7ce84e6da30 (diff)
implement detection and denial of endless connection loops
it is quite easy to bring down a proxy server by forcing it to make connections to one of its own ports, because this will result in an endless loop spawning more and more connections, until all available fds are exhausted. since there's a potentially infinite number of potential DNS/ip addresses resolving to the proxy, it is impossible to detect an endless loop by simply looking at the destination ip address and port. what *is* possible though is to record the ip/port tuples assigned to outgoing connections, and then compare them against new incoming connections. if they match, the sender was the proxy itself and therefore needs to reject that connection. fixes #199.
Diffstat (limited to 'src/reqs.c')
-rw-r--r--src/reqs.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/reqs.c b/src/reqs.c
index c576412..3adc473 100644
--- a/src/reqs.c
+++ b/src/reqs.c
@@ -49,6 +49,7 @@
#include "connect-ports.h"
#include "conf.h"
#include "basicauth.h"
+#include "loop.h"
/*
* Maximum length of a HTTP line
@@ -1560,6 +1561,20 @@ void handle_connection (int fd, union sockaddr_union* addr)
return;
}
+ if (connection_loops (addr)) {
+ log_message (LOG_CONN,
+ "Prevented endless loop (file descriptor %d): %s",
+ fd, peer_ipaddr);
+
+ indicate_http_error(connptr, 400, "Bad Request",
+ "detail",
+ "You tried to connect to the "
+ "machine the proxy is running on",
+ NULL);
+ goto fail;
+ }
+
+
if (check_acl (peer_ipaddr, addr, config.access_list) <= 0) {
update_stats (STAT_DENIED);
indicate_http_error (connptr, 403, "Access denied",