Skip to content

Commit

Permalink
rejects shares to bogus account keys (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
autodidaddict authored Mar 13, 2024
1 parent 135ed96 commit fed64b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions internal/globalservice/event_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
"github.com/nats-io/nkeys"
"github.com/synadia-labs/natster/internal/models"
)

Expand Down Expand Up @@ -330,6 +331,10 @@ func (srv *GlobalService) validateCatalogSharedEvent(accountKey string, evt mode
if acct == nil {
return errors.New("rejecting catalog_shared event, can't share from a nonexistent account")
}
if !nkeys.IsValidPublicAccountKey(evt.Target) {
// sadly this will prevent us from sharing to ABOB or AALICE
return errors.New("target account is not a valid public key")
}
if slices.ContainsFunc(acct.OutShares, func(cat shareEntry) bool {
return cat.Account == accountKey && cat.Catalog == evt.Catalog
}) {
Expand Down
2 changes: 1 addition & 1 deletion natster/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func ShareCatalog(ctx *fisk.ParseContext) error {
return err
}

fmt.Printf("Shared catalog '%s' with target '%s'. Note: Natster makes no guarantees that the target account exists.\n",
fmt.Printf("Shared catalog '%s' with target '%s'.\nNote: Natster's backend makes no guarantees that the target account exists.\n",
ShareOpts.Name,
ShareOpts.AccountKey,
)
Expand Down

0 comments on commit fed64b8

Please sign in to comment.