From 21a355e4c7aa4b0f3b5b0a21e305ff4a861a64f6 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 6 Aug 2024 09:32:05 +0300 Subject: [PATCH 1/5] Vorpal in VsCode is unable to run scans in sampes with complex names --- src/main/wrapper/ExecutionService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index c781805b..f175c49d 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -42,7 +42,7 @@ function transformation(commands: string[]):string[] { function transform(n:string) { let r = ""; - if(n) r = n.replace(/["']/g, "").replace("/[, ]/g",","); + if(n) r = n.replace(/["]/g, "").replace("/[, ]/g",","); return r; } From 55d912a5c2b055dc2e4fdc51e6a3a8877bf46e6e Mon Sep 17 00:00:00 2001 From: elchananarb Date: Tue, 6 Aug 2024 10:25:19 +0300 Subject: [PATCH 2/5] v2 To talk with Tiago, if necessary, we'll do it this way --- src/main/wrapper/ExecutionService.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index f175c49d..2849312e 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -24,6 +24,7 @@ import CxChat from "../chat/CxChat"; import CxMask from "../mask/CxMask"; import CxVorpal from "../vorpal/CxVorpal"; +let skipNext = false; function isJsonString(s: string) { try { @@ -35,14 +36,26 @@ function isJsonString(s: string) { return true; } -function transformation(commands: string[]):string[] { - const result:string[] = commands.map(transform); +function transformation(commands: string[]): string[] { + skipNext = false; // Reset the flag before processing + const result: string[] = commands.map(transform); return result; } function transform(n:string) { + // If the flag is set, return the current string as-is and reset the flag + if (skipNext) { + skipNext = false; + return n; + } + // If the current string is "--file-source", set the flag and return it as-is + if (n === "--file-source") { + skipNext = true; + return n; + } + let r = ""; - if(n) r = n.replace(/["]/g, "").replace("/[, ]/g",","); + if(n) r = n.replace(/["']/g, "").replace("/[, ]/g",","); return r; } From 8c045501aad02852f932a277a1228e0d4ae2f7c4 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Wed, 7 Aug 2024 10:48:54 +0300 Subject: [PATCH 3/5] Update ExecutionService.ts --- src/main/wrapper/ExecutionService.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index 2849312e..381a5fa9 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -24,7 +24,8 @@ import CxChat from "../chat/CxChat"; import CxMask from "../mask/CxMask"; import CxVorpal from "../vorpal/CxVorpal"; -let skipNext = false; +let skipValue = false; +const fileSourceFlag = "--file-source" function isJsonString(s: string) { try { @@ -37,20 +38,20 @@ function isJsonString(s: string) { } function transformation(commands: string[]): string[] { - skipNext = false; // Reset the flag before processing + skipValue = false; // Reset the flag before processing const result: string[] = commands.map(transform); return result; } function transform(n:string) { // If the flag is set, return the current string as-is and reset the flag - if (skipNext) { - skipNext = false; + if (skipValue) { + skipValue = false; return n; } // If the current string is "--file-source", set the flag and return it as-is - if (n === "--file-source") { - skipNext = true; + if (n === fileSourceFlag) { + skipValue = true; return n; } From 131501f5e40ebc9dd61a8b384358937ad927ec91 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Thu, 8 Aug 2024 19:08:17 +0300 Subject: [PATCH 4/5] Update ExecutionService.ts --- src/main/wrapper/ExecutionService.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/wrapper/ExecutionService.ts b/src/main/wrapper/ExecutionService.ts index 381a5fa9..6311d5b6 100644 --- a/src/main/wrapper/ExecutionService.ts +++ b/src/main/wrapper/ExecutionService.ts @@ -44,15 +44,17 @@ function transformation(commands: string[]): string[] { } function transform(n:string) { - // If the flag is set, return the current string as-is and reset the flag + +// in case the file name looks like this: 'var express require('express');.js' we won't delete "'" if (skipValue) { skipValue = false; - return n; + let r = ""; + if(n) r = n.replace(/["]/g, "").replace("/[, ]/g",","); + return r; } - // If the current string is "--file-source", set the flag and return it as-is + // If the current string is "--file-source", set the flag if (n === fileSourceFlag) { skipValue = true; - return n; } let r = ""; From 74b3b893a3cf827b81634be9219279c5e6722140 Mon Sep 17 00:00:00 2001 From: elchananarb Date: Sun, 11 Aug 2024 13:21:07 +0300 Subject: [PATCH 5/5] add test --- src/tests/ScanTest.test.ts | 10 ++++++++++ tsc/tests/data/var express = require('express';.js | 1 + 2 files changed, 11 insertions(+) create mode 100644 tsc/tests/data/var express = require('express';.js diff --git a/src/tests/ScanTest.test.ts b/src/tests/ScanTest.test.ts index 56cf7c96..fb7b9a69 100644 --- a/src/tests/ScanTest.test.ts +++ b/src/tests/ScanTest.test.ts @@ -145,6 +145,16 @@ describe("ScanCreate cases", () => { expect(scanObject.status).toEqual(true); }); + it('ScanVorpal with complex name Successful case', async () => { + const auth = new CxWrapper(cxScanConfig); + const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/var express = require('express';.js"); + console.log("Json object from scanVorpal successful case: " + JSON.stringify(cxCommandOutput)); + const scanObject = cxCommandOutput.payload.pop(); + expect(cxCommandOutput.payload).toBeDefined(); + expect(cxCommandOutput.exitCode).toBe(0); + expect(scanObject.status).toEqual(true); + }); + it('ScanVorpal Successful case with update version', async () => { const auth = new CxWrapper(cxScanConfig); const cxCommandOutput: CxCommandOutput = await auth.scanVorpal("tsc/tests/data/python-vul-file.py", true); diff --git a/tsc/tests/data/var express = require('express';.js b/tsc/tests/data/var express = require('express';.js new file mode 100644 index 00000000..11a74e4c --- /dev/null +++ b/tsc/tests/data/var express = require('express';.js @@ -0,0 +1 @@ +var password = "Jf9$gH!sD7#lq2nW";