RangerMauve / js-ipfs-fetch

Use the same `fetch()` API browsers provide for HTTP, but for IPFS
https://youtu.be/kI9Issf3MNc?t=1606
MIT License
65 stars 7 forks source link

Validation of pubsub messages? #16

Open sim31 opened 1 year ago

sim31 commented 1 year ago

As I understand agregore browser enables pubsub subscriptions through fetch API.

I'm planning to use agregore for my project, but in addition to using pubsub it will eventually need to validate messages received through pubsub. I read that it is possible to tell libp2p which messages are valid so that invalid ones are not propagated. This would be useful for my use case. Searching around, I found that the way to do it in js is probably through datastore-pubsub.

I could probably add a dependency to js-datastore-pubsub for my webapp, but I see agregore already depends on ipfs-core, which depends on datastore-pubsub. And I was planning to use fetch API provided by agregore anyway.

Would it make sense for agregore to provide datastore-pubsub like API? Any advice for a solution in the short-term?

RangerMauve commented 1 year ago

At this stage, I would just perform the validation of the data upon receiving it in your JavaScript once you get the message in your EventSource.

Getting the validation logic from JS into the p2p protocol handler is a bit hard to do at the moment. We're making use of js-ipfs-core for wrapping over libp2p's pubsub right now and it looks like there's no interface there for doing extra validation the way there is in Go. https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/PUBSUB.md

What sort of validation logic were you hoping to do? Checking that the structure makes sense?

sim31 commented 1 year ago

I can do the validation after getting the message from EventSource. I'm more worried about the propagation of messages. Pubsub topic strings will be public and I'm wondering what will happen if someone starts spamming with invalid messages to that topic.

Does the ipfs node within agregore automatically propagate messages they subscribe to? If detect invalid only in my logic that won't stop the propagation of the messages I imagine, right?

sim31 commented 1 year ago

To answer your question about validation logic: validation might depend on some objects which will have to be fetched from IPFS by some peers. Some peers might already have it. I'd like peers who already have to not propagate invalid messages, so as to not make new peers do unecessary fetching and validation.

RangerMauve commented 1 year ago

Do you have any thoughts on what the fetch/EventSource interface should do to enable this?

It feels like we would need to add some way to execute arbitrary code that gets passed in from JS (maybe WASM?) but that also feels like major overkill.

Is this a major blocker for getting your app started / do you anticipate it being mandatory for things to work within the next 6 months or so?

sim31 commented 1 year ago

It's definitely not a blocker to get started. I just suspect it might become an issue later. I'm also considering some workarounds using IPNS.