Skip to content

Commit

Permalink
fix: fedramp URL check
Browse files Browse the repository at this point in the history
  • Loading branch information
j-luong committed Aug 31, 2023
1 parent 52b900c commit b47d7a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/snyk/common/analytics/itly.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import SegmentPlugin from '@itly/plugin-segment-node';
import itly, {
AnalysisIsReadyProperties,
AnalysisIsTriggeredProperties as _AnalysisIsTriggeredProperties,
FalsePositiveIsSubmittedProperties,
IssueHoverIsDisplayedProperties,
IssueInTreeIsClickedProperties,
QuickFixIsDisplayedProperties as _QuickFixIsDisplayedProperties,
ScanModeIsSelectedProperties,
TrackOptions,
AnalysisIsTriggeredProperties as _AnalysisIsTriggeredProperties,
QuickFixIsDisplayedProperties as _QuickFixIsDisplayedProperties,
} from '../../../ampli';
import { Configuration } from '../configuration/configuration';
import { SnykConfiguration } from '../configuration/snykConfiguration';
Expand Down Expand Up @@ -82,6 +82,7 @@ export class Iteratively implements IAnalytics {
this.logger.debug(`Analytics are disabled. No analytics will be collected.`);
return null;
}
this.logger.debug(`Analytics are enabled. Analytics will be collected.`);

const segmentWriteKey = this.snykConfiguration?.segmentWriteKey;
if (!segmentWriteKey) {
Expand Down
5 changes: 3 additions & 2 deletions src/snyk/common/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,15 @@ export class Configuration implements IConfiguration {
get isFedramp(): boolean {
if (!this.customEndpoint) return false;

// FEDRAMP URL e.g. https://api.fedramp.snykgov.io
const endpoint = new URL(this.customEndpoint);

// hostname validation
const hostnameParts = endpoint.hostname.split('.');
if (hostnameParts.length < 3) return false;

const isFedrampInstance = hostnameParts[1] === 'fedramp';
const isFedrampDomain = hostnameParts[2] === 'snykgov' && hostnameParts[3] === 'io';
const isFedrampInstance = hostnameParts[1].includes('fedramp');
const isFedrampDomain = hostnameParts[2].includes('snykgov') && hostnameParts[3].includes('io');
return isFedrampDomain && isFedrampInstance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/integration/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ suite('Analytics', () => {
});

test('"Welcome Is Viewed" not tracked if using fedramp endpoint', async () => {
await configuration.setEndpoint('https://snyk.fedramp.gov');
await configuration.setEndpoint('https://api.fedramp.snykgov.io');
await vscode.commands.executeCommand('workbench.action.toggleSidebarVisibility');
await vscode.commands.executeCommand(VSCODE_VIEW_CONTAINER_COMMAND);

Expand Down

0 comments on commit b47d7a2

Please sign in to comment.