Skip to content

Commit c766301

Browse files
authored
Merge pull request #88 from CheckmarxDev/feature/AST-6696-codebashing-link
2 parents c2a8d35 + 71576be commit c766301

File tree

6 files changed

+49
-6
lines changed

6 files changed

+49
-6
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
CX_BASE_URI: ${{ secrets.BASE_URI }}
2121
CX_TENANT: ${{ secrets.TENANT }}
2222
CX_SCANID: ${{ secrets.SCANID }}
23+
CX_APIKEY: ${{ secrets.CX_APIKEY }}
2324
run: npm test
2425
cx-scan:
2526
runs-on: ubuntu-latest
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default class CxCodeBashing {
2+
path: string = "";
3+
cweId: string = "";
4+
language: string = "";
5+
queryName: string = "";
6+
7+
static parseCodeBashing(resultObject: any[]): CxCodeBashing[] {
8+
let codeBashingLink: CxCodeBashing[] = [];
9+
codeBashingLink = resultObject.map((member: any) => {
10+
let codeBashing = new CxCodeBashing();
11+
codeBashing.path = member.path;
12+
codeBashing.cweId = member.cwe_id;
13+
codeBashing.language = member.lang;
14+
codeBashing.queryName = member.cxQueryName;
15+
return codeBashing;
16+
});
17+
return codeBashingLink;
18+
}
19+
}

src/main/wrapper/CxConstants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export enum CxConstants {
2626
CMD_TRIAGE = "triage",
2727
SUB_CMD_UPDATE = "update",
2828
CMD_RESULT = "results",
29+
CMD_CODE_BASHING = "codebashing",
2930
SCAN_INFO_FORMAT = "--scan-info-format",
3031
FORMAT = "--format",
3132
FORMAT_JSON = "json",
@@ -46,7 +47,11 @@ export enum CxConstants {
4647
SCAN_TYPE = "CxScan",
4748
PROJECT_TYPE = "CxProject",
4849
PREDICATE_TYPE = "CxPredicate",
50+
CODE_BASHING_TYPE = "CxCodeBashing",
4951
SAST = "sast",
52+
LANGUAGE = "--language",
53+
VULNERABILITY_TYPE = "--vulnerabity-type",
54+
CWE_ID = "--cwe-id",
5055

5156
SEVERITY_HIGH = "high",
5257
SEVERITY_MEDIUM = "medium",

src/main/wrapper/CxWrapper.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,15 @@ export class CxWrapper {
195195
return await exec.executeCommands(this.config.pathToExecutable, commands);
196196
}
197197

198+
async codeBashingList(cweId:string,language:string,queryName:string): Promise<CxCommandOutput> {
199+
const commands: string[] = [CxConstants.CMD_RESULT, CxConstants.CMD_CODE_BASHING, CxConstants.LANGUAGE, language, CxConstants.VULNERABILITY_TYPE , queryName, CxConstants.CWE_ID , cweId];
200+
commands.push(...this.initializeCommands(true));
201+
const exec = new ExecutionService();
202+
return await exec.executeCommands(this.config.pathToExecutable, commands,CxConstants.CODE_BASHING_TYPE);
203+
}
204+
198205
resultsShow(scanId: string, reportFormat: string, outputFileName: string, outputPath: string): string[] {
199-
const commands: string[] = [CxConstants.CMD_RESULT,CxConstants.SUB_CMD_SHOW, CxConstants.SCAN_ID, scanId,CxConstants.REPORT_FORMAT , reportFormat];
206+
const commands: string[] = [CxConstants.CMD_RESULT, CxConstants.SUB_CMD_SHOW, CxConstants.SCAN_ID, scanId,CxConstants.REPORT_FORMAT , reportFormat];
200207
if (outputFileName) {
201208
commands.push(CxConstants.OUTPUT_NAME);
202209
commands.push(outputFileName);

src/main/wrapper/ExecutionService.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as os from "os";
66
import * as path from "path";
77
import CxResult from "../results/CxResult";
88
import CxProject from "../project/CxProject";
9+
import CxCodeBashing from "../codebashing/CxCodeBashing";
910

1011
const spawn = require('child_process').spawn;
1112

@@ -69,15 +70,19 @@ export class ExecutionService {
6970

7071
if (data) {
7172
let resultObject = JSON.parse(data);
72-
switch(output){
73-
case 'CxScan':
74-
let scans = CxScan.parseProject(resultObject)
73+
switch (output) {
74+
case "CxScan":
75+
let scans = CxScan.parseProject(resultObject);
7576
cxCommandOutput.payload = scans;
7677
break;
77-
case 'CxProject':
78-
let projects = CxProject.parseProject(resultObject)
78+
case "CxProject":
79+
let projects = CxProject.parseProject(resultObject);
7980
cxCommandOutput.payload = projects;
8081
break;
82+
case "CxCodeBashing":
83+
let codeBashing = CxCodeBashing.parseCodeBashing(resultObject);
84+
cxCommandOutput.payload = codeBashing;
85+
break;
8186
default:
8287
cxCommandOutput.payload = resultObject;
8388
}

src/tests/ResultTest.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ describe("Results cases",() => {
4040
expect(written.payload.length).toBeGreaterThan(0);
4141
});
4242

43+
it('Result codebashing successful case', async () => {
44+
const auth = new CxWrapper(cxScanConfig);
45+
const cxCommandOutput: CxCommandOutput = await auth.codeBashingList("79","PHP","Reflected XSS All Clients");
46+
expect(cxCommandOutput.payload.length).toBeGreaterThan(0);
47+
});
48+
4349
});
4450

4551
const fileExists = (file:any) => {

0 commit comments

Comments
 (0)