Repository navigation
Reject non-HTTP OAuth authorization URLs - #7423
xianshujun wants to merge 2 commits into
Conversation
ValidateEndpointURL accepted any scheme for localhost, so a javascript or data authorization URL could reach the OS browser. Accept only https, or http for localhost, and re-check the scheme immediately before browser.OpenURL. Signed-off-by: xianshujun <xianshupang@gmail.com>
|
I compared the base branch job with the PR job. The same four tests in Could a maintainer rerun the failed Go test job when convenient? Thanks! |
jhrozek
left a comment
There was a problem hiding this comment.
Thanks for this. Limiting the scheme to https, or http on loopback, is the right fix. Before javascript://localhost/... or ftp://localhost would have passed the old localhost exemption, and now they don't. A few things I'd like to see before merging.
-
https:///authorizepasses both checks.url.Parseaccepts it with an empty host, and bothvalidateEndpointURLWithSkipandvalidateBrowserURLaccept it on scheme alone. Login would then print or open a link with no authorization server and wait for a callback. Please require a non-emptyu.Hostname()in both, ideally through one shared helper so the two checks can't drift, and add a hostless https case to both test tables. -
The error text includes the whole authorization URL. By the time
validateBrowserURLruns, the URL carries state, the resource indicator and any caller-supplied params, and the wrapped parse error can echo it too. Those end up in bug reports and logs. I'd return just the reason, with no URL. The message also says "non-HTTP" for a remotehttp://URL, which is confusing. Something like "authorization URL must use https, or http on a loopback host" would be clearer. -
The new guard ignores the insecure opt-outs.
ValidateEndpointURLandValidateEndpointURLWithInsecurereturn early underINSECURE_DISABLE_URL_VALIDATION=trueorinsecureAllowHTTP, so discovery can still hand back a remotehttp://authorization endpoint.Startnow refuses it, and because the check runs before theskipBrowserbranch, the headless manual-login link is refused too. That is a behaviour change for people who rely on those dev settings. If it's deliberate, please say so in the PR body (before and after) and update the HTTPS enforcement and headless sections indocs/remote-mcp-authentication.md. If it isn't, I'd make the browser guard reject only non-http(s) schemes, since that is the actual javascript/data/file problem, and leave the HTTPS requirement to the existing opt-out-aware validation. -
Tests.
TestValidateBrowserURLcalls the helper directly, so deleting the call inStart, or moving it below the manual-login branch, leaves it green. A test throughFlow.Startthat uses a recording opener and checks that nothing is opened or printed, for both values ofskipBrowser, would pin that down. Also,javascript:alert(1)was already rejected before this change because its host is empty. The cases that exercise the regression arejavascript://localhost/%0aalert(1)andfile://localhost/etc/passwd, so please add those to both tables.
Smaller one: our contributing guidelines don't use conventional-commit prefixes, so the commit subject and PR title should drop fix(oauth):, e.g. "Reject non-HTTP OAuth authorization URLs".
Not for this PR, but worth knowing: the auth-server redirect path doesn't go through Flow.Start, so this guard doesn't cover it.
Signed-off-by: xianshujun <xianshupang@gmail.com>
What
ValidateEndpointURLonly required HTTPS for non-localhost hosts, so a localhost URL with any scheme (javascript:,data:,file:, ...) passed validation and could reachbrowser.OpenURLin the OAuth flow.https, orhttpfor localhost, invalidateEndpointURLWithSkip.browser.OpenURL, even if the earlier endpoint validation was skipped.Testing
go test ./pkg/networking ./pkg/auth/oauthgo vet ./pkg/networking ./pkg/auth/oauthFixes #7401