Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(gitlab): give an actionable message when the instance URL redirects (#68140)

Tom Owers0ef79da4d776
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py
index f166e582af62..cdf7d32a48e6 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/gitlab.py
@@ -215,7 +215,14 @@ def validate_credentials(
return False, str(e)
if response.is_redirect or response.is_permanent_redirect:
- return False, HOST_NOT_ALLOWED_ERROR
+ # A redirect on the API request usually means the instance URL doesn't point directly at
+ # GitLab (a project/web page, a login/SSO gateway, or a proxy). We can't follow it — the
+ # target could be an internal address (SSRF) — so guide the user to the right URL.
+ return False, (
+ "The GitLab instance URL returned an unexpected redirect. Enter just your instance URL "
+ "(for example https://gitlab.com or https://gitlab.example.com) with no project path, and make sure "
+ "it points directly at GitLab rather than a login, SSO, or proxy page."
+ )
if response.status_code == 200:
return True, None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py
index fb00cf81dc1f..1d7f74afe968 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gitlab/tests/test_gitlab.py
@@ -275,7 +275,7 @@ class TestValidateCredentials:
with self._patch_session(_response(status_code=302)) as patched:
valid, msg = validate_credentials("https://gitlab.com", "tok", "group/project")
assert valid is False
- assert msg == gitlab_module.HOST_NOT_ALLOWED_ERROR
+ assert "unexpected redirect" in (msg or "")
assert patched.return_value.get.call_args.kwargs["allow_redirects"] is False
def test_blocks_unsafe_host(self):