Commit ad494d7
authored
fix(oidc): trust Fastify proxy metadata (#1982)
## Summary
- trust local proxy metadata through Fastify while keeping the OIDC
authorize flow on one shared request-origin derivation path
- tighten the request-origin contract so downstream OIDC code always
receives a defined host and no longer re-derives origin data
- harden the new regression coverage by relaxing brittle async exception
assertions and making the authorize integration reply mock pass strict
type-checking
## Problem
A valid callback like
`https://nas.domain.com/graphql/api/auth/oidc/callback` could fail
behind the built-in proxy path even though it was allowed in Management
Access. The authorize flow had duplicated origin derivation, one layer
previously relied on raw forwarded headers, and the follow-up regression
coverage still had a few reviewable rough edges around proxy trust
clarity and test contracts.
## Fix
Use Fastify's explicit `loopback` trust proxy alias, centralize OIDC
request-origin extraction, and pass only normalized protocol/host
information through the authorize flow. The request-origin utilities now
guarantee a defined host, and the OIDC tests assert rejection behavior
and reply interactions without coupling to exception classes or unsafe
mock casts.
## Testing
- `pnpm --filter ./api type-check`
- `pnpm --filter ./api exec vitest run src/unraid-api/main.test.ts
src/unraid-api/graph/resolvers/sso/client/oidc-redirect-uri.service.test.ts
src/unraid-api/graph/resolvers/sso/utils/oidc-request-origin.util.test.ts
src/unraid-api/graph/resolvers/sso/utils/oidc-request-handler.util.spec.ts
src/unraid-api/rest/rest.controller.oidc.integration.test.ts`
- `pnpm --filter ./api exec vitest run src/unraid-api/main.test.ts
src/unraid-api/graph/resolvers/sso/utils/oidc-request-origin.util.test.ts
src/unraid-api/graph/resolvers/sso/client/oidc-redirect-uri.service.test.ts
src/unraid-api/graph/resolvers/sso/utils/oidc-request-handler.util.spec.ts
src/unraid-api/graph/resolvers/sso/core/oidc.service.test.ts
src/unraid-api/graph/resolvers/sso/core/oidc.service.integration.test.ts
src/unraid-api/rest/rest.controller.test.ts
src/unraid-api/rest/rest.controller.oidc.integration.test.ts`
## Deployment Note
- The built-in `webgui` mount proxies `/graphql` to the API over
`unix:/var/run/unraid-api.sock` and forwards `Host`, so these changes
should not disrupt existing users on the standard nginx/socket path.
- If a separate deployment relies on trusted `X-Forwarded-*` over a
non-loopback TCP proxy hop, `trustProxy` may need to be widened to that
explicit trusted network instead of loopback.
## Work Intent
- Reference: `[UNRD]` from the reported issue context
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features & Improvements**
* Centralized and improved derivation of request origin (protocol/host),
with better handling of proxied/forwarded values and trusted request
info.
* Fastify proxy trust tightened to loopback for more accurate
client/proxy behavior.
* **Tests**
* Added and updated unit/integration tests for OIDC/SSO flows:
redirect-URI validation, authorization URL building, request-origin
utilities, and proxied-request scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 160c5b1 commit ad494d7
14 files changed
Lines changed: 606 additions & 217 deletions
File tree
- api/src/unraid-api
- graph/resolvers/sso
- client
- core
- utils
- rest
Lines changed: 45 additions & 107 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| |||
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
16 | 14 | | |
17 | | - | |
| 15 | + | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
| |||
39 | 37 | | |
40 | 38 | | |
41 | 39 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 40 | + | |
49 | 41 | | |
50 | 42 | | |
51 | 43 | | |
52 | 44 | | |
53 | 45 | | |
54 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
55 | 50 | | |
56 | 51 | | |
57 | 52 | | |
| |||
63 | 58 | | |
64 | 59 | | |
65 | 60 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
| 61 | + | |
73 | 62 | | |
74 | 63 | | |
75 | 64 | | |
76 | 65 | | |
77 | 66 | | |
78 | | - | |
79 | | - | |
80 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
81 | 73 | | |
82 | 74 | | |
83 | | - | |
| 75 | + | |
84 | 76 | | |
85 | 77 | | |
86 | 78 | | |
87 | 79 | | |
88 | 80 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | 81 | | |
96 | 82 | | |
97 | 83 | | |
98 | 84 | | |
99 | 85 | | |
100 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
101 | 90 | | |
102 | 91 | | |
103 | 92 | | |
| |||
109 | 98 | | |
110 | 99 | | |
111 | 100 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 101 | + | |
119 | 102 | | |
120 | 103 | | |
121 | | - | |
| 104 | + | |
122 | 105 | | |
123 | 106 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
133 | 113 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | 114 | | |
147 | | - | |
148 | | - | |
149 | | - | |
| 115 | + | |
150 | 116 | | |
151 | | - | |
152 | | - | |
153 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
154 | 120 | | |
155 | 121 | | |
156 | 122 | | |
157 | 123 | | |
158 | 124 | | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
| 125 | + | |
166 | 126 | | |
167 | 127 | | |
168 | 128 | | |
169 | 129 | | |
170 | 130 | | |
171 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
172 | 135 | | |
173 | 136 | | |
174 | 137 | | |
175 | 138 | | |
176 | | - | |
177 | | - | |
| 139 | + | |
| 140 | + | |
178 | 141 | | |
179 | 142 | | |
180 | 143 | | |
181 | 144 | | |
182 | 145 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 146 | + | |
205 | 147 | | |
206 | 148 | | |
207 | | - | |
| 149 | + | |
208 | 150 | | |
209 | 151 | | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
220 | 158 | | |
221 | 159 | | |
222 | 160 | | |
Lines changed: 3 additions & 38 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 14 | + | |
17 | 15 | | |
18 | | - | |
| 16 | + | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
| |||
61 | 59 | | |
62 | 60 | | |
63 | 61 | | |
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 | 62 | | |
Lines changed: 7 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
248 | 248 | | |
249 | 249 | | |
250 | 250 | | |
251 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
| |||
278 | 281 | | |
279 | 282 | | |
280 | 283 | | |
281 | | - | |
282 | | - | |
283 | | - | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
284 | 287 | | |
285 | 288 | | |
286 | 289 | | |
| |||
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
134 | 134 | | |
135 | 135 | | |
136 | 136 | | |
137 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
138 | 141 | | |
139 | 142 | | |
140 | 143 | | |
141 | 144 | | |
142 | 145 | | |
| 146 | + | |
143 | 147 | | |
144 | 148 | | |
145 | 149 | | |
| |||
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
180 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
181 | 188 | | |
182 | 189 | | |
183 | 190 | | |
| |||
193 | 200 | | |
194 | 201 | | |
195 | 202 | | |
196 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
197 | 207 | | |
198 | 208 | | |
199 | 209 | | |
| |||
0 commit comments