Commit 2c65f87
committed
CS-11264 follow-up: validate via registry, no per-row cold-mount
Routing every permission row through `reconciler.lookupOrMount` made
`_realm-auth` correct for the user's own non-pinned realms but
introduced a cold-mount-storm hazard: `fetchUserPermissions` is
called with `onlyOwnRealms: false`, so the result includes every
`'*'`-readable realm in addition to the user's owned/writable
realms. The host login flow and `boxel realm list` both hit
`/_realm-auth` and expect a JWT for every accessible realm; on a
fresh process that's an unbounded series of sequential
`realm.start()` calls against the entire public-readable set.
A JWT does not actually require a mounted realm. The token encodes
the URL, the user's permissions, the session room, and the realm
server URL; the realm itself is only used when the holder later
hits a per-realm endpoint, and `findOrMountRealm` /
`reconciler.lookupOrMount` handle the on-demand mount there.
Switch the handler to:
- Validate each accessible URL against `reconciler.knownByUrl` (the
in-memory mirror of `realm_registry`), with a single batched
probe against `realm_registry` for URLs not yet reflected in
this process. Mirrors `multiRealmAuthorization` (CS-11238).
- Resolve the session room once per request (it is keyed by
matrixUserId in the DB, not by realm). For the create branch,
use the realm-server's matrix client to call `createDM`,
matching how `_server-session` creates session rooms — the
caller has already exchanged an OpenID token via
`_server-session` to get the JWT they're presenting here, so
the server client is already logged in.
- Issue the JWT for every URL that resolved against the registry,
with no mount. Mount stays deferred to the next per-realm
request.
Strengthen the regression test: `testingOnlyEvictRealmFromRealmsList`
now also removes the realm from `reconciler.mounted`, so the test
proves the handler issues a JWT for a realm absent from both
`realms[]` and `mounted` (i.e. would have needed a cold mount
under the previous follow-up's behavior). Adds preconditions and
a post-call assertion that `reconciler.mounted` is still empty
for the URL — the handler did NOT cold-mount.1 parent 6b84929 commit 2c65f87
3 files changed
Lines changed: 133 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
8 | 13 | | |
9 | 14 | | |
10 | 15 | | |
| |||
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
| 22 | + | |
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
| |||
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| 46 | + | |
40 | 47 | | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
46 | 99 | | |
47 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
48 | 103 | | |
49 | 104 | | |
50 | | - | |
51 | 105 | | |
52 | | - | |
53 | 106 | | |
54 | 107 | | |
55 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
56 | 115 | | |
57 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
58 | 121 | | |
59 | 122 | | |
60 | 123 | | |
61 | 124 | | |
62 | 125 | | |
63 | | - | |
| 126 | + | |
64 | 127 | | |
65 | | - | |
66 | 128 | | |
67 | 129 | | |
68 | 130 | | |
| |||
79 | 141 | | |
80 | 142 | | |
81 | 143 | | |
82 | | - | |
83 | 144 | | |
84 | 145 | | |
85 | | - | |
86 | 146 | | |
87 | 147 | | |
88 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
540 | 547 | | |
541 | 548 | | |
542 | 549 | | |
543 | 550 | | |
544 | 551 | | |
545 | 552 | | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
552 | 562 | | |
553 | 563 | | |
554 | 564 | | |
555 | 565 | | |
556 | 566 | | |
| 567 | + | |
557 | 568 | | |
558 | 569 | | |
559 | 570 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
108 | 114 | | |
109 | 115 | | |
110 | 116 | | |
| |||
114 | 120 | | |
115 | 121 | | |
116 | 122 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
121 | 128 | | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
122 | 143 | | |
123 | 144 | | |
124 | 145 | | |
| |||
136 | 157 | | |
137 | 158 | | |
138 | 159 | | |
139 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
140 | 165 | | |
141 | 166 | | |
142 | 167 | | |
| |||
0 commit comments