Skip to content

Commit 1a9f27b

Browse files
committed
Check that NAAM ad provider matches peer ID in IPNS key
When fetching metadata from ads, check that provider matches the peer ID extracted from IPNS key. This should guarantee that the records resolved for a given IPNS key are only the ones published by the original publisher.
1 parent 9002ac9 commit 1a9f27b

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

indexer_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func (n *Naam) announce(ctx context.Context, ai *peer.AddrInfo, head cid.Cid) er
8080
return nil
8181
}
8282

83-
func (n *Naam) getNaamMetadata(ctx context.Context, mh multihash.Multihash) ([]byte, error) {
83+
func (n *Naam) getNaamMetadata(ctx context.Context, pid peer.ID, mh multihash.Multihash) ([]byte, error) {
8484
req, err := http.NewRequestWithContext(ctx, http.MethodGet, n.httpIndexerEndpoint+"/multihash/"+mh.B58String(), nil)
8585
if err != nil {
8686
return nil, err
@@ -104,7 +104,7 @@ func (n *Naam) getNaamMetadata(ctx context.Context, mh multihash.Multihash) ([]b
104104
for _, mhr := range r.MultihashResults {
105105
if bytes.Equal(mhr.Multihash, mh) {
106106
for _, pr := range mhr.ProviderResults {
107-
if bytes.Equal(pr.ContextID, ContextID) {
107+
if pr.Provider.ID == pid && bytes.Equal(pr.ContextID, ContextID) {
108108
return pr.Metadata, nil
109109
}
110110
}

naam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (n *Naam) Resolve(ctx context.Context, name string) (value path.Path, err e
8181
if err != nil {
8282
return "", err
8383
}
84-
metadata, err = n.getNaamMetadata(ctx, mh)
84+
metadata, err = n.getNaamMetadata(ctx, pid, mh)
8585
if err != nil {
8686
return "", err
8787
}

0 commit comments

Comments
 (0)