Repository navigation
Commit 599a2ee
authored
fix(oauth): parse resource_metadata per RFC 7235 auth-param rules (#1771)
## Bug
`ExtractResourceMetadataURL` (`internal/oauth/discovery.go`) finds the
PRM URL by splitting the header on the literal `resource_metadata="`.
RFC 7235 section 2.1 allows a case-insensitive parameter name and
whitespace around `=`, so a valid challenge can be missed and discovery
falls back to a constructed URL. A plain substring split also misreads
other parameters:
- `x_resource_metadata="…"` is taken as `resource_metadata`.
- An escaped mention inside another parameter's quoted value, such as
`error_description`, is taken as the real one.
## Trigger
All of these headers return `""` or the wrong URL today:
- `Bearer Resource_Metadata="https://…/oauth-protected-resource"`
- `Bearer error="invalid_token", resource_metadata = "https://…"`
- `Bearer x_resource_metadata="https://wrong",
resource_metadata="https://…"`
## Fix
The function now runs a small auth-param scanner:
- parameter names are case-insensitive tokens;
- whitespace is allowed around `=`;
- quoted strings are unescaped;
- other parameters' quoted values are skipped, not searched.
Token-form (unquoted) values are still rejected, matching the existing
"missing opening quote" case.
## Verification
- `go test -count=1 -run TestExtractResourceMetadataURL
./internal/oauth/` passes. That covers the new cases and the existing
`TestExtractResourceMetadataURL` table.
- With `discovery.go` reverted (`git stash push
internal/oauth/discovery.go`), the new test fails on 4 of its 5
subtests: case-insensitive name, whitespace around `=`, similar-suffix
parameter, and lookalike-only.
- `gofmt -l` is clean on both files.
- I haven't run the full `go test -count=1 ./internal/oauth/` locally.
Work stopped because free disk fell below 1 GB.1 parent 4c7d2b2 commit 599a2ee
2 files changed
Lines changed: 86 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
281 | 286 | | |
282 | | - | |
283 | | - | |
284 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
285 | 294 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
291 | 336 | | |
| 337 | + | |
| 338 | + | |
292 | 339 | | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
297 | 345 | | |
298 | | - | |
299 | | - | |
| 346 | + | |
300 | 347 | | |
301 | 348 | | |
302 | 349 | | |
| |||
| 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 | + | |
0 commit comments