Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: custom endpoint validation [IDE-126] #454

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Snyk Security Changelog
## [2.6.1]
- Improve the validation of the custom endpoint and change the default to https://api.snyk.io.

## [2.6.0]
- Improve UX of AI fixes by adding previews and options

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@
},
"snyk.advanced.customEndpoint": {
"type": "string",
"markdownDescription": "Sets API endpoint to use for Snyk requests. Useful for custom Snyk setups. E.g. `https://app.eu.snyk.io/api`.",
"scope": "window"
"markdownDescription": "Sets API endpoint to use for Snyk requests. Useful for custom Snyk setups. E.g. `https://api.eu.snyk.io`.",
"scope": "window",
"format": "uri",
"pattern": "^(https?://)api.?[a-zA-Z0-9]{0,19}.(snyk|snykgov).io$"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only thing to call out here is that I noticed in IntelliJ the custom endpoint supports http(s)://snyk.io/... endpoints. VSCode never did though and I'm not sure why

},
"snyk.advanced.organization": {
"type": "string",
Expand Down
16 changes: 0 additions & 16 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export interface IConfiguration {
source: string;

authHost: string;
baseApiUrl: string;

getToken(): Promise<string | undefined>;

Expand Down Expand Up @@ -97,8 +96,6 @@ export interface IConfiguration {

isFedramp: boolean;

analyticsPermitted: boolean;

severityFilter: SeverityFilter;

scanningMode: string | undefined;
Expand All @@ -117,8 +114,6 @@ export class Configuration implements IConfiguration {
private readonly defaultSnykCodeBaseURL = 'https://deeproxy.snyk.io';
private readonly defaultAuthHost = 'https://snyk.io';
private readonly defaultOssApiEndpoint = `${this.defaultAuthHost}/api/v1`;
private readonly defaultBaseApiHost = 'https://api.snyk.io';
private readonly analyticsPermittedEnvironments = { 'app.snyk.io': true, 'app.us.snyk.io': true };

constructor(private processEnv: NodeJS.ProcessEnv = process.env, private workspace: IVSCodeWorkspace) {}

Expand Down Expand Up @@ -204,13 +199,6 @@ export class Configuration implements IConfiguration {
return `${hostnameParts[2]}.${hostnameParts[3]}`.includes('snykgov.io');
}

get analyticsPermitted(): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code deleted in this file doesn't seem to be used anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added in 8c2811b but the itly analytics have been removed since

if (!this.customEndpoint) return true;

const hostname = new URL(this.customEndpoint).hostname;
return hostname in this.analyticsPermittedEnvironments;
}

get snykOssApiEndpoint(): string {
if (this.customEndpoint) {
return this.customEndpoint; // E.g. https://app.eu.snyk.io/api
Expand Down Expand Up @@ -292,10 +280,6 @@ export class Configuration implements IConfiguration {
return Configuration.source;
}

get baseApiUrl(): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was added in 213c781 but it seems the usage has since been removed

return this.defaultBaseApiHost;
}

getFeaturesConfiguration(): FeaturesConfiguration {
const ossEnabled = this.workspace.getConfiguration<boolean>(
CONFIGURATION_IDENTIFIER,
Expand Down
41 changes: 0 additions & 41 deletions src/test/unit/common/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,45 +229,4 @@ suite('Configuration', () => {
strictEqual(configuration.isFedramp, false);
});
});

suite('.analyticsPermitted()', () => {
test('returns true when no custom endpoint configured', () => {
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, undefined);

const configuration = new Configuration({}, workspace);
strictEqual(configuration.analyticsPermitted, true);
});

test('returns true for app.snyk.io', () => {
const customEndpoint = 'https://app.snyk.io';
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, customEndpoint);

const configuration = new Configuration({}, workspace);
strictEqual(configuration.analyticsPermitted, true);
});

test('returns true for app.us.snyk.io', () => {
const customEndpoint = 'https://app.us.snyk.io';
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, customEndpoint);

const configuration = new Configuration({}, workspace);
strictEqual(configuration.analyticsPermitted, true);
});

test('returns false for app.snykgov.io', () => {
const customEndpoint = 'https://app.snykgov.io';
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, customEndpoint);

const configuration = new Configuration({}, workspace);
strictEqual(configuration.analyticsPermitted, false);
});

test('returns false for app.eu.snyk.io', () => {
const customEndpoint = 'https://app.eu.snyk.io';
const workspace = stubWorkspaceConfiguration(ADVANCED_CUSTOM_ENDPOINT, customEndpoint);

const configuration = new Configuration({}, workspace);
strictEqual(configuration.analyticsPermitted, false);
});
});
});
Loading