security: harden OAuth discovery and token endpoints
Merged
JE
4mo ago+2721+2721+0123456789012345678901234567890123456789-132-132-012345678901234567890123456789
Harden OAuth discovery and token endpoints
(Threat: T1 malicious/compromised OAuth/discovery server.)
authorization_endpointscheme validation (auth.gobuildAuthURL): the endpoint comes from the server-controlled discovery doc and is later handed toOpenBrowserāxdg-open/open. Now required to behttps(orhttpon loopback); afile:///--leading value is rejected before dispatch.registration_endpointscheme validation (registerBC3Client): the DCR path now validates the endpoint against the stricterisSecureEndpointURLwhitelist (absolute URL with a non-empty host;https, orhttpon loopback), and re-validates every redirect hop with the same rule.- No-redirect OAuth client (
appctx/context.go):CheckRedirect: ErrUseLastResponse. The exchange/refresh requests setGetBody, so Go would replayrefresh_token/auth code to a redirect target; RFC 6749 token endpoints don't legitimately 3xx-redirect POSTs. Mirrors the SDK API client's redirect guard.
Tests
TestBuildAuthURL_RejectsUnsafeScheme (accepts https / http-loopback, rejects file://, foreign http://, javascript:, -flag).
Part 3/6 of the stacked security series. Base: security/02-output-ansi-sanitize.
š Stack (merge bottom-up)
- #478 ā reject foreign-host URLs in
api(basemain) - #479 ā strip ANSI/OSC escapes from output
- #480 ā harden OAuth discovery / token endpoints
- #481 ā close config trust-boundary gaps + completion gate
- #482 ā tighten config-dir perms + plugin scope argv
- #483 ā bump toolchain/x-net + CI gates
Each is independent except #482 depends on #481 (shared root.go). #478 can land first/alone.