Skip to content

Conversation

@bogdanm-s25
Copy link

Description

The language server is using the wrong API endpoint for code analysis. It defaults to api.snyk.io but attempts to use api.eu.snyk.io for code, causing authentication errors.
For production debugging purpose on the EU server, when custom endpoint is specified, it triggers error:
Instance specified in callback ([api.snyk.io](http://api.snyk.io/)) does not match pre-configured value ([api.eu.snyk.io](http://api.eu.snyk.io/))
Based on ticket https://snyksec.atlassian.net/browse/IDE-1488 and Slack thread https://snyk.slack.com/archives/C073S2B45J6/p1760079795011899?thread_ts=1760016536.850679&cid=C073S2B45J6

Changes

Added an extra check to see if custom API URL is a subdomain of the default API URL.
In this case, default URL will be returned and not the regional one.

Checklist

  • Tests added and all succeed
  • Regenerated mocks, etc. (make generate)
  • Linted (make lint-fix)
  • README.md updated, if user-facing
  • License file updated, if new 3rd-party dependency is introduced

@CLAassistant
Copy link

CLAassistant commented Nov 5, 2025

CLA assistant check
All committers have signed the CLA.

@snyk-io
Copy link

snyk-io bot commented Nov 5, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @bogdanm-s25, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical authentication problem in the language server where regional API endpoints were being incorrectly selected over the primary default API endpoint, specifically impacting EU production debugging. The change introduces a robust mechanism to detect and correctly prioritize the default API URL when a custom endpoint is a subdomain, thereby resolving the authentication failures and ensuring consistent API access.

Highlights

  • API Endpoint Resolution Fix: Resolved an issue where the language server was incorrectly using regional API endpoints (e.g., api.eu.snyk.io) for code analysis when the default API endpoint (api.snyk.io) should have been prioritized, leading to authentication errors.
  • Subdomain Check Implementation: Introduced a new helper function, isApiSubdomain, to accurately determine if a custom API URL is a subdomain of the default API URL. This function handles https:// and api. prefixes, and performs case-insensitive comparison of domain parts.
  • Prioritized API URL Logic Update: Modified the getPrioritizedApiUrl function to include a check using isApiSubdomain. If the custom URL is identified as a subdomain of the default URL, the default URL is now returned, preventing the authentication conflict.
  • New Test Case: Added a new test case to auth_service_impl_test.go to validate the correct behavior of getPrioritizedApiUrl when a custom URL is a subdomain of the default URL, ensuring the fix works as expected.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue with regional API endpoints by ensuring that when a custom URL is a subdomain of the default API URL (e.g., a regional endpoint), the default URL is used instead. This is achieved by introducing a new helper function, isApiSubdomain, and adding a corresponding check in getPrioritizedApiUrl. The change is accompanied by a new test case that validates this specific scenario. My review includes a suggestion to simplify the implementation of the new isApiSubdomain function for improved readability and maintainability.

return engineUrl
}

// #IDE-1488 Fix for production debugging issue on the EU server.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this comment needed?

Copy link
Author

Choose a reason for hiding this comment

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

Scope of the comment is to link the bug fix to a ticket.
Sometimes when fixing a bug, the change does not make sense after some time and this would help avoid removing or refactoring it.
If this does not fit team's conventions, I will remove it.

return customUrl
}

func isApiSubdomain(domain, subdomain string) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I read the code correctly, this method returns, whether the given domain starts with api. I do not understand what we want to achieve with the code from L178ff.

Copy link
Author

Choose a reason for hiding this comment

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

The method tests if a given subdomain URL is a region subdomain of the parent domain, but only do it if both URLs start with api. to avoid altering existing behaviour for other types of URLs.

}

// #IDE-1488 Fix for production debugging issue on the EU server.
if isApiSubdomain(defaultUrl, customUrl) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the logical reasoning for this?

Copy link
Author

Choose a reason for hiding this comment

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

The idea is to only apply the switch between URLs for those particular cases.

expectedResult: customUrl,
},
{
name: "Default URL when custom URL is subdomain",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? This does not seem right.

Copy link
Author

Choose a reason for hiding this comment

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

This will only apply the switch in the case when both URLs start with api and the custom one is actually a region of default one.
All the existing tests are still passing, no change in existing behavior and I added an extra test for this exact situation.

@bastiandoetsch
Copy link
Collaborator

I do not think that the solution is valid. A custom URL should overwrite the default URL returned. I'm not sure if we can fix it on our side, apart from showing a warning that a different endpoint URL is configured for the user and the given endpoint address is wrong. Most likely we need to display an error about the endpoint configuration in this scenario. For the example, we should check with our authentication team (access), if the returned URL is correct or not.

@bogdanm-s25
Copy link
Author

I do not think that the solution is valid. A custom URL should overwrite the default URL returned. I'm not sure if we can fix it on our side, apart from showing a warning that a different endpoint URL is configured for the user and the given endpoint address is wrong. Most likely we need to display an error about the endpoint configuration in this scenario. For the example, we should check with our authentication team (access), if the returned URL is correct or not.

From my understanding, we needed to use the parent domain when performing authentication and I tried to capture this in the PR description.
The custom URL used for debugging contains eu and this does not fit the URL expected by the auth process.

What exact team should I check this with? The initial thread mentiones a bug on our side: https://snyk.slack.com/archives/C073S2B45J6/p1760079795011899?thread_ts=1760016536.850679&cid=C073S2B45J6

As suggested in Standup, I have asked about it on #ask-foundation but I got send back to IDE team https://snyk.slack.com/archives/C040Q5G1Q3G/p1762788585169979

@bastiandoetsch
Copy link
Collaborator

I do not think that the solution is valid. A custom URL should overwrite the default URL returned. I'm not sure if we can fix it on our side, apart from showing a warning that a different endpoint URL is configured for the user and the given endpoint address is wrong. Most likely we need to display an error about the endpoint configuration in this scenario. For the example, we should check with our authentication team (access), if the returned URL is correct or not.

From my understanding, we needed to use the parent domain when performing authentication and I tried to capture this in the PR description. The custom URL used for debugging contains eu and this does not fit the URL expected by the auth process.

What exact team should I check this with? The initial thread mentiones a bug on our side: https://snyk.slack.com/archives/C073S2B45J6/p1760079795011899?thread_ts=1760016536.850679&cid=C073S2B45J6

As suggested in Standup, I have asked about it on #ask-foundation but I got send back to IDE team https://snyk.slack.com/archives/C040Q5G1Q3G/p1762788585169979

let's move the discussion to slack.

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.

4 participants