Skip to content

Commit

Permalink
correctly handle multi-hop dnslink resolution
Browse files Browse the repository at this point in the history
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 <[email protected]>


This commit was moved from ipfs/kubo@6a81c72
  • Loading branch information
Stebalien committed Jul 7, 2018
1 parent 58545a5 commit 2ccbcc6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion gateway/core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func (m mockNamesys) Resolve(ctx context.Context, name string, opts ...nsopts.Re
if depth == nsopts.UnlimitedDepth {
depth = math.MaxUint64
}
for depth > 0 && strings.HasPrefix(name, "/ipns/") {
for strings.HasPrefix(name, "/ipns/") {
if depth <= 0 {
return value, namesys.ErrResolveRecursion
}
depth--

var ok bool
Expand Down
4 changes: 3 additions & 1 deletion gateway/core/corehttp/ipns_hostname.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

core "github.com/ipfs/go-ipfs/core"
namesys "github.com/ipfs/go-ipfs/namesys"
nsopts "github.com/ipfs/go-ipfs/namesys/opts"

isd "gx/ipfs/QmZmmuAXgX73UQmX1jRKjTGmjzq24Jinqkq8vzkBtno4uX/go-is-domain"
Expand All @@ -25,7 +26,8 @@ func IPNSHostnameOption() ServeOption {
host := strings.SplitN(r.Host, ":", 2)[0]
if len(host) > 0 && isd.IsDomain(host) {
name := "/ipns/" + host
if _, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1)); err == nil {
_, err := n.Namesys.Resolve(ctx, name, nsopts.Depth(1))
if err == nil || err == namesys.ErrResolveRecursion {
r.Header.Set("X-Ipns-Original-Path", r.URL.Path)
r.URL.Path = name + r.URL.Path
}
Expand Down

0 comments on commit 2ccbcc6

Please sign in to comment.