Skip to content

Reject non-HTTP OAuth authorization URLs - #7423

Open
xianshujun wants to merge 2 commits into
stacklok:mainfrom
xianshujun:fix-7401-oauth-discovery-scheme
Open

xianshujun wants to merge 2 commits into
stacklok:mainfrom
xianshujun:fix-7401-oauth-discovery-scheme

Conversation

@xianshujun

Copy link
Copy Markdown
Contributor

What

ValidateEndpointURL only required HTTPS for non-localhost hosts, so a localhost URL with any scheme (javascript:, data:, file:, ...) passed validation and could reach browser.OpenURL in the OAuth flow.

  • Accept only https, or http for localhost, in validateEndpointURLWithSkip.
  • Re-check the scheme immediately before browser.OpenURL, even if the earlier endpoint validation was skipped.
  • Add tests for javascript/data/file URLs and non-HTTP schemes on localhost.

Testing

  • go test ./pkg/networking ./pkg/auth/oauth
  • go vet ./pkg/networking ./pkg/auth/oauth

Fixes #7401

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>
@xianshujun

Copy link
Copy Markdown
Contributor Author

I compared the base branch job with the PR job. The same four tests in pkg/script and pkg/vmcp/codemode failed on the base commit (5d6e66f) before the PR job started. Both jobs used the same Ubuntu runner image and Go version. Three failures had matching errors, and the fourth failed at the same assertion with a different sandbox error.

Could a maintainer rerun the failed Go test job when convenient? Thanks!

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

  1. https:///authorize passes both checks. url.Parse accepts it with an empty host, and both validateEndpointURLWithSkip and validateBrowserURL accept 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-empty u.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.

  2. The error text includes the whole authorization URL. By the time validateBrowserURL runs, 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 remote http:// URL, which is confusing. Something like "authorization URL must use https, or http on a loopback host" would be clearer.

  3. The new guard ignores the insecure opt-outs. ValidateEndpointURL and ValidateEndpointURLWithInsecure return early under INSECURE_DISABLE_URL_VALIDATION=true or insecureAllowHTTP, so discovery can still hand back a remote http:// authorization endpoint. Start now refuses it, and because the check runs before the skipBrowser branch, 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 in docs/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.

  4. Tests. TestValidateBrowserURL calls the helper directly, so deleting the call in Start, or moving it below the manual-login branch, leaves it green. A test through Flow.Start that uses a recording opener and checks that nothing is opened or printed, for both values of skipBrowser, 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 are javascript://localhost/%0aalert(1) and file://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>
@xianshujun xianshujun changed the title fix(oauth): reject non-HTTP authorization URLs Reject non-HTTP OAuth authorization URLs Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OAuth discovery: accept only http(s) endpoint URLs

2 participants