Repository navigation
Commit 0820dea
fix(relay): trust and time-bound the NIP-OA owner before recording it
Review of the previous commit found two ways it granted authority from an
attestation that had not earned it, plus a test gap that hid both.
**The claimed owner must be trusted, not merely attested.** On a closed
relay the only prior path to an owner was `ViaOwner`, which requires the
owner to be a relay member. `resolve_nip_oa_owner` bypassed that for direct
members: any member could mint a throwaway keypair, attest itself, and have
that key recorded. The resolved owner is not inert — `materialize_nip_oa_owner`
creates a user row for it, and `connection.rs:632` derives `is_agent` from
`agent_owner_pubkey.is_some()` alone, switching the message limit from 60/min
to 120/min. So a member could double its own quota. Worse, `set_agent_owner`
is first-write-wins: one authentication with a wrong or stale tag pins that
mapping permanently and the legitimate owner is refused afterwards, which is
durable corruption rather than a transient privilege bump. The claimed owner
must now be a relay member on closed relays, exactly as `ViaOwner` demands.
Open relays are unchanged — with no membership boundary there is nothing to
check against. `allow_nip_oa_auth` stays out of it: its own doc comment
scopes it to granting *membership*, which this never does.
**A signature that verifies is not a credential that is valid.**
`validate_conditions` is purely syntactic — it checks `created_at<N` is a
canonical decimal and never compares N to anything — so an expired tag was
indistinguishable from a live one. `evaluate_time_bounds` and
`verify_auth_tag_at` add that evaluation, judged against the `created_at` of
the signed authentication event that carried the tag (the NIP-42 AUTH event,
or the NIP-98 request event) rather than wall clock, because the bound is a
property of what the owner authorized. The semantics are not invented here:
`enforce_request_auth_time_bounds` already enforced these clauses for NIP-IA
archive requests with both bounds strict, and now delegates to the shared
evaluator so the two cannot drift.
The bounds are enforced even when the membership gate already resolved an
owner, since that gate does not evaluate them — an expired tag can still
produce a `ViaOwner` decision. Leaving that pre-existing membership grant
alone is deliberate and out of scope here; what changes is that it can no
longer be *materialized* into an ownership record.
Time bounds gate granting, never denying. `extract_nip_oa_owner` keeps its
signature-only behaviour for the ban cascades in `handlers::auth` and
`api::git::transport`: widening who gets denied is safe, and an expired
attestation must not become an escape hatch from an owner ban.
`verify_bridge_auth` now reports the NIP-98 request event's `created_at`.
It is `None` under X-Pubkey dev auth, where nothing was signed and there is
no timestamp to judge bounds against; no ownership is recorded in that case
rather than treating the tag as unbounded.
The four unit tests this replaces did not protect the regression — reverting
both production call sites left them green, because they exercised the helper
rather than its callers. They are replaced with coverage of what is genuinely
pure (time bounds, signature binding, and the grant/deny split). The
Postgres-backed tests through the real HTTP and NIP-42 paths are still owed,
along with the CI filter that selects them: no job currently runs
`api::relay_members::tests` at all.
Also corrects three doc comments the previous commit falsified, including
`AuthContext::agent_owner_pubkey`, which still claimed `None` for direct
relay members.
Refs block#4223, block#4937, block#4260.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Roberto Michelena <[email protected]>1 parent 491ddd1 commit 0820dea
8 files changed
Lines changed: 453 additions & 101 deletions
File tree
- crates
- buzz-auth/src
- buzz-relay/src
- api
- handlers
- buzz-sdk/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | | - | |
78 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
58 | 72 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
65 | 76 | | |
66 | 77 | | |
67 | 78 | | |
68 | | - | |
| 79 | + | |
69 | 80 | | |
70 | 81 | | |
71 | 82 | | |
| |||
76 | 87 | | |
77 | 88 | | |
78 | 89 | | |
79 | | - | |
| 90 | + | |
80 | 91 | | |
81 | 92 | | |
82 | 93 | | |
| |||
111 | 122 | | |
112 | 123 | | |
113 | 124 | | |
114 | | - | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
115 | 130 | | |
116 | 131 | | |
117 | 132 | | |
| |||
120 | 135 | | |
121 | 136 | | |
122 | 137 | | |
123 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
124 | 143 | | |
125 | 144 | | |
126 | 145 | | |
| |||
637 | 656 | | |
638 | 657 | | |
639 | 658 | | |
640 | | - | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
641 | 664 | | |
642 | 665 | | |
643 | 666 | | |
| |||
650 | 673 | | |
651 | 674 | | |
652 | 675 | | |
653 | | - | |
654 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
655 | 686 | | |
656 | 687 | | |
657 | 688 | | |
| |||
760 | 791 | | |
761 | 792 | | |
762 | 793 | | |
| 794 | + | |
763 | 795 | | |
764 | 796 | | |
765 | 797 | | |
| |||
811 | 843 | | |
812 | 844 | | |
813 | 845 | | |
814 | | - | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
815 | 863 | | |
816 | 864 | | |
817 | 865 | | |
| |||
902 | 950 | | |
903 | 951 | | |
904 | 952 | | |
905 | | - | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
906 | 958 | | |
907 | 959 | | |
908 | 960 | | |
| |||
1389 | 1441 | | |
1390 | 1442 | | |
1391 | 1443 | | |
1392 | | - | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
1393 | 1449 | | |
1394 | 1450 | | |
1395 | 1451 | | |
| |||
2157 | 2213 | | |
2158 | 2214 | | |
2159 | 2215 | | |
2160 | | - | |
2161 | | - | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
2162 | 2221 | | |
2163 | 2222 | | |
2164 | 2223 | | |
| |||
2620 | 2679 | | |
2621 | 2680 | | |
2622 | 2681 | | |
2623 | | - | |
| 2682 | + | |
2624 | 2683 | | |
2625 | 2684 | | |
2626 | 2685 | | |
| |||
2669 | 2728 | | |
2670 | 2729 | | |
2671 | 2730 | | |
2672 | | - | |
| 2731 | + | |
2673 | 2732 | | |
2674 | 2733 | | |
2675 | 2734 | | |
| |||
2726 | 2785 | | |
2727 | 2786 | | |
2728 | 2787 | | |
2729 | | - | |
| 2788 | + | |
2730 | 2789 | | |
2731 | 2790 | | |
2732 | 2791 | | |
| |||
2751 | 2810 | | |
2752 | 2811 | | |
2753 | 2812 | | |
2754 | | - | |
| 2813 | + | |
2755 | 2814 | | |
2756 | 2815 | | |
2757 | 2816 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
251 | 255 | | |
252 | 256 | | |
253 | 257 | | |
| |||
0 commit comments