]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Reject SOCKS requests for "localhost" or ".local"
authorNick Mathewson <nickm@torproject.org>
Wed, 28 Mar 2012 07:19:00 +0000 (03:19 -0400)
committerNick Mathewson <nickm@torproject.org>
Wed, 28 Mar 2012 07:19:00 +0000 (03:19 -0400)
Sending them on is futile, since we will be told "127.0.0.1" and then
think we've been lied to.  Partial fix for 2822.

changes/bug2822.2 [new file with mode: 0644]
src/common/address.c
src/common/address.h
src/or/connection_edge.c

diff --git a/changes/bug2822.2 b/changes/bug2822.2
new file mode 100644 (file)
index 0000000..373741c
--- /dev/null
@@ -0,0 +1,6 @@
+  o Minor features:
+
+    - Don't bother trying to connect to addresses that we are sure will
+      resolve to 127.0.0.1: Getting 127.0.0.1 in a reply makes us think
+      we have been lied to, even when the address the client tried to
+      connect to was "localhost." Partial fix for bug 2822.
index 676c48589735498c68f95d63605ef069280ccbba..e379464ebf90a3bf1e1aa6eddbe901db9f821530 100644 (file)
@@ -1682,3 +1682,12 @@ get_interface_address(int severity, uint32_t *addr)
   return r;
 }
 
+/** Return true if we can tell that <b>name</b> is a canonical name for the
+ * loopback address. */
+int
+tor_addr_hostname_is_local(const char *name)
+{
+  return !strcasecmp(name, "localhost") ||
+    !strcasecmp(name, "local") ||
+    !strcasecmpend(name, ".local");
+}
index 4568c32bf94541ca10cc6297aad3ce4acb2ea7e7..125fd3818e761a199c5903af0bb036294d26e086 100644 (file)
@@ -191,6 +191,8 @@ int tor_addr_is_loopback(const tor_addr_t *addr);
 int tor_addr_port_split(int severity, const char *addrport,
                         char **address_out, uint16_t *port_out);
 
+int tor_addr_hostname_is_local(const char *name);
+
 /* IPv4 helpers */
 int is_internal_IP(uint32_t ip, int for_listening);
 int addr_port_lookup(int severity, const char *addrport, char **address,
index e19d7f07744e21fe7c3e3c16ce7d67eb97b000ae..fb09281fe54ab1b809f310ce44bd31eb0638df8d 100644 (file)
@@ -2000,8 +2000,9 @@ connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
       if (options->ClientRejectInternalAddresses &&
           !conn->use_begindir && !conn->chosen_exit_name && !circ) {
         tor_addr_t addr;
-        if (tor_addr_parse(&addr, socks->address) >= 0 &&
-            tor_addr_is_internal(&addr, 0)) {
+        if (tor_addr_hostname_is_local(socks->address) ||
+            (tor_addr_parse(&addr, socks->address) >= 0 &&
+             tor_addr_is_internal(&addr, 0))) {
           /* If this is an explicit private address with no chosen exit node,
            * then we really don't want to try to connect to it.  That's
            * probably an error. */