@@ -183,6 +183,10 @@ var (
183183 Entity : "mint" ,
184184 Action : "read" ,
185185 }},
186+ "/universerpc.Universe/Info" : {{
187+ Entity : "universe" ,
188+ Action : "read" ,
189+ }},
186190 "/universerpc.Universe/MultiverseRoot" : {{
187191 Entity : "universe" ,
188192 Action : "read" ,
@@ -339,22 +343,10 @@ var (
339343 Entity : "mailbox" ,
340344 Action : "read" ,
341345 }},
342- "/authmailboxrpc.Mailbox/MailboxInfo" : {{}},
343- }
344-
345- // defaultMacaroonWhitelist defines a default set of RPC endpoints that
346- // don't require macaroons authentication.
347- //
348- // For now, these are the Universe related read/write methods. We permit
349- // InsertProof as a valid proof requires an on-chain transaction, so we
350- // gain a layer of DoS defense.
351- defaultMacaroonWhitelist = map [string ]struct {}{
352- "/universerpc.Universe/AssetRoots" : {},
353- "/universerpc.Universe/QueryAssetRoots" : {},
354- "/universerpc.Universe/AssetLeafKeys" : {},
355- "/universerpc.Universe/AssetLeaves" : {},
356- "/universerpc.Universe/Info" : {},
357- "/authmailboxrpc.Mailbox/MailboxInfo" : {},
346+ "/authmailboxrpc.Mailbox/MailboxInfo" : {{
347+ Entity : "mailbox" ,
348+ Action : "read" ,
349+ }},
358350 }
359351)
360352
@@ -364,34 +356,63 @@ func MacaroonWhitelist(allowUniPublicAccessRead bool,
364356 allowUniPublicAccessWrite bool , allowPublicUniProofCourier bool ,
365357 allowPublicStats bool ) map [string ]struct {} {
366358
367- // Make a copy of the default whitelist.
368359 whitelist := make (map [string ]struct {})
369- for k , v := range defaultMacaroonWhitelist {
370- whitelist [k ] = v
360+
361+ // addEndpoints adds the given endpoints to the whitelist map.
362+ addEndpoints := func (endpoints ... string ) {
363+ for _ , endpoint := range endpoints {
364+ whitelist [endpoint ] = struct {}{}
365+ }
371366 }
372367
373368 // Conditionally whitelist universe server read methods.
374- // nolint: lll
375- if allowUniPublicAccessRead || allowPublicUniProofCourier {
376- whitelist ["/universerpc.Universe/QueryProof" ] = struct {}{}
377- whitelist ["/universerpc.Universe/FetchSupplyCommit" ] = struct {}{}
378- whitelist ["/universerpc.Universe/FetchSupplyLeaves" ] = struct {}{}
379- whitelist ["/authmailboxrpc.Mailbox/ReceiveMessages" ] = struct {}{}
369+ if allowUniPublicAccessRead {
370+ addEndpoints (
371+ "/universerpc.Universe/Info" ,
372+
373+ "/universerpc.Universe/AssetRoots" ,
374+ "/universerpc.Universe/QueryAssetRoots" ,
375+ "/universerpc.Universe/AssetLeafKeys" ,
376+ "/universerpc.Universe/AssetLeaves" ,
377+ "/universerpc.Universe/QueryProof" ,
378+
379+ "/universerpc.Universe/FetchSupplyCommit" ,
380+ "/universerpc.Universe/FetchSupplyLeaves" ,
381+
382+ "/authmailboxrpc.Mailbox/MailboxInfo" ,
383+ "/authmailboxrpc.Mailbox/ReceiveMessages" ,
384+ )
380385 }
381386
382387 // Conditionally whitelist universe server write methods.
383- // nolint: lll
384- if allowUniPublicAccessWrite || allowPublicUniProofCourier {
385- whitelist ["/universerpc.Universe/InsertProof" ] = struct {}{}
386- whitelist ["/universerpc.Universe/InsertSupplyCommit" ] = struct {}{}
387- whitelist ["/authmailboxrpc.Mailbox/SendMessage" ] = struct {}{}
388+ if allowUniPublicAccessWrite {
389+ addEndpoints (
390+ "/universerpc.Universe/InsertProof" ,
391+ "/universerpc.Universe/InsertSupplyCommit" ,
392+ "/authmailboxrpc.Mailbox/SendMessage" ,
393+ )
388394 }
389395
390396 // Conditionally add public stats RPC endpoints to the whitelist.
391397 if allowPublicStats {
392- whitelist ["/universerpc.Universe/QueryAssetStats" ] = struct {}{}
393- whitelist ["/universerpc.Universe/UniverseStats" ] = struct {}{}
394- whitelist ["/universerpc.Universe/QueryEvents" ] = struct {}{}
398+ addEndpoints (
399+ "/universerpc.Universe/QueryAssetStats" ,
400+ "/universerpc.Universe/UniverseStats" ,
401+ "/universerpc.Universe/QueryEvents" ,
402+ )
403+ }
404+
405+ // Conditionally whitelist public universe server proof courier methods.
406+ if allowPublicUniProofCourier {
407+ addEndpoints (
408+ "/universerpc.Universe/Info" ,
409+ "/universerpc.Universe/InsertProof" ,
410+ "/universerpc.Universe/QueryProof" ,
411+
412+ "/authmailboxrpc.Mailbox/MailboxInfo" ,
413+ "/authmailboxrpc.Mailbox/SendMessage" ,
414+ "/authmailboxrpc.Mailbox/ReceiveMessages" ,
415+ )
395416 }
396417
397418 return whitelist
0 commit comments