Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/checkmarx-one-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Checkout
uses: actions/[email protected]
- name: Checkmarx One CLI Action
uses: checkmarx/ast-github-action@6c56658230f79c227a55120e9b24845d574d5225 #2.0.31
uses: checkmarx/ast-github-action@main
with:
base_uri: ${{ secrets.AST_RND_SCANS_BASE_URI }}
cx_tenant: ${{ secrets.AST_RND_SCANS_TENANT }}
Expand Down
42 changes: 33 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,19 @@
"*"
],
"main": "./out/extension.js",
"contributes": {
"commands": [
"contributes": { "commands": [
{
"command": "ast-results.testCopilotChatIntegration",
"category": "ast-results",
"title": "Test Copilot Chat Integration"
},
{
"command": "ast-results.openCopilotChat",
"category": "ast-results",
"title": "Ask Copilot About Vulnerability",
"icon": "$(comment-discussion)",
"enablement": "ast-results.isValidCredentials"
},
{
"command": "ast-results.newDetails",
"title": "Details"
Expand Down Expand Up @@ -504,6 +515,10 @@
"title": "Run SCA Realtime Scan",
"icon": "$(notebook-execute)",
"enablement": "ast-results.isSCAScanEnabled"
},
{
"command": "ast-results.openCopilotChatWithQuery",
"title": "Open Copilot Chat with Query"
}
],
"submenus": [
Expand Down Expand Up @@ -586,8 +601,17 @@
"group": "navigation@2",
"when": "!ast-results-Ignored"
}
],
"view/item/context": [
], "view/item/context": [
{
"command": "ast-results.openCopilotChat",
"group": "inline@1",
"when": "viewItem == vulnerability-item"
},
{
"command": "ast-results.debugTreeItem",
"group": "inline@2",
"when": "viewItem == vulnerability-item"
},
{
"command": "ast-results.projectPick",
"group": "inline@3",
Expand Down Expand Up @@ -882,11 +906,11 @@
}
},
{
"title": "Activate Vorpal Real-time Scanning",
"id": "vorpal",
"title": "Activate ASCA",
"id": "asca",
"order": 2,
"properties": {
"CheckmarxVorpal.Activate Vorpal Real-time Scanning": {
"Checkmarx AI Secure Coding Assistant (ASCA).Activate ASCA": {
"type": "boolean",
"order": 3,
"default": false,
Expand Down Expand Up @@ -916,8 +940,8 @@
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.2.0",
"chai": "4.3.1",
"eslint-config-prettier": "^9.1.0",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"mocha": "10.3.0",
"typescript": "^5.5.3",
"vsce": "^2.15.0",
Expand All @@ -927,7 +951,7 @@
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@checkmarxdev/ast-cli-javascript-wrapper": "0.0.113",
"@checkmarxdev/ast-cli-javascript-wrapper": "0.0.114",
"copyfiles": "2.4.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-node": "^11.1.0",
Expand Down
48 changes: 24 additions & 24 deletions src/vorpal/vorpalService.ts → src/asca/ascaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import path from "path";
import * as os from "os";
import { error } from "console";
import { Logs } from "../models/logs";
import CxVorpal from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/vorpal/CxVorpal";
import CxAsca from "@checkmarxdev/ast-cli-javascript-wrapper/dist/main/asca/CxAsca";
import { constants } from "../utils/common/constants";

const vorpalDir = "CxVorpal";
const ascaDir = "CxVorpal";

export const diagnosticCollection = vscode.languages.createDiagnosticCollection(
constants.extensionFullName
);

export async function scanVorpal(document: vscode.TextDocument, logs: Logs) {
export async function scanAsca(document: vscode.TextDocument, logs: Logs) {

if (ignoreFiles(document))
{return;}
Expand All @@ -24,30 +24,30 @@ export async function scanVorpal(document: vscode.TextDocument, logs: Logs) {
path.basename(document.uri.fsPath),
document.getText()
);
// RUN VORPAL SCAN
logs.info("Start Vorpal Scan On File: " + document.uri.fsPath);
const scanVorpalResult = await cx.scanVorpal(filePath);
// RUN ASCA SCAN
logs.info("Start ASCA scan On File: " + document.uri.fsPath);
const scanAscaResult = await cx.scanAsca(filePath);
// DELETE TEMP FILE
deleteFile(filePath);
console.info("file %s deleted", filePath);
// HANDLE ERROR
if (scanVorpalResult.error) {
if (scanAscaResult.error) {
logs.warn(
"Vorpal Warning: " +
(scanVorpalResult.error.description ?? scanVorpalResult.error)
"ASCA Warning: " +
(scanAscaResult.error.description ?? scanAscaResult.error)
);
return;
}
// VIEW PROBLEMS
logs.info(
scanVorpalResult.scanDetails.length +
" security best coding practices issues were found in " +
scanAscaResult.scanDetails.length +
" security best practice violations were found in " +
document.uri.fsPath
);
updateProblems(scanVorpalResult, document.uri);
updateProblems(scanAscaResult, document.uri);
} catch (error) {
console.error(error);
logs.error(constants.errorScanVorpal);
logs.error(constants.errorScanAsca);
}
}

Expand All @@ -56,16 +56,16 @@ function ignoreFiles(document: vscode.TextDocument): boolean {
return document.uri.scheme !== 'file';
}

export async function clearVorpalProblems() {
export async function clearAscaProblems() {
diagnosticCollection.clear();
}

function updateProblems(scanVorpalResult: CxVorpal, uri: vscode.Uri) {
function updateProblems(scanAscaResult: CxAsca, uri: vscode.Uri) {
diagnosticCollection.delete(uri);
const diagnostics: vscode.Diagnostic[] = [];

for (let i = 0; i < scanVorpalResult.scanDetails.length; i++) {
const res = scanVorpalResult.scanDetails[i];
for (let i = 0; i < scanAscaResult.scanDetails.length; i++) {
const res = scanAscaResult.scanDetails[i];
const range = new vscode.Range(
new vscode.Position(res.line - 1, 0),
new vscode.Position(res.line - 1, 100)
Expand All @@ -75,24 +75,24 @@ function updateProblems(scanVorpalResult: CxVorpal, uri: vscode.Uri) {
`${res.ruleName} - ${res.remediationAdvise}`,
parseSeverity(res.severity)
);
diagnostic.source = constants.vorpalEngineName;
diagnostic.source = constants.ascaEngineName;
diagnostics.push(diagnostic);
}
diagnosticCollection.set(uri, diagnostics);
}

function parseSeverity(vorpalSeverity: string): vscode.DiagnosticSeverity {
function parseSeverity(ascaSeverity: string): vscode.DiagnosticSeverity {
const severityMap: Record<string, vscode.DiagnosticSeverity> = {
CRITICAL: vscode.DiagnosticSeverity.Error,
HIGH: vscode.DiagnosticSeverity.Error,
MEDIUM: vscode.DiagnosticSeverity.Warning,
LOW: vscode.DiagnosticSeverity.Information
};

const severity = severityMap[vorpalSeverity.toUpperCase()];
const severity = severityMap[ascaSeverity.toUpperCase()];

if (severity === undefined) {
console.log(`Invalid vorpalSeverity value: ${vorpalSeverity}`);
console.log(`Invalid ASCASeverity value: ${ascaSeverity}`);
return vscode.DiagnosticSeverity.Information;
}

Expand All @@ -102,7 +102,7 @@ function parseSeverity(vorpalSeverity: string): vscode.DiagnosticSeverity {
function saveTempFile(fileName: string, content: string): string | null {
try {
const tempDir = os.tmpdir();
const tempFilePath = path.join(tempDir, vorpalDir, fileName);
const tempFilePath = path.join(tempDir, ascaDir, fileName);
fs.writeFileSync(tempFilePath, content);
console.info("Temp file was saved in: " + tempFilePath);
return tempFilePath;
Expand All @@ -112,9 +112,9 @@ function saveTempFile(fileName: string, content: string): string | null {
}
}

export async function installVorpal(logs: Logs) {
export async function installAsca(logs: Logs) {
try {
const res = await cx.installVorpal();
const res = await cx.installAsca();
if (res.error) {
const errorMessage = constants.errorInstallation + " : " + res.error;
vscode.window.showErrorMessage(errorMessage);
Expand Down
46 changes: 23 additions & 23 deletions src/commands/vorpalCommand.ts → src/commands/ascaCommand.ts
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import * as vscode from "vscode";
import { Logs } from "../models/logs";
import {
clearVorpalProblems,
installVorpal,
scanVorpal,
} from "../vorpal/vorpalService";
clearAscaProblems,
installAsca,
scanAsca,
} from "../asca/ascaService";
import { constants } from "../utils/common/constants";

let timeout = null;
export class VorpalCommand {
export class AscaCommand {
context: vscode.ExtensionContext;
logs: Logs;
onDidChangeTextDocument: vscode.Disposable;
constructor(context: vscode.ExtensionContext, logs: Logs) {
this.context = context;
this.logs = logs;
}
public async registerVorpal() {
public async registerAsca() {
try {
const vorpalActive = vscode.workspace
.getConfiguration(constants.CheckmarxVorpal)
.get(constants.ActivateVorpalAutoScanning) as boolean;
if (vorpalActive) {
await this.installVorpal();
await this.registerVorpalScanOnChangeText();
this.logs.info(constants.vorpalStart);
const ascaActive = vscode.workspace
.getConfiguration(constants.CheckmarxAsca)
.get(constants.ActivateAscaAutoScanning) as boolean;
if (ascaActive) {
await this.installAsca();
await this.registerAscaScanOnChangeText();
this.logs.info(constants.ascaStart);
} else {
await this.disposeVorpalScanOnChangeText();
await clearVorpalProblems();
this.logs.info(constants.vorpalDisabled);
await this.disposeAscaScanOnChangeText();
await clearAscaProblems();
this.logs.info(constants.ascaDisabled);
}
} catch (error) {
console.error(error);
}
}
public installVorpal() {
installVorpal(this.logs);
public installAsca() {
installAsca(this.logs);
this.onDidChangeTextDocument = vscode.workspace.onDidChangeTextDocument(
// Must be no less than 2000ms. Otherwise, the temporary file can be deleted before the vorpal scan is finished.
// Must be no less than 2000ms. Otherwise, the temporary file can be deleted before the ASCA scan is finished.
this.debounce(this.onTextChange, 2000)
);
}

public onTextChange(event) {
try {
scanVorpal(event.document, this.logs);
scanAsca(event.document, this.logs);
} catch (error) {
console.error(error);
this.logs.warn("fail to scan vorpal");
this.logs.warn("fail to scan ASCA");
}
}
// Debounce function
Expand All @@ -68,10 +68,10 @@ export class VorpalCommand {
};
}

public registerVorpalScanOnChangeText() {
public registerAscaScanOnChangeText() {
this.context.subscriptions.push(this.onDidChangeTextDocument);
}
public disposeVorpalScanOnChangeText() {
public disposeAscaScanOnChangeText() {
if (this.onDidChangeTextDocument) {
this.onDidChangeTextDocument.dispose();
this.context.subscriptions.push(this.onDidChangeTextDocument);
Expand Down
Loading