summaryrefslogtreecommitdiff
path: root/obfs4proxy
diff options
context:
space:
mode:
authorYawning Angel <yawning@schwanenlied.me>2014-05-25 08:20:20 +0000
committerYawning Angel <yawning@schwanenlied.me>2014-05-25 08:20:20 +0000
commitb3d17c327b3d0f8cfd3ebf91e776e1f99bb81004 (patch)
treef7606efa172531b1f2447a82a04c461f397febb1 /obfs4proxy
parentd5c3a25dec7f235ce34890fcc0f9eb9e7933c2b0 (diff)
Validate the host component of the proxy URI.
Part of issue #7.
Diffstat (limited to 'obfs4proxy')
-rw-r--r--obfs4proxy/pt_extra.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/obfs4proxy/pt_extra.go b/obfs4proxy/pt_extra.go
index 4d629e8..56e16cb 100644
--- a/obfs4proxy/pt_extra.go
+++ b/obfs4proxy/pt_extra.go
@@ -30,8 +30,10 @@ package main
import (
"errors"
"fmt"
+ "net"
"net/url"
"os"
+ "strconv"
"git.torproject.org/pluggable-transports/goptlib"
)
@@ -131,5 +133,36 @@ func ptGetProxy() (*url.URL, error) {
return nil, ptProxyError(fmt.Sprintf("proxy URI has invalid scheme: %s", spec.Scheme))
}
+ err = validateAddrStr(spec.Host)
+ if err != nil {
+ return nil, ptProxyError(fmt.Sprintf("proxy URI has invalid host: %s", err))
+ }
+
return spec, nil
}
+
+// Sigh, pt.resolveAddr() isn't exported. Include our own getto version that
+// doesn't work around #7011, because we don't work with pre-0.2.5.x tor, and
+// all we care about is validation anyway.
+func validateAddrStr(addrStr string) error {
+ ipStr, portStr, err := net.SplitHostPort(addrStr)
+ if err != nil {
+ return err
+ }
+
+ if ipStr == "" {
+ return net.InvalidAddrError(fmt.Sprintf("address string %q lacks a host part", addrStr))
+ }
+ if portStr == "" {
+ return net.InvalidAddrError(fmt.Sprintf("address string %q lacks a port part", addrStr))
+ }
+ if net.ParseIP(ipStr) == nil {
+ return net.InvalidAddrError(fmt.Sprintf("not an IP string: %q", ipStr))
+ }
+ _, err = strconv.ParseUint(portStr, 10, 16)
+ if err != nil {
+ return net.InvalidAddrError(fmt.Sprintf("not a Port string: %q", portStr))
+ }
+
+ return nil
+}