Skip to content

fix(auth): preserve NIP-OA owner for direct members - #4616

Open
cmyk wants to merge 1 commit into
block:mainfrom
Peakhunter:fix/nip-oa-direct-member-owner
Open

fix(auth): preserve NIP-OA owner for direct members#4616
cmyk wants to merge 1 commit into
block:mainfrom
Peakhunter:fix/nip-oa-direct-member-owner

Conversation

@cmyk

@cmyk cmyk commented Aug 3, 2026

Copy link
Copy Markdown

Summary

On membership-enforced relays, a directly admitted agent could authenticate successfully but lose the owner asserted by its valid NIP-OA tag.

Direct membership admission returns without an owner because membership alone does not establish ownership. The AUTH handler previously attempted NIP-OA owner extraction only on open relays, so the direct-member path skipped extraction entirely. The owner mapping was therefore not materialized, the observer cache was not populated, and auth_ctx.agent_owner_pubkey remained unset for later owner-authorized behavior.

This change supplements only a missing admission owner with the existing cryptographically verified NIP-OA resolver, then reuses the existing materialization path. It does not change membership admission or observer authorization.

Security properties are preserved:

  • an owner already returned by admission remains authoritative;
  • NIP-OA signatures are verified against the authenticated agent key before an owner is returned;
  • existing owner mappings remain first-write-wins;
  • conflicting mappings fail closed;
  • the auth context is populated only after the stored owner is confirmed to match.

Related issue

No open duplicate issue or PR found.

Related ownership and membership work:

Testing

Regression coverage exercises the real handle_auth boundary with PostgreSQL:

  • a direct relay member with a valid signed NIP-OA tag materializes the owner mapping, populates the observer cache, and sets auth_ctx.agent_owner_pubkey;
  • a pre-existing conflicting owner remains unchanged and the conflicting owner is not placed in the auth context;
  • absent and invalid tags preserve ordinary direct membership without an owner;
  • an owner returned by admission takes precedence over a conflicting tag.

Executed red/green proof:

  • RED: with only the production owner-resolution hunk temporarily restored to its pre-fix form, the direct-member regression failed because auth_ctx.agent_owner_pubkey remained None;
  • GREEN: after restoring the fix, both PostgreSQL-backed AUTH regressions passed.

Final verification:

  • cargo test -p buzz-relay handlers::auth -- --include-ignored — 8 passed, 0 failed
  • cargo clippy -p buzz-relay --tests -- -D warnings — passed
  • cargo fmt --check — passed
  • git diff --check — passed

No UI behavior changes; screenshots are not applicable.

Co-authored-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
Signed-off-by: Schrödinger’s Cat <62413+cmyk@users.noreply.github.com>
@cmyk
cmyk requested a review from a team as a code owner August 3, 2026 20:58
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.

1 participant