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

Chore: Update CHANGELOG [HEAD-78] #398

Closed
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI
on:
pull_request:
branches:
- main
- '**'
Copy link
Contributor

Choose a reason for hiding this comment

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

question: what does this do?

workflow_call:
secrets:
ITERATIVELY_KEY:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Snyk Security - Code and Open Source Dependencies Changelog

## [1.27.0]

### Feat

- Snyk LS: Snyk Open Source Security features now use Language Server backend

## [1.26.1]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Run extension and debug

Clone the repository, then run `npm install` in the directory.
Clone the repository, then run `npm install && npm run build` in the directory.

- Open repository directory in VS Code and press `F5` to run extension in a new VS Code window.
- This allows extension debugging within VS Code.
Expand Down
4 changes: 1 addition & 3 deletions src/snyk/base/modules/baseSnykModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { IMarkdownStringAdapter, MarkdownStringAdapter } from '../../common/vsco
import { IWatcher } from '../../common/watchers/interfaces';
import { ICodeSettings } from '../../snykCode/codeSettings';
import SnykEditorsWatcher from '../../snykCode/watchers/editorsWatcher';
import { OssService } from '../../snykOss/services/ossService';
import { OssService } from '../../snykOss/ossService';
import { OssVulnerabilityCountService } from '../../snykOss/services/vulnerabilityCount/ossVulnerabilityCountService';
import { IAuthenticationService } from '../services/authenticationService';
import { ScanModeService } from '../services/scanModeService';
Expand Down Expand Up @@ -85,6 +85,4 @@ export default abstract class BaseSnykModule implements IBaseSnykModule {
}

abstract runScan(): Promise<void>;

abstract runOssScan(): Promise<void>;
}
1 change: 0 additions & 1 deletion src/snyk/base/modules/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface IBaseSnykModule {

// Abstract methods
runScan(): Promise<void>;
runOssScan(manual?: boolean): Promise<void>;
}

export interface ISnykLib {
Expand Down
34 changes: 1 addition & 33 deletions src/snyk/base/modules/snykLib.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import * as _ from 'lodash';
import { firstValueFrom } from 'rxjs';
import { CliError } from '../../cli/services/cliService';
import { SupportedAnalysisProperties } from '../../common/analytics/itly';
import { configuration } from '../../common/configuration/instance';
import { DEFAULT_SCAN_DEBOUNCE_INTERVAL, IDE_NAME, OSS_SCAN_DEBOUNCE_INTERVAL } from '../../common/constants/general';
import { DEFAULT_SCAN_DEBOUNCE_INTERVAL, IDE_NAME } from '../../common/constants/general';
import { SNYK_CONTEXT } from '../../common/constants/views';
import { ErrorHandler } from '../../common/error/errorHandler';
import { Logger } from '../../common/logger/logger';
Expand All @@ -23,7 +21,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
return;
}

// Only starts OSS scan. Code & IaC scans are managed by LS
Logger.info('Starting full scan');

await this.contextService.setContext(SNYK_CONTEXT.AUTHENTICATING, false);
Expand All @@ -39,7 +36,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
const workspacePaths = vsCodeWorkspace.getWorkspaceFolders();
if (workspacePaths.length) {
this.logFullAnalysisIsTriggered(manual);
void this.startOssAnalysis(manual, false);
}
} catch (err) {
await ErrorHandler.handleGlobal(err, Logger, this.contextService, this.loadingBadge);
Expand All @@ -48,11 +44,8 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {

// This function is called by commands, error handlers, etc.
// We should avoid having duplicate parallel executions.
// Only starts OSS scan. Code & IaC scans are managed by LS
public runScan = _.debounce(this.runFullScan_.bind(this), DEFAULT_SCAN_DEBOUNCE_INTERVAL, { leading: true });

public runOssScan = _.debounce(this.startOssAnalysis.bind(this), OSS_SCAN_DEBOUNCE_INTERVAL, { leading: true });

async enableCode(): Promise<void> {
Logger.info('Enabling Snyk Code');
const wasEnabled = await this.codeSettings.enable();
Expand All @@ -66,12 +59,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
}
}

onDidChangeOssTreeVisibility(visible: boolean): void {
if (this.ossService) {
this.ossService.setVulnerabilityTreeVisibility(visible);
}
}

async checkAdvancedMode(): Promise<void> {
await this.contextService.setContext(SNYK_CONTEXT.ADVANCED, configuration.shouldShowAdvancedView);
}
Expand All @@ -81,25 +68,6 @@ export default class SnykLib extends BaseSnykModule implements ISnykLib {
await this.contextService.setContext(SNYK_CONTEXT.WORKSPACE_FOUND, workspaceFound);
}

private async startOssAnalysis(manual = false, reportTriggeredEvent = true): Promise<void> {
if (!configuration.getFeaturesConfiguration()?.ossEnabled) return;
if (!this.ossService) throw new Error('OSS service is not initialized.');

// wait until Snyk Language Server is downloaded
await firstValueFrom(this.downloadService.downloadReady$);

try {
const result = await this.ossService.test(manual, reportTriggeredEvent);

if (result instanceof CliError || !result) {
return;
}
} catch (err) {
// catch unhandled error cases by reporting test failure
this.ossService.finalizeTest(new CliError(err));
}
}

private isSnykCodeAutoscanSuspended(manual: boolean) {
return !manual && !this.scanModeService.isCodeAutoScanAllowed();
}
Expand Down
3 changes: 2 additions & 1 deletion src/snyk/cli/process.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import { OAuthToken } from '../base/services/authenticationService';
import { Configuration, IConfiguration } from '../common/configuration/configuration';
import { ILog } from '../common/logger/interfaces';
import { getVsCodeProxy } from '../common/proxy';
import { IVSCodeWorkspace } from '../common/vscode/workspace';
import { CLI_INTEGRATION_NAME } from './contants/integration';
import { CliError } from './services/cliService';
import { OAuthToken } from '../base/services/authenticationService';

export class CliProcess {
private runningProcess: ChildProcessWithoutNullStreams | null;
Expand All @@ -25,6 +25,7 @@ export class CliProcess {
return new Promise((resolve, reject) => {
let output = '';

// file deepcode ignore ArrayMethodOnNonArray: readonly string[] is an array of strings
this.logger.info(`Running "${cliPath} ${args.join(' ')}".`);

this.runningProcess = spawn(cliPath, args, { env: { ...process.env, ...processEnv }, cwd });
Expand Down
31 changes: 22 additions & 9 deletions src/snyk/common/commands/commandController.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import _ from 'lodash';
import path from 'path';
import { IAuthenticationService } from '../../base/services/authenticationService';
import { ScanModeService } from '../../base/services/scanModeService';
import { createDCIgnore } from '../../snykCode/utils/ignoreFileUtils';
import { createDCIgnore as createDCIgnoreUtil } from '../../snykCode/utils/ignoreFileUtils';
import { IssueUtils } from '../../snykCode/utils/issueUtils';
import { CodeIssueCommandArg } from '../../snykCode/views/interfaces';
import { IacIssueCommandArg } from '../../snykIac/views/interfaces';
import { capitalizeOssSeverity } from '../../snykOss/ossResult';
import { OssService } from '../../snykOss/services/ossService';
import { OssIssueCommandArg } from '../../snykOss/views/ossVulnerabilityTreeProvider';
import { OssService } from '../../snykOss/ossService';
import { IAnalytics } from '../analytics/itly';
import {
SNYK_INITIATE_LOGIN_COMMAND,
Expand Down Expand Up @@ -90,11 +89,11 @@ export class CommandController {
const paths = this.workspace.getWorkspaceFolders();
const promises = [];
for (const p of paths) {
promises.push(createDCIgnore(p, custom, this.workspace, this.window, uriAdapter));
promises.push(createDCIgnoreUtil(p, custom, this.workspace, this.window, uriAdapter));
}
await Promise.all(promises);
} else {
await createDCIgnore(path, custom, this.workspace, this.window, uriAdapter);
await createDCIgnoreUtil(path, custom, this.workspace, this.window, uriAdapter);
}
}

Expand Down Expand Up @@ -122,14 +121,28 @@ export class CommandController {
severity: IssueUtils.issueSeverityAsText(issue.severity),
});
} else if (arg.issueType == OpenCommandIssueType.OssVulnerability) {
const issue = arg.issue as OssIssueCommandArg;
void this.ossService.showSuggestionProvider(issue);
const issueArgs = arg.issue as CodeIssueCommandArg;
const folderPath = path.dirname(issueArgs.filePath);
const issue = this.ossService.getIssue(folderPath, issueArgs.id);

if (!issue) {
this.logger.warn(`Failed to find the issue ${issueArgs.id}.`);
return;
}

await this.openLocalFile(issue.filePath, issueArgs.range);

try {
await this.ossService.showSuggestionProvider(folderPath, issueArgs.id);
} catch (e) {
ErrorHandler.handle(e, this.logger);
}

this.analytics.logIssueInTreeIsClicked({
ide: IDE_NAME,
issueId: issue.id,
issueType: 'Open Source Vulnerability',
severity: capitalizeOssSeverity(issue.severity),
severity: IssueUtils.issueSeverityAsText(issue.severity),
});
} else if (arg.issueType == OpenCommandIssueType.IacIssue) {
const issueArgs = arg.issue as IacIssueCommandArg;
Expand Down
11 changes: 2 additions & 9 deletions src/snyk/common/commands/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { completeFileSuggestionType } from '../../snykCode/interfaces';
import { CodeIssueCommandArg } from '../../snykCode/views/interfaces';
import { IacIssueCommandArg } from '../../snykIac/views/interfaces';
import { OssIssueCommandArg } from '../../snykOss/views/ossVulnerabilityTreeProvider';
import { OssIssueCommandArg } from '../../snykOss/interfaces';
import { CodeIssueData, Issue } from '../languageServer/types';

export enum OpenCommandIssueType {
Expand All @@ -11,7 +11,7 @@ export enum OpenCommandIssueType {
}

export type OpenIssueCommandArg = {
issue: CodeIssueCommandArg | OssIssueCommandArg | IacIssueCommandArg;
issue: CodeIssueCommandArg | IacIssueCommandArg | OssIssueCommandArg;
issueType: OpenCommandIssueType;
};

Expand All @@ -21,10 +21,3 @@ export const isCodeIssue = (
): _issue is Issue<CodeIssueData> => {
return issueType === OpenCommandIssueType.CodeIssue;
};

export const isOssIssue = (
_issue: completeFileSuggestionType | Issue<CodeIssueData> | OssIssueCommandArg,
issueType: OpenCommandIssueType,
): _issue is OssIssueCommandArg => {
return issueType === OpenCommandIssueType.OssVulnerability;
};
1 change: 0 additions & 1 deletion src/snyk/common/constants/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const IDE_NAME_SHORT = 'vscode';
export const COMMAND_DEBOUNCE_INTERVAL = 200; // 200 milliseconds
export const DEFAULT_SCAN_DEBOUNCE_INTERVAL = 1000; // 1 second
export const DEFAULT_LS_DEBOUNCE_INTERVAL = 1000; // 1 second
export const OSS_SCAN_DEBOUNCE_INTERVAL = 10000; // 10 seconds
export const EXECUTION_THROTTLING_INTERVAL = 1000 * 10; // * 60 * 30; // 30 minutes
export const EXECUTION_PAUSE_INTERVAL = 1000 * 60 * 30; // 30 minutes
export const REFRESH_VIEW_DEBOUNCE_INTERVAL = 200; // 200 milliseconds
Expand Down
23 changes: 17 additions & 6 deletions src/snyk/common/editor/codeActionsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@ import { IAnalytics, SupportedQuickFixProperties } from '../../common/analytics/
import { IDE_NAME } from '../../common/constants/general';
import { Issue } from '../../common/languageServer/types';
import { ICodeActionKindAdapter } from '../../common/vscode/codeAction';
import { CodeAction, CodeActionKind, CodeActionProvider, Range, TextDocument } from '../../common/vscode/types';
import {
CodeAction,
CodeActionContext,
CodeActionKind,
CodeActionProvider,
Range,
TextDocument,
} from '../../common/vscode/types';
import { ProductResult } from '../services/productService';

export abstract class CodeActionsProvider<T> implements CodeActionProvider {
protected readonly providedCodeActionKinds = [this.codeActionKindAdapter.getQuickFix()];

constructor(
private readonly issues: ProductResult<T>,
protected readonly issues: ProductResult<T>,
private readonly codeActionKindAdapter: ICodeActionKindAdapter,
private readonly analytics: IAnalytics,
protected readonly analytics: IAnalytics,
) {}

abstract getActions(folderPath: string, document: TextDocument, issue: Issue<T>, issueRange: Range): CodeAction[];
abstract getActions(folderPath: string, document: TextDocument, issue: Issue<T>, issueRange?: Range): CodeAction[];

abstract getAnalyticsActionTypes(): [string, ...string[]] &
[SupportedQuickFixProperties, ...SupportedQuickFixProperties[]];
Expand All @@ -25,7 +32,11 @@ export abstract class CodeActionsProvider<T> implements CodeActionProvider {
return this.providedCodeActionKinds;
}

public provideCodeActions(document: TextDocument, clickedRange: Range): CodeAction[] | undefined {
public provideCodeActions(
document: TextDocument,
clickedRange: Range,
_context: CodeActionContext,
): CodeAction[] | undefined {
if (this.issues.size === 0) {
return undefined;
}
Expand Down Expand Up @@ -57,7 +68,7 @@ export abstract class CodeActionsProvider<T> implements CodeActionProvider {
return undefined;
}

private findIssueWithRange(
protected findIssueWithRange(
result: Issue<T>[],
document: TextDocument,
clickedRange: Range,
Expand Down
4 changes: 2 additions & 2 deletions src/snyk/common/languageServer/lsExecutable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ export class LsExecutable {
return customPath;
}

const platform = this.getCurrentWithArch();
const platform = LsExecutable.getCurrentWithArch();

const homeDir = Platform.getHomeDir();
const lsFilename = this.getFilename(platform);
const lsFilename = LsExecutable.getFilename(platform);
const defaultPath = this.defaultPaths[platform];
const lsDir = path.join(homeDir, defaultPath, 'snyk-ls');
return path.join(lsDir, lsFilename);
Expand Down
31 changes: 16 additions & 15 deletions src/snyk/common/languageServer/settings.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ from 'lodash';
import { CLI_INTEGRATION_NAME } from '../../cli/contants/integration';
import { Configuration, IConfiguration, SeverityFilter } from '../configuration/configuration';
import { User } from '../user';
Expand Down Expand Up @@ -57,35 +58,35 @@ export class LanguageServerSettings {
static async fromConfiguration(configuration: IConfiguration, user: User): Promise<ServerSettings> {
const featuresConfiguration = configuration.getFeaturesConfiguration();

const iacEnabled = defaultToTrue(featuresConfiguration.iacEnabled);
const codeSecurityEnabled = defaultToTrue(featuresConfiguration.codeSecurityEnabled);
const codeQualityEnabled = defaultToTrue(featuresConfiguration.codeQualityEnabled);
const ossEnabled = _.isUndefined(featuresConfiguration.ossEnabled) ? true : featuresConfiguration.ossEnabled;

return {
activateSnykCodeSecurity: codeSecurityEnabled,
activateSnykCodeQuality: codeQualityEnabled,
activateSnykOpenSource: 'false',
activateSnykIac: iacEnabled,
const iacEnabled = _.isUndefined(featuresConfiguration.iacEnabled) ? true : featuresConfiguration.iacEnabled;
const codeSecurityEnabled = _.isUndefined(featuresConfiguration.codeSecurityEnabled)
? true
: featuresConfiguration.codeSecurityEnabled;
const codeQualityEnabled = _.isUndefined(featuresConfiguration.codeQualityEnabled)
? true
: featuresConfiguration.codeQualityEnabled;

return {
activateSnykCodeSecurity: `${codeSecurityEnabled}`,
activateSnykCodeQuality: `${codeQualityEnabled}`,
activateSnykOpenSource: `${ossEnabled}`,
activateSnykIac: `${iacEnabled}`,
enableTelemetry: `${configuration.shouldReportEvents}`,
sendErrorReports: `${configuration.shouldReportErrors}`,
cliPath: configuration.getCliPath(),
endpoint: configuration.snykOssApiEndpoint,
organization: configuration.organization,

token: await configuration.getToken(),
automaticAuthentication: 'false',
additionalParams: configuration.getAdditionalCliParameters(),
manageBinariesAutomatically: `${configuration.isAutomaticDependencyManagementEnabled()}`,

sendErrorReports: `${configuration.shouldReportErrors}`,
enableTelemetry: `${configuration.shouldReportEvents}`,

filterSeverity: configuration.severityFilter,
scanningMode: configuration.scanningMode,
insecure: `${configuration.getInsecure()}`,

enableTrustedFoldersFeature: 'true',
trustedFolders: configuration.getTrustedFolders(),

integrationName: CLI_INTEGRATION_NAME,
integrationVersion: await Configuration.getVersion(),
deviceId: user.anonymousId,
Expand Down
2 changes: 2 additions & 0 deletions src/snyk/common/languageServer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export type OssIssueData = {

projectName: string;
displayTargetFile: string;

details: string;
};
export type Identifiers = {
CWE: string[];
Expand Down
Loading
Loading