diff --git a/infrastructure/authentication/auth_service_impl.go b/infrastructure/authentication/auth_service_impl.go index 69bbe6096..53fe0f025 100644 --- a/infrastructure/authentication/auth_service_impl.go +++ b/infrastructure/authentication/auth_service_impl.go @@ -157,11 +157,33 @@ func getPrioritizedApiUrl(customUrl string, engineUrl string) string { return engineUrl } + // #IDE-1488 Fix for production debugging issue on the EU server. + if isApiSubdomain(defaultUrl, customUrl) { + return defaultUrl + } + // Otherwise, return the custom URL set by the user. // FedRAMP and single tenant environments. return customUrl } +func isApiSubdomain(domain, subdomain string) bool { + domain = strings.TrimPrefix(domain, "https://") + subdomain = strings.TrimPrefix(subdomain, "https://") + + if !strings.HasPrefix(domain, "api.") || !strings.HasPrefix(subdomain, "api.") { + return false + } + + domain = strings.TrimPrefix(domain, "api.") + subdomain = strings.TrimPrefix(subdomain, "api.") + + domain = strings.ToLower(strings.TrimSpace(domain)) + subdomain = strings.ToLower(strings.TrimSpace(subdomain)) + + return strings.HasSuffix(subdomain, "."+domain) +} + func (a *AuthenticationServiceImpl) UpdateCredentials(newToken string, sendNotification bool, updateApiUrl bool) { a.m.Lock() defer a.m.Unlock() diff --git a/infrastructure/authentication/auth_service_impl_test.go b/infrastructure/authentication/auth_service_impl_test.go index 6d0b19c65..7ed7ba9f2 100644 --- a/infrastructure/authentication/auth_service_impl_test.go +++ b/infrastructure/authentication/auth_service_impl_test.go @@ -341,6 +341,12 @@ func TestGetApiUrl(t *testing.T) { engineUrl: "", expectedResult: customUrl, }, + { + name: "Default URL when custom URL is subdomain", + customUrl: "https://api.eu.snyk.io", + engineUrl: "", + expectedResult: defaultUrl, // equals to "https://api.snyk.io" + }, } for _, tt := range tests {