Commit d319d8b
committed
fix(auth): stop reading an unreachable Keycloak as "no registered redirect URIs"
The redirect_uri check is fail-closed on an empty allowlist, and the cache handed
it an empty allowlist for two very different reasons: Keycloak said the client has
no URIs, or Keycloak could not be asked at all. fetchClientConfig caught every
error and returned `{ redirectUris: [] }`, so an admin-API failure came back out
of /auth/authorize as
400 redirect_uri does not match a registered redirect URI for this client
blaming the app's configuration for an outage on ours. Both call sites already
had the right branch for this — authorize and the callback handler answer a
THROWN lookup with `Unable to validate redirect_uri` and an error-level log — but
the cache swallowed the throw, so neither branch could ever fire. This is the
same shape as the WAF incident recorded in keycloak-stack.ts.
Worse, the empty result was cached for the full 5-minute TTL, so a single hiccup
rejected every launch for five minutes.
The lookup now reports found / absent / unavailable. Only found and absent are
cached, absent on a short 30s TTL because absence usually means "not created
yet" (the compliance workflow deletes and recreates its client mid-run).
getRegisteredRedirectUris throws on unavailable; getSmartClientConfig stays
lenient because token-time enrichment only reads patientFacing and must not fail
a token issue over an unreachable admin API.
Also drops a duplicated KcAdminClient construction in favour of the existing
getAdminClient factory, which exists precisely to be a test seam, and moves the
cache behind createClientConfigCache so the new test drives it by injection —
a sibling test mock.modules this whole module, and bun's module mocks are
process-global.
Backend 1389 pass / 31 pre-existing fail (same 31 without this diff), typecheck,
lint.1 parent 21052c9 commit d319d8b
3 files changed
Lines changed: 215 additions & 51 deletions
File tree
- .github/workflows
- backend
- src/lib
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
1 | 4 | | |
2 | 5 | | |
3 | 6 | | |
| |||
473 | 476 | | |
474 | 477 | | |
475 | 478 | | |
476 | | - | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
477 | 482 | | |
478 | 483 | | |
479 | 484 | | |
480 | 485 | | |
481 | 486 | | |
| 487 | + | |
482 | 488 | | |
483 | 489 | | |
484 | 490 | | |
| 491 | + | |
485 | 492 | | |
486 | 493 | | |
487 | 494 | | |
488 | 495 | | |
489 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
490 | 503 | | |
491 | 504 | | |
492 | 505 | | |
| |||
1371 | 1384 | | |
1372 | 1385 | | |
1373 | 1386 | | |
1374 | | - | |
| 1387 | + | |
1375 | 1388 | | |
1376 | | - | |
| 1389 | + | |
1377 | 1390 | | |
1378 | | - | |
1379 | | - | |
| 1391 | + | |
| 1392 | + | |
1380 | 1393 | | |
1381 | 1394 | | |
1382 | 1395 | | |
| |||
1422 | 1435 | | |
1423 | 1436 | | |
1424 | 1437 | | |
| 1438 | + | |
1425 | 1439 | | |
1426 | 1440 | | |
1427 | 1441 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | | - | |
| 15 | + | |
17 | 16 | | |
18 | 17 | | |
19 | 18 | | |
| |||
36 | 35 | | |
37 | 36 | | |
38 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
39 | 54 | | |
40 | 55 | | |
41 | 56 | | |
42 | 57 | | |
43 | 58 | | |
44 | 59 | | |
| 60 | + | |
| 61 | + | |
45 | 62 | | |
46 | | - | |
| 63 | + | |
47 | 64 | | |
48 | 65 | | |
49 | | - | |
50 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
51 | 71 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 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 | + | |
| 99 | + | |
55 | 100 | | |
56 | | - | |
57 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
58 | 112 | | |
59 | 113 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
64 | 133 | | |
65 | 134 | | |
66 | 135 | | |
| |||
81 | 150 | | |
82 | 151 | | |
83 | 152 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
87 | 162 | | |
88 | 163 | | |
89 | 164 | | |
90 | 165 | | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 166 | + | |
97 | 167 | | |
98 | 168 | | |
99 | 169 | | |
100 | 170 | | |
101 | 171 | | |
102 | 172 | | |
103 | | - | |
| 173 | + | |
104 | 174 | | |
105 | 175 | | |
106 | 176 | | |
107 | 177 | | |
108 | 178 | | |
109 | 179 | | |
110 | | - | |
| 180 | + | |
111 | 181 | | |
112 | 182 | | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 183 | + | |
118 | 184 | | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
128 | 189 | | |
129 | 190 | | |
130 | 191 | | |
131 | | - | |
| 192 | + | |
| 193 | + | |
132 | 194 | | |
133 | 195 | | |
134 | 196 | | |
| |||
139 | 201 | | |
140 | 202 | | |
141 | 203 | | |
142 | | - | |
| 204 | + | |
143 | 205 | | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
149 | 209 | | |
150 | 210 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 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 | + | |
0 commit comments