fix(workspace): honor explicit provider host when injecting git clone tokens - #4571
Merged
VascoSch92 merged 3 commits intoAug 22, 2026
Merged
Conversation
… tokens Self-hosted git instances (e.g. a company GitLab) never matched the hardcoded public SaaS host in _build_clone_url, so the auth token was silently dropped and the clone went out unauthenticated. Now, when the provider was explicitly configured (not auto-detected from the URL), the token is injected using the URL's own host instead of forcing a match against the canonical public domain. The auto-detected path keeps its exact-host check, so lookalike domains still never receive a token. Fixes OpenHands#4543
Collaborator
|
👋 This PR needs a couple of things fixed before OpenHands can review it:
Push an update once this is addressed and this check re-runs automatically. This is an automated check - no AI was used to generate this comment. |
Collaborator
|
🚦 CI is currently failing on this PR's latest commit. Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request This is an automated check - no AI was used to generate this comment. |
3 tasks
Rebuild the netloc instead of string-replacing it, so a self-hosted host keeps its case and port, a URL that already carries credentials is left alone, and a lookalike of the public host is refused even when the provider is explicit.
VascoSch92
enabled auto-merge (squash)
August 22, 2026 16:31
VascoSch92
approved these changes
Aug 22, 2026
VascoSch92
left a comment
Member
There was a problem hiding this comment.
LGTM!
thanks!
I just corrected a couple of nits.
This was referenced Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HUMAN:
Ran the workspace test suite locally (61 tests, incl. the new self-hosted GitLab cases) plus ruff, pyright, and pre-commit before pushing.
AGENT:
Why
_build_clone_urlonly injects the auth token into a full clone URL when the URL's host matches the provider's hardcoded public SaaS domain (gitlab.com,github.com,bitbucket.org). A self-hosted instance (e.g.https://gitlab.mycompany.com/owner/repo) never matches, so the token is silently dropped and the clone goes out unauthenticated and fails.That exact-host check exists intentionally, to stop an auto-detected provider from leaking a token into a lookalike host (
github.com.evil.com). The fix distinguishes the two cases instead of removing the check:RepoSource.providerset by the caller): the pairing ofurl+providerwas authored directly by the caller, not derived from an untrusted URL, so the token is now injected using the URL's own host._clone_single_repopassesexplicit_provider=repo.provider is not Nonethrough to_build_clone_urlto make this distinction.Summary
providerfield) now get the token injected using the URL's actual host, instead of requiring an exact match against the canonical public SaaS domain.Issue Number
Fixes #4543
How to Test
uv run pytest tests/workspace/test_cloud_workspace_repos.py -q— 61 passed, including:test_build_clone_url_self_hosted_gitlab_with_explicit_provider— token injected for self-hosted GitLab with explicit providertest_build_clone_url_self_hosted_host_without_explicit_provider— no token when provider isn't explicittest_build_clone_url_lookalike_host_not_injected— regression: lookalike host never gets a tokentest_clone_self_hosted_gitlab_with_token— end-to-endclone_repos()call asserting the authenticated URL passed togit cloneAlso ran
uv run ruff check/ruff format --checkon the changed files, and the repo's pre-commit hooks (ruff, pyright, import-dependency rules, tool registration) — all clean.Type
Notes
None.