Validate pubsub subscriptions (#627)
* Check topic before subscribing * Block subscribe to invalid topics
This commit is contained in:
parent
e72d03bc78
commit
1a97d0a2f5
|
@ -452,6 +452,11 @@ proc subscribe*(p: PubSub,
|
|||
## on every received message
|
||||
##
|
||||
|
||||
# Check that this is an allowed topic
|
||||
if p.subscriptionValidator != nil and p.subscriptionValidator(topic) == false:
|
||||
warn "Trying to subscribe to a topic not passing validation!", topic
|
||||
return
|
||||
|
||||
p.topics.withValue(topic, handlers) do:
|
||||
# Already subscribed, just adding another handler
|
||||
handlers[].add(handler)
|
||||
|
|
|
@ -147,6 +147,9 @@ suite "GossipSub":
|
|||
nodes[1].start(),
|
||||
))
|
||||
|
||||
# We must subscribe before setting the validator
|
||||
nodes[0].subscribe("foobar", handler)
|
||||
|
||||
var gossip = GossipSub(nodes[0])
|
||||
let invalidDetected = newFuture[void]()
|
||||
gossip.subscriptionValidator =
|
||||
|
@ -162,7 +165,6 @@ suite "GossipSub":
|
|||
|
||||
await subscribeNodes(nodes)
|
||||
|
||||
nodes[0].subscribe("foobar", handler)
|
||||
nodes[1].subscribe("foobar", handler)
|
||||
|
||||
await invalidDetected.wait(10.seconds)
|
||||
|
|
Loading…
Reference in New Issue