Skip to content

Commit

Permalink
Check that NAAM ad provider matches peer ID in IPNS key
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
masih committed Dec 13, 2022
1 parent 9002ac9 commit 1a9f27b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions indexer_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (n *Naam) announce(ctx context.Context, ai *peer.AddrInfo, head cid.Cid) er
return nil
}

func (n *Naam) getNaamMetadata(ctx context.Context, mh multihash.Multihash) ([]byte, error) {
func (n *Naam) getNaamMetadata(ctx context.Context, pid peer.ID, mh multihash.Multihash) ([]byte, error) {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, n.httpIndexerEndpoint+"/multihash/"+mh.B58String(), nil)
if err != nil {
return nil, err
Expand All @@ -104,7 +104,7 @@ func (n *Naam) getNaamMetadata(ctx context.Context, mh multihash.Multihash) ([]b
for _, mhr := range r.MultihashResults {
if bytes.Equal(mhr.Multihash, mh) {
for _, pr := range mhr.ProviderResults {
if bytes.Equal(pr.ContextID, ContextID) {
if pr.Provider.ID == pid && bytes.Equal(pr.ContextID, ContextID) {
return pr.Metadata, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion naam.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (n *Naam) Resolve(ctx context.Context, name string) (value path.Path, err e
if err != nil {
return "", err
}
metadata, err = n.getNaamMetadata(ctx, mh)
metadata, err = n.getNaamMetadata(ctx, pid, mh)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 1a9f27b

Please sign in to comment.