codesentry 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +35 -16
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli.ts
|
|
4
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
5
|
+
import { createRequire as createRequire4 } from "module";
|
|
4
6
|
import { Command } from "commander";
|
|
5
7
|
import figlet from "figlet";
|
|
6
8
|
import gradient from "gradient-string";
|
|
@@ -272,16 +274,26 @@ import { availableParallelism } from "os";
|
|
|
272
274
|
|
|
273
275
|
// src/scanner/file-finder.ts
|
|
274
276
|
import { readdir } from "fs/promises";
|
|
275
|
-
import { join
|
|
277
|
+
import { join } from "path";
|
|
276
278
|
var SCANNABLE_EXTENSIONS = [".js", ".ts", ".jsx", ".tsx"];
|
|
277
279
|
var IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", ".next"]);
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
+
var isScannable = (fileName) => SCANNABLE_EXTENSIONS.some((ext) => fileName.endsWith(ext));
|
|
281
|
+
var walk = async (currentDir) => {
|
|
282
|
+
const entries = await readdir(currentDir, { withFileTypes: true });
|
|
283
|
+
const files = [];
|
|
284
|
+
for (const entry of entries) {
|
|
285
|
+
if (entry.isDirectory()) {
|
|
286
|
+
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
287
|
+
files.push(...await walk(join(currentDir, entry.name)));
|
|
288
|
+
} else if (entry.isFile() && isScannable(entry.name)) {
|
|
289
|
+
files.push(join(currentDir, entry.name));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return files;
|
|
280
293
|
};
|
|
281
294
|
var findFiles = async (targetDir) => {
|
|
282
295
|
try {
|
|
283
|
-
|
|
284
|
-
return entries.filter((entry) => entry.isFile()).map((entry) => join(entry.parentPath, entry.name)).filter((filePath) => !isInsideIgnoredDir(filePath)).filter((filePath) => SCANNABLE_EXTENSIONS.some((ext) => filePath.endsWith(ext)));
|
|
296
|
+
return await walk(targetDir);
|
|
285
297
|
} catch (error) {
|
|
286
298
|
throw new Error(`N\xE3o foi poss\xEDvel listar os arquivos em "${targetDir}".`, { cause: error });
|
|
287
299
|
}
|
|
@@ -451,9 +463,10 @@ var runBundledSemgrep = async (targetDir, runtime = resolveBundledSemgrepRuntime
|
|
|
451
463
|
"."
|
|
452
464
|
];
|
|
453
465
|
let stdout;
|
|
466
|
+
const SYSTEM_PATH_FALLBACK = process.platform === "win32" ? "C:\\Windows\\System32;C:\\Windows" : "/usr/local/bin:/usr/bin:/bin";
|
|
454
467
|
const env = {
|
|
455
468
|
...process.env,
|
|
456
|
-
PATH: `${dirname2(runtime.semgrep)}${delimiter}${process.env.PATH ?? ""}`
|
|
469
|
+
PATH: `${dirname2(runtime.semgrep)}${delimiter}${process.env.PATH ?? ""}${delimiter}${SYSTEM_PATH_FALLBACK}`
|
|
457
470
|
};
|
|
458
471
|
try {
|
|
459
472
|
({ stdout } = await execute(runtime.semgrep, args, { cwd: targetDir, maxBuffer: 20 * 1024 * 1024, env }));
|
|
@@ -573,9 +586,9 @@ var isSourceNode2 = (value) => {
|
|
|
573
586
|
var walkChildren = (node, depth, results) => {
|
|
574
587
|
for (const value of Object.values(node)) {
|
|
575
588
|
if (Array.isArray(value)) {
|
|
576
|
-
value.filter(isSourceNode2).forEach((child) =>
|
|
589
|
+
value.filter(isSourceNode2).forEach((child) => walk2(child, depth, results));
|
|
577
590
|
} else if (isSourceNode2(value)) {
|
|
578
|
-
|
|
591
|
+
walk2(value, depth, results);
|
|
579
592
|
}
|
|
580
593
|
}
|
|
581
594
|
};
|
|
@@ -586,7 +599,7 @@ var checkDepth = (newDepth, line, results) => {
|
|
|
586
599
|
};
|
|
587
600
|
var walkIfChild = (value, depth, results) => {
|
|
588
601
|
if (isSourceNode2(value)) {
|
|
589
|
-
|
|
602
|
+
walk2(value, depth, results);
|
|
590
603
|
}
|
|
591
604
|
};
|
|
592
605
|
var walkIfAlternate = (alternate, depth, results) => {
|
|
@@ -597,7 +610,7 @@ var walkIfAlternate = (alternate, depth, results) => {
|
|
|
597
610
|
walkIfChain(alternate, depth, results);
|
|
598
611
|
return;
|
|
599
612
|
}
|
|
600
|
-
|
|
613
|
+
walk2(alternate, depth + 1, results);
|
|
601
614
|
};
|
|
602
615
|
var walkIfChain = (node, depth, results) => {
|
|
603
616
|
const chainDepth = depth + 1;
|
|
@@ -617,13 +630,13 @@ var walkNestingBlock = (node, depth, results) => {
|
|
|
617
630
|
var selectWalker = (node) => {
|
|
618
631
|
return FUNCTION_TYPES.has(node.type) ? walkFunction : node.type === "IfStatement" ? walkIfChain : NESTING_TYPES.has(node.type) ? walkNestingBlock : walkChildren;
|
|
619
632
|
};
|
|
620
|
-
var
|
|
633
|
+
var walk2 = (node, depth, results) => {
|
|
621
634
|
selectWalker(node)(node, depth, results);
|
|
622
635
|
};
|
|
623
636
|
var findDeepNesting = (filePath, content) => {
|
|
624
637
|
const results = [];
|
|
625
638
|
const sourceFile = parseSourceFile(filePath, content);
|
|
626
|
-
|
|
639
|
+
walk2(sourceFile, 0, results);
|
|
627
640
|
return results;
|
|
628
641
|
};
|
|
629
642
|
var deepNestingRule = {
|
|
@@ -892,9 +905,9 @@ var appendOverLimitContext = (context, state) => {
|
|
|
892
905
|
};
|
|
893
906
|
var walkChild = (value, parent, context, state) => {
|
|
894
907
|
if (Array.isArray(value)) {
|
|
895
|
-
value.filter(isSourceNode3).forEach((child) =>
|
|
908
|
+
value.filter(isSourceNode3).forEach((child) => walk3(child, parent, context, state));
|
|
896
909
|
} else if (isSourceNode3(value)) {
|
|
897
|
-
|
|
910
|
+
walk3(value, parent, context, state);
|
|
898
911
|
}
|
|
899
912
|
};
|
|
900
913
|
var walkChildren2 = (node, context, state) => {
|
|
@@ -912,7 +925,7 @@ var incrementStatementCount = (node, context, state) => {
|
|
|
912
925
|
context.count += 1;
|
|
913
926
|
}
|
|
914
927
|
};
|
|
915
|
-
var
|
|
928
|
+
var walk3 = (node, parent, context, state) => {
|
|
916
929
|
if (FUNCTION_TYPES2.has(node.type)) {
|
|
917
930
|
walkFunction2(node, parent, state);
|
|
918
931
|
return;
|
|
@@ -2495,9 +2508,15 @@ var registerSecurityCommands = (program) => {
|
|
|
2495
2508
|
registerSensitiveDataInLogsCommand(program);
|
|
2496
2509
|
registerPublicEnvVarSecretCommand(program);
|
|
2497
2510
|
};
|
|
2511
|
+
var require5 = createRequire4(import.meta.url);
|
|
2512
|
+
var readPackageVersion = () => {
|
|
2513
|
+
const packageJsonPath = require5.resolve("../package.json");
|
|
2514
|
+
const { version } = JSON.parse(readFileSync2(packageJsonPath, "utf-8"));
|
|
2515
|
+
return version;
|
|
2516
|
+
};
|
|
2498
2517
|
var createCli = () => {
|
|
2499
2518
|
printBanner();
|
|
2500
|
-
const program = new Command().name("codesentry").description("CLI de verifica\xE7\xE3o de vulnerabilidades e qualidade de c\xF3digo").version(
|
|
2519
|
+
const program = new Command().name("codesentry").description("CLI de verifica\xE7\xE3o de vulnerabilidades e qualidade de c\xF3digo").version(readPackageVersion()).helpCommand(false);
|
|
2501
2520
|
registerInitCommand(program);
|
|
2502
2521
|
registerAnalysisCommands(program);
|
|
2503
2522
|
registerQualityCommands(program);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codesentry",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"workspaces": [
|
|
5
5
|
"packages/semgrep-rules"
|
|
6
6
|
],
|
|
@@ -48,7 +48,6 @@
|
|
|
48
48
|
"@clack/prompts": "^1.7.0",
|
|
49
49
|
"chalk": "^6.0.0",
|
|
50
50
|
"cli-table3": "^0.6.5",
|
|
51
|
-
"codesentry-semgrep-rules": "0.1.4",
|
|
52
51
|
"commander": "^15.0.0",
|
|
53
52
|
"eslint": "^10.10.0",
|
|
54
53
|
"eslint-plugin-no-unsanitized": "^4.1.5",
|
|
@@ -59,8 +58,8 @@
|
|
|
59
58
|
"p-limit": "^7.3.2"
|
|
60
59
|
},
|
|
61
60
|
"optionalDependencies": {
|
|
62
|
-
"codesentry-semgrep-linux-x64": "0.1.
|
|
63
|
-
"codesentry-semgrep-win32-x64": "0.1.
|
|
61
|
+
"codesentry-semgrep-linux-x64": "0.1.6",
|
|
62
|
+
"codesentry-semgrep-win32-x64": "0.1.6"
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
66
65
|
"@types/node": "^26.4.1",
|