Repository navigation
Commit fdeda44
Sami
Authorize join alerts from the snapshot, and bound their cost
Three defects, all at inputs nobody had fed this code.
Stale role authorization (found by Wren, reproduced live by Max against
a real relay; a ship blocker). The effect gated on
`useMyRelayMembershipLookupQuery`, which is invalidated only by this
client's own membership mutations. `staleTime` marks data stale without
scheduling a refetch, and the global QueryClient disables focus refetch,
so a viewer demoted by ANOTHER admin kept a cached owner/admin role for
as long as the app stayed open — and kept learning every later joiner's
identity through OS notifications from a role they no longer held.
Authorization now comes from the snapshot in hand. The relay stamps
every row as `["member", pubkey, role]` in
`publish_nip43_membership_locked`, so the viewer's own role always rides
in the event, and the snapshot that revokes authorization is the same
one that would disclose the join. Checking it there closes the race in
one read; an async invalidation cannot beat the handler it races. Fails
closed when the viewer is absent from the roster entirely.
Unbounded notification fan-out. A snapshot is a whole roster, not an
event per join, so a bulk add alerted once per key: measured at 248 OS
notifications from a single 250-key snapshot, delivered through a serial
await loop. Above three joins the batch collapses to one summary, and
the profile fetch is skipped since its result would be unused.
kind:8000 REQ amplification. The accelerator refetched 1:1 per delta —
250 deltas cost 250 REQ frames. REQ is billed against the same
per-principal `WsEvents` budget as the user's own sends (default 10/s
over a 5s window, `admission.rs` + `connection.rs`), so a bulk add could
rate-limit an owner out of their own app: the damage lands on their
message sends and channel opens, not on this feature. Refetches now
coalesce on a 500ms trailing window; one snapshot is authoritative for
the whole burst, so the trailing edge loses nothing.
The `snapshot()` test helper stamped every member `"member"`, including
the viewer — a fixture that could not express the demotion this gate
turns on. It now carries the viewer's role, defaulting to owner. That
fixture gap is why the existing suite went red on the first version of
this fix: the tests were right and the fixture was unrealistic.
Three mutants killed, control green before and after each: role gate
removed (restores Wren's blocker, 2 arms fail), cap removed (restores
the 248-banner fan-out), debounce removed (restores 1:1 REQ). Five new
arms, including a positive control proving an authorized admin still
alerts — a gate that refused everything would otherwise pass every
negative assertion.
Gates after merging main: pnpm typecheck rc=0, pnpm check rc=0 (same
pre-existing 1 warning/2 infos), pnpm test 4321/4321.
Co-authored-by: Sami <f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68@buzz.block.builderlab.xyz>
Signed-off-by: Sami <f4a42a97e594b77bdbd8ee35191c8b28a94a4cb871d96f32921558275421fb68@buzz.block.builderlab.xyz>1 parent 3b63c1a commit fdeda44
3 files changed
Lines changed: 334 additions & 12 deletions
File tree
- desktop/src/features/community-members
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
| 257 | + | |
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
263 | | - | |
264 | | - | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
265 | 277 | | |
266 | 278 | | |
267 | 279 | | |
268 | 280 | | |
269 | 281 | | |
270 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
271 | 287 | | |
272 | 288 | | |
273 | 289 | | |
| |||
441 | 457 | | |
442 | 458 | | |
443 | 459 | | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
444 | 474 | | |
445 | 475 | | |
446 | 476 | | |
| |||
585 | 615 | | |
586 | 616 | | |
587 | 617 | | |
588 | | - | |
| 618 | + | |
589 | 619 | | |
590 | 620 | | |
591 | 621 | | |
| |||
605 | 635 | | |
606 | 636 | | |
607 | 637 | | |
608 | | - | |
| 638 | + | |
609 | 639 | | |
610 | 640 | | |
611 | 641 | | |
| |||
651 | 681 | | |
652 | 682 | | |
653 | 683 | | |
654 | | - | |
| 684 | + | |
655 | 685 | | |
656 | 686 | | |
657 | 687 | | |
| |||
676 | 706 | | |
677 | 707 | | |
678 | 708 | | |
679 | | - | |
| 709 | + | |
680 | 710 | | |
681 | 711 | | |
682 | 712 | | |
| |||
877 | 907 | | |
878 | 908 | | |
879 | 909 | | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
880 | 1110 | | |
881 | 1111 | | |
882 | 1112 | | |
0 commit comments