@cryptotaxi247 / kubo / commits / 6a81c72cf

correctly handle multi-hop dnslink resolution

Namesys returns `ErrResolveRecursion` when it stops recursing due to a depth limit. It doesn't return success. Alternative to #5199. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Jul 7, 2018 at 00:18 UTC 6a81c72cfb8d8c8e71307fb386e2ff3d3395df06
2 files changed +7 -2
core/corehttp/gateway_test.go
+4 -1
@@ -40,7 +40,10 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re
40 if depth == nsopts.UnlimitedDepth {
41 depth = math.MaxUint64
42 }
43 - for depth > 0 && strings.HasPrefix(name, "/ipns/") {
43 + for strings.HasPrefix(name, "/ipns/") {
44 + if depth <= 0 {
45 + return value, namesys.ErrResolveRecursion
46 + }
47 depth--
48
49 var ok bool
core/corehttp/ipns_hostname.go
+3 -1
@@ -7,6 +7,7 @@ import (
7 "strings"
8
9 core "github.com/ipfs/go-ipfs/core"
10 + namesys "github.com/ipfs/go-ipfs/namesys"
11 nsopts "github.com/ipfs/go-ipfs/namesys/opts"
12
13 isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain"
@@ -25,7 +26,8 @@ func IPNSHostnameOption() ServeOption {
26 host := strings.SplitN(r.Host, ":", 2)[0]
27 if len(host) > 0 && isd.IsDomain(host) {
28 name := "/ipns/" + host
28 - if _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1)); err == nil {
29 + _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1))
30 + if err == nil || err == namesys.ErrResolveRecursion {
31 r.Header.Set("X-Ipns-Original-Path", r.URL.Path)
32 r.URL.Path = name + r.URL.Path
33 }