Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relay-based event access-control with the ["-"] tag #1030

Merged
merged 7 commits into from
Jul 10, 2024

Conversation

fiatjaf
Copy link
Member

@fiatjaf fiatjaf commented Feb 8, 2024

Read about it in the NIP body: https://github.com/nostr-protocol/nips/blob/protected-events-tag/70.md

This is inspired by #1029, there is more discussion there.

@vitorpamplona
Copy link
Collaborator

So, relays and clients that don't yet support this tag will receive and rebroadcast the event everywhere as usual.

And the relays that do support it, will have to find a way to know what protected means (how to define: "published willingly" by its author) in each event.

verify that the authenticated public key matches the event author public key.

Doesn't that mean that, in a group, a user would only be able to download their own messages?

Protected Events
----------------

`draft` `optional`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`draft` `optional`
`draft` `mandatory`

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the simplicity, but it's gotta be widely adopted for it to be useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the requirement that relays reject events with "-" tag by default should actually be added to NIP01, and then this NIP would define when events with "-" tag can be accepted (when the author matches authenticated user). that would suggest that rejection of events with "-" tag is expected behavior, while making it optional to accept them under very specific parameters.

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 8, 2024

So, relays and clients that don't yet support this tag will receive and rebroadcast the event everywhere as usual.

Yes, but this NIP only works if it gets mass adoption by relays, which I think is not a large ask once most people are convinced of its usefulness.

Doesn't that mean that, in a group, a user would only be able to download their own messages?

No. This would fit other schemes, like #566, and reuse the authorization scheme already described in those.

It could also be relied upon by an encrypted DM or group chat scheme that would rely on relays not leaking metadata to anyone.

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 8, 2024

Also remember that in most cases, specially if a group is small enough, there will be no incentive for receivers of these protected events to go around searching for a rogue relay to which publish the data against the will of the original author.

And also most normal users wouldn't also download a special client that knows what are these rogue relays and uses them specifically to download the events leaked from groups that would otherwise be private. A normal NIP-29 client, for example, would never even try to download events from groups to which it doesn't belong.

Exceptions are not the rule.

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented Feb 8, 2024

this NIP only works if it gets mass adoption by relays
like #566, and reuse the authorization scheme already described in those

Those two things are mutually exclusive.

The protected tag doesn't reference which authorization scheme the relay should use. If we have separate implementations of #566, how would the relay know which one to apply?

Clients can use this tag to not automatically re-broadcast the event and require choosing relays when the user tries to re-broadcast. However users might not know where the event should go to make the choice themselves.

It feels very abstract/general. Which is unlike you @fiatjaf

@arthurfranca
Copy link
Contributor

Handy NIP to make an event be hosted just on relays that support NIPs/behavior the author needs.
Though feels not that useful without an event access control spec for relays.

@monlovesmango
Copy link
Member

love this. very simple but powerful (but as with all nostr policy, only as powerful as its adoption). honestly surprised me that this hasn't already been done.

I kinda think this should just be added to the NIP42 generally, right? if so, my next question is what use case are you envisioning where we would have authenticated writes but not authenticated reads (which would need this separate NIP)? if not, what use case would have authenticated reads but not benefit from authenticated writes?

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 11, 2024

NIP-29 groups, both private and public, would benefit from authenticated writes. DMs would benefit from authenticated reads and writes. Just kind1 notes would benefit from authenticated writes/unauthenticated reads when the user wants to have some control of what they have posted and a little more assurance that deleting notes would be possible, for example.

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 11, 2024

@vitorpamplona the reason I think it's ok to be generic here is that I just expect all relays to implement this with a two-line check: if protected tag is present reject by default so that requires it being generic -- but I agree that being generic is often bad and that this is very unlike me. Maybe I'm wrong here though.

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 11, 2024

What do you think of using a tag like ["-"] instead of ["protected"] for brevity?

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented Feb 11, 2024

But this requires changing the code: if protected tag is present reject

Most relays will not even realize that this PR is a thing. The default relay behavior of folks who do NOT implement this PR is to accept, not to reject. That's why I proposed changing the serialization: to reject by default on current relays and make it backward compatible (relays don't need to change) and they shouldn't be working with "protected" events without implementing this or the other PR.

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented Feb 11, 2024

Same for all clients: The default behavior for those not implementing this PR is to accept the protected event as a regular event and re-broadcast at will.

@monlovesmango
Copy link
Member

That's why I proposed changing the serialization: to reject by default on current relays and make it backward compatible (relays don't need to change) and they shouldn't be working with "protected" events without implementing this or the other PR.

but there's nothing stopping a relay from updating its serialization (which is easy if they are using a nostr library that keeps up with nips) without actually implementing the auth in the PR. so still doesn't accomplish the goal of forcing non-supporting relays to protect these events.

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented Feb 11, 2024

so still doesn't accomplish the goal of forcing

Nothing will ever force relays to auth correctly. That's not the point. If relays want to fuck around they can do it in a lot of ways.

The only point of the serialization change is to make sure only clients and relays that have seen NIP-42 and are minimally aware of the difference between public and protected events can receive and rebroadcast these events.

Otherwise, if protected events are just being treated like public events by a majority of clients and relays, nothing in this PR makes any sense.

@monlovesmango
Copy link
Member

The only point of the serialization change is to make sure only clients and relays that have seen NIP-42 and are minimally aware of the difference between public and protected events can receive and rebroadcast these events.

yes agree. my point is you can update your nostr library dependency (which has accounted for new serialization) without being explicitly aware of the difference between public and protected events. most aren't writing their serialization code themselves (I think).

@vitorpamplona
Copy link
Collaborator

Agree. My hope was that libraries requested an extra param (isAuthed: Boolean = false) to the serialization function which fails if the relay is not aware of NIP-42

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 11, 2024

But this requires changing the code: if protected tag is present reject

I know. This is obvious and is my base assumption!

I don't know why every time I mention this proposal to someone they have to point this out, but I guess I'll rewrite this proposal to make this more explicit.

Most relays will not even realize that this PR is a thing. The default relay behavior of folks who do NOT implement this PR is to accept, not to reject. That's why I proposed changing the serialization: to reject by default on current relays and make it backward compatible (relays don't need to change) and they shouldn't be working with "protected" events without implementing this or the other PR.

I'm not sure about that. There are like 3 or 4 big relay implementations. If they implement this, which they can very easily, we give the network a couple of months and suddenly this change is in effect mostly everywhere. I think it's worth trying. If it fails then it fails, we don't lose anything.

Changing the serialization would achieve the same result at the end, but at a much bigger cost. It would make writing basic Nostr event creation libraries and using these libraries much more cumbersome for everybody forever.

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented Feb 11, 2024

There are like 3 or 4 big relay implementations. If they implement this...

I think that is the main difference between our experiences. I don't expect the current public relay codebases to be the same as the relay code that will work with the protected events. In fact, I don't want to change the public relay's code at all.

Changing the serialization would achieve the same result at the end

The difference is subtle but it's real. In this approach, there will be public relays, protected relays, and the ad-hoc relays that don't know the difference between the two because they have not read this PR yet. Those ad-hoc relays will re-broadcast everything protected.

Same for clients. There will be clients that deal with the public events, clients that can deal with the protected events and those who don't know about this and will just scatter protected events everywhere.

The proposal to change the serialization minimizes the existence of 3rd set of both relays and clients, better protecting events that should be protected.

@monlovesmango
Copy link
Member

The proposal to change the serialization minimizes the existence of 3rd set of both relays and clients, better protecting events that should be protected.

agree this is the case. I think where we disagree is whether the better protection is enough to warrant such a drastic change to protocol fundamentals. IMO its not bc the network is always going to be vulnerable to malicious relays that don't follow the rules anyway, and this is the subset I am more concerned about. non-malicious actors that are ignorant of this NIP and accidentally spread protected events will diminish over time. I'd rather wait for that slow process to work itself out than force it with changes in serialization.

@arthurfranca
Copy link
Contributor

arthurfranca commented Feb 11, 2024

I wanna see pull requests adding the protected tag spec to 10 relay implementations then we have a deal @_@ hahah

@vitorpamplona
Copy link
Collaborator

vitorpamplona commented Feb 11, 2024

whether the better protection is enough to warrant such a drastic change to protocol fundamentals.

Don't get me wrong. I think the idea of changing the serialization is crazy as well (as I wrote in the PR itself). I don't think it is a change in fundamentals. To me, it is the start of a second Nostr relay network that is designed for private events (medical information in my case) while not forcing users to centralize in the hospital's or country's private relay. The public network shouldn't change to stay as simple as possible.

I would love to find a way to add to the serialization process a step where the relay has to prove one of the pubkeys was authenticated and in order to verify the event. In Clients, the client must prove it has access to the private key of one of the pubkeys listed in the event. That would be a dream. I would allow the event to be verified only on relays that are being used by the listed keys and those listed keys could move the event to any relay or client they want. But that is very far out.

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 12, 2024

I wanna see pull requests adding the protected tag spec to 10 relay implementations then we have a deal @_@ hahah

Working on that.

@fiatjaf fiatjaf changed the title relay-based event access-control with the ["protected"] tag relay-based event access-control with the ["-"] tag Feb 12, 2024
Copy link
Member

@monlovesmango monlovesmango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe name this 'Propagation Protected Events' or 'Write Protected Events' to make it clear it this NIP doesn't affect read access but doesn't really matter.

70.md Outdated Show resolved Hide resolved
70.md Outdated Show resolved Hide resolved
fiatjaf and others added 2 commits February 12, 2024 07:58
Co-authored-by: monlovesmango <96307647+monlovesmango@users.noreply.github.com>
Co-authored-by: monlovesmango <96307647+monlovesmango@users.noreply.github.com>
Copy link
Collaborator

@Semisol Semisol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm.

imo people still should not treat this NIP as a way to shove gift wraps/NIP-04/NIP-44 DMs into clients instead of proper solutions like SimpleX

Copy link
Member

@staab staab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better than any of the alternatives I've seen for keeping public events on a given relay. It's like delete, which also doesn't enforce anything, but is a useful hint.

70.md Outdated

When the `"-"` tag is present, that means the event is "protected".

A protected event is an event that can only be published to relays by its author. That allows the author to choose who can access their events (either by knowing in advance the relay policy with regards to reads or by means of an external relationship with the relay that is not specified here).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A protected event is an event that can only be published to relays by its author

What if optionally the "-" tag can have a list of pubkeys that are allowed to (re)publish the event (which may have been authored by someone else)?

It would be in line with for example a gift wrap that is authored by a random key but is meant to be "owned" by the receiving user (set on the p tag).

Copy link
Member

@staab staab Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would leak a lot of metadata if used with gift wraps, defeating the entire purpose.

Edit: I suppose with the p tag it would be ok. But if the recipient has the message I'm not sure why they would need to re-broadcast it.

Copy link
Collaborator

@vitorpamplona vitorpamplona Feb 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only users authed by the p-tag should be able to download GiftWraps. Anyone can upload.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if optionally the "-" tag can have a list of pubkeys that are allowed to (re)publish the event (which may have been authored by someone else)?

I thought of this too actually, I think it would work well. but figured that this NIP can always be extended to add this feature in the future so maybe just shelve it until theres an actual use case. most important thing right now is making rejection of events with "-" tag the default behavior.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that with e.g. ["-", "<author-pub>", "<receiver-pub>"] the receiver could rebroadcast it to backup for example a local copy to another relay.

But yeah for gift wraps it doesn't make much sense as the receiver could re-wrap the seal. Just an idea but yeah haven't give it much thought.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding authorized pubkeys to the - tag makes sense. Not all use cases of protected events require privacy at that level. And for GiftWraps, the p-tag is already visible anyway and AUTH on the p-tag is what could/should be required for GiftWraps.

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 13, 2024

Implemented here -- with the necessary AUTH support already: fiatjaf/khatru@cd4c25c

@monlovesmango
Copy link
Member

how about "Publication Protected Events"? or "Publish Protected Events"?

@fiatjaf
Copy link
Member Author

fiatjaf commented Feb 14, 2024

Whatever is fine for me, but I would prefer a smaller but meaningful name. A single word.

@nostr-wine
Copy link
Contributor

Simple enough and should be useful if relays adopt it. We will add this tag for subscriber-only events on creatr.nostr.wine.

@mikedilger
Copy link
Contributor

+1. Simple enough to get implemented everywhere quickly.

Implemented in chorus here:
mikedilger/chorus@1e2187b

70.md Outdated Show resolved Hide resolved
Co-authored-by: monlovesmango <96307647+monlovesmango@users.noreply.github.com>
@gsovereignty
Copy link
Contributor

This is by far the simplest solution to the problem, anyone who disagrees is probably a statist.

@fiatjaf
Copy link
Member Author

fiatjaf commented Apr 11, 2024

Strfry PR: hoytech/strfry#100

@jb55 jb55 mentioned this pull request Apr 18, 2024
6 tasks
jb55 added a commit to damus-io/strfry that referenced this pull request Jul 9, 2024
"a simple change can maybe fix the world."

Link: nostr-protocol/nips#1030

* fiatjaf (2):
      implement NIP-70, protected events.
      update supported nips list.
@jb55
Copy link
Contributor

jb55 commented Jul 9, 2024

This is live on the damus relay! I will also make a nip70 strfry plugin for https://github.com/damus-io/noteguard

jb55 added a commit to damus-io/noteguard that referenced this pull request Jul 9, 2024
This adds support for protected events

Link: nostr-protocol/nips#1030
Signed-off-by: William Casarin <jb55@jb55.com>
@jb55
Copy link
Contributor

jb55 commented Jul 9, 2024

NIP70 has been added to noteguard, so you can enable it on an unmodified strfry instance now.

@fiatjaf
Copy link
Member Author

fiatjaf commented Jul 10, 2024

This is implemented in Khatru, Chorus, nostr.wine and relay.damus.io.

@fiatjaf fiatjaf merged commit ae1906e into master Jul 10, 2024
@fiatjaf fiatjaf deleted the protected-events-tag branch July 10, 2024 12:00
@bezysoftware
Copy link
Contributor

Shouldn't the default behavior of dropping events (without auth) be mentioned in nip-01?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.