diff --git a/pkg/transaction/authorizer.go b/pkg/transaction/authorizer.go index f03f3c3..b41a46f 100644 --- a/pkg/transaction/authorizer.go +++ b/pkg/transaction/authorizer.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "crypto/ed25519" + "github.com/pkg/errors" "github.com/golang/protobuf/proto" "github.com/kinecosystem/agora-common/kin" @@ -32,6 +33,7 @@ type authorizer struct { log *logrus.Entry mapper app.Mapper configStore app.ConfigStore + blockAnonTxns bool mint ed25519.PublicKey subsidizer ed25519.PublicKey subsidizerKey ed25519.PrivateKey @@ -45,6 +47,7 @@ type authorizer struct { func NewAuthorizer( mapper app.Mapper, configStore app.ConfigStore, + blockAnonTxns bool, webhookClient *webhook.Client, limiter *Limiter, subsidizer ed25519.PrivateKey, @@ -59,6 +62,7 @@ func NewAuthorizer( log: logrus.StandardLogger().WithField("type", "transaction/authorizer"), mapper: mapper, configStore: configStore, + blockAnonTxns: blockAnonTxns, webhookClient: webhookClient, limiter: limiter, mint: mint, @@ -117,7 +121,11 @@ func (s *authorizer) Authorize(ctx context.Context, raw solana.Transaction, il * } } if appIndex == 0 { - appIndex, _ = app.GetAppIndex(ctx) + appIndex, err = app.GetAppIndex(ctx) + if s.blockAnonTxns && (err != nil || appIndex == 0) { + log.Warn("Authorize: blocked anonymous transactions") + return a, errors.New("Authorize: blocked anonymous creations") + } } // diff --git a/service/agora/service.go b/service/agora/service.go index 5d7e81d..3c081ae 100644 --- a/service/agora/service.go +++ b/service/agora/service.go @@ -84,6 +84,7 @@ const ( // Agora Config agoraBlockAnonCreates = "AGORA_BLOCK_ANON_CREATES" + agoraBlockAnonTxns = "AGORA_BLOCK_ANON_TXNS" agoraSdkFilter = "AGORA_SDK_FILTER" // Events config @@ -278,6 +279,17 @@ func (a *app) Init(_ agoraapp.Config) (err error) { log.Warnf("Anonymous creations: ALLOWED") } + var blockAnonTxns = false + if len(os.Getenv(agoraBlockAnonTxns)) > 0 { + blockAnonTxns = os.Getenv(agoraBlockAnonTxns) == "true" + } + + if blockAnonTxns { + log.Warnf("Anonymous transactions: BLOCKED") + } else { + log.Warnf("Anonymous transactions: ALLOWED") + } + accountAuthorizer := account.NewAuthorizer( appMapper, appConfigStore, @@ -304,6 +316,7 @@ func (a *app) Init(_ agoraapp.Config) (err error) { authorizer, err := transaction.NewAuthorizer( appMapper, appConfigStore, + blockAnonTxns, webhookClient, txLimiter, subsidizer,