deepscan-cli 1.2.0 → 1.2.1

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/README.md CHANGED
@@ -241,6 +241,54 @@ deepscan report convert results.json --to html --output report.html
241
241
 
242
242
  ---
243
243
 
244
+ ## 🤖 GitHub Actions (CI/CD & Code Scanning)
245
+
246
+ Run DeepScan automatically on every push and pull request, detect security & OOM-kill bugs, and upload SARIF results directly to the **GitHub Security → Code Scanning** tab:
247
+
248
+ ```yaml
249
+ name: DeepScan Security & Ops Check
250
+
251
+ on:
252
+ push:
253
+ branches: [main]
254
+ pull_request:
255
+ branches: [main]
256
+
257
+ permissions:
258
+ contents: read
259
+ security-events: write
260
+
261
+ jobs:
262
+ deepscan:
263
+ runs-on: ubuntu-latest
264
+ steps:
265
+ - uses: actions/checkout@v4
266
+
267
+ - name: Run DeepScan (SAST + Ops/OOM-Kill)
268
+ uses: maiductuan/code-security-scanner@v1.2.0
269
+ with:
270
+ path: '.'
271
+ scanners: 'security,ops'
272
+ fail-on: 'critical,high'
273
+ upload-sarif: 'true'
274
+ ```
275
+
276
+ ### Action Inputs
277
+
278
+ | Input | Description | Default |
279
+ | :--- | :--- | :--- |
280
+ | `path` | Target path to scan | `.` |
281
+ | `scanners` | Comma-separated scanners (`security,ops,quality,cve`) | `security,ops` |
282
+ | `severity` | Severities to report (`critical,high,medium,low`) | `critical,high,medium,low` |
283
+ | `fail-on` | Severities that fail the job (`none` to never fail) | `critical,high` |
284
+ | `format` | Output format (`sarif`, `json`, `html`, `csv`, `console`) | `sarif` |
285
+ | `output` | Output report file path | `deepscan-results.sarif` |
286
+ | `upload-sarif` | Upload SARIF report to GitHub Code Scanning | `true` |
287
+ | `baseline` | Optional baseline JSON file path to ignore existing findings | `""` |
288
+ | `deep` | Enable taint flow & semantic analysis | `false` |
289
+
290
+ ---
291
+
244
292
  ## 🤖 AI-Assisted Validation
245
293
 
246
294
  Enable AI validation to reduce false positives (optional):
@@ -320,8 +368,8 @@ This section is intended for developers and users who want to run DeepScan from
320
368
  ### Setup
321
369
  Clone the repository and install all dependencies:
322
370
  ```bash
323
- git clone https://github.com/your-org/code-scan-security.git
324
- cd code-scan-security
371
+ git clone https://github.com/maiductuan/code-security-scanner.git
372
+ cd code-security-scanner
325
373
  npm install
326
374
  ```
327
375
 
@@ -13,7 +13,7 @@ import {
13
13
  loadBaseline,
14
14
  loadConfig,
15
15
  saveBaseline
16
- } from "../chunk-KITQQYNW.js";
16
+ } from "../chunk-4TWV5TES.js";
17
17
 
18
18
  // src/cli/index.ts
19
19
  import { Command as Command5 } from "commander";
@@ -11,7 +11,7 @@ var OutputFormatSchema = z.enum(["json", "csv", "html", "sarif", "console"]);
11
11
  var SecurityScannerSchema = z.object({
12
12
  enabled: z.boolean().default(true),
13
13
  severity: z.array(SeveritySchema).default(["critical", "high", "medium", "low"])
14
- }).default({});
14
+ }).prefault({});
15
15
  var QualityThresholdsSchema = z.object({
16
16
  maxComplexity: z.number().min(1).default(15),
17
17
  maxCognitiveComplexity: z.number().min(1).default(20),
@@ -19,31 +19,31 @@ var QualityThresholdsSchema = z.object({
19
19
  maxFunctionLength: z.number().min(5).default(50),
20
20
  maxNestingDepth: z.number().min(1).default(4),
21
21
  minCommentRatio: z.number().min(0).max(1).default(0.02)
22
- }).default({});
22
+ }).prefault({});
23
23
  var QualityScannerSchema = z.object({
24
24
  enabled: z.boolean().default(false),
25
25
  thresholds: QualityThresholdsSchema
26
- }).default({});
26
+ }).prefault({});
27
27
  var CVEScannerSchema = z.object({
28
28
  enabled: z.boolean().default(false),
29
29
  sources: z.array(z.string()).default(["osv"]),
30
30
  failOnSeverity: SeveritySchema.optional()
31
- }).default({});
31
+ }).prefault({});
32
32
  var OpsScannerSchema = z.object({
33
33
  enabled: z.boolean().default(true),
34
34
  severity: z.array(SeveritySchema).default(["critical", "high", "medium", "low"])
35
- }).default({});
35
+ }).prefault({});
36
36
  var ScannersSchema = z.object({
37
37
  security: SecurityScannerSchema,
38
38
  quality: QualityScannerSchema,
39
39
  cve: CVEScannerSchema,
40
40
  ops: OpsScannerSchema
41
- }).default({});
41
+ }).prefault({});
42
42
  var RulesSchema = z.object({
43
43
  include: z.array(z.string()).default(["*"]),
44
44
  exclude: z.array(z.string()).default([]),
45
45
  custom: z.array(z.string()).default([])
46
- }).default({});
46
+ }).prefault({});
47
47
  var PathsSchema = z.object({
48
48
  include: z.array(z.string()).default(["**/*"]),
49
49
  exclude: z.array(z.string()).default([
@@ -75,13 +75,13 @@ var PathsSchema = z.object({
75
75
  "**/*.chunk.js",
76
76
  "**/*.map"
77
77
  ])
78
- }).default({});
78
+ }).prefault({});
79
79
  var OutputSchema = z.object({
80
80
  format: OutputFormatSchema.default("console"),
81
81
  file: z.string().optional(),
82
82
  verbose: z.boolean().default(false),
83
83
  colors: z.boolean().default(true)
84
- }).default({});
84
+ }).prefault({});
85
85
  var AISchema = z.object({
86
86
  enabled: z.boolean().default(false),
87
87
  provider: z.enum(["openai", "anthropic", "ollama", "google"]).default("openai"),
@@ -90,12 +90,12 @@ var AISchema = z.object({
90
90
  baseUrl: z.string().optional(),
91
91
  maxFindings: z.number().min(1).default(20),
92
92
  temperature: z.number().min(0).max(2).default(0.1)
93
- }).default({});
93
+ }).prefault({});
94
94
  var ContextSchema = z.object({
95
95
  projectType: z.enum(["web", "api", "library", "mobile", "cli", "auto"]).default("auto"),
96
96
  frameworks: z.array(z.string()).default([]),
97
97
  sensitivePatterns: z.array(z.string()).default([])
98
- }).default({});
98
+ }).prefault({});
99
99
  var DeepScanConfigSchema = z.object({
100
100
  version: z.string().default("1.0"),
101
101
  scanners: ScannersSchema,
@@ -161,12 +161,12 @@ import { fileURLToPath } from "url";
161
161
  import { dirname, resolve } from "path";
162
162
  import yaml from "js-yaml";
163
163
  function resolveBuiltInPath(filename) {
164
- const __filename = fileURLToPath(import.meta.url);
165
- const __dirname = dirname(__filename);
164
+ const __filename2 = fileURLToPath(import.meta.url);
165
+ const __dirname2 = dirname(__filename2);
166
166
  const searchPaths = [
167
- resolve(__dirname, `../../rules/built-in/${filename}`),
167
+ resolve(__dirname2, `../../rules/built-in/${filename}`),
168
168
  // from dist/bin/
169
- resolve(__dirname, `../rules/built-in/${filename}`),
169
+ resolve(__dirname2, `../rules/built-in/${filename}`),
170
170
  // from dist/
171
171
  resolve(process.cwd(), `rules/built-in/${filename}`)
172
172
  // in dev mode
@@ -458,10 +458,10 @@ import { dirname as dirname2, resolve as resolve3 } from "path";
458
458
  import { fileURLToPath as fileURLToPath2 } from "url";
459
459
  function readPackageVersion() {
460
460
  try {
461
- const __dirname = dirname2(fileURLToPath2(import.meta.url));
461
+ const __dirname2 = dirname2(fileURLToPath2(import.meta.url));
462
462
  const candidates = [
463
- resolve3(__dirname, "../package.json"),
464
- resolve3(__dirname, "../../package.json"),
463
+ resolve3(__dirname2, "../package.json"),
464
+ resolve3(__dirname2, "../../package.json"),
465
465
  resolve3(process.cwd(), "package.json")
466
466
  ];
467
467
  for (const candidate of candidates) {
@@ -1484,9 +1484,20 @@ ${finding.context ? `**Context:** This code is in a ${finding.context.type} cont
1484
1484
 
1485
1485
  // src/core/ast-parser.ts
1486
1486
  import { Parser, Language } from "web-tree-sitter";
1487
- import { resolve as resolve5, join as join2 } from "path";
1487
+ import { resolve as resolve5, join as join2, dirname as dirname3 } from "path";
1488
+ import { fileURLToPath as fileURLToPath3 } from "url";
1488
1489
  import { existsSync as existsSync4 } from "fs";
1489
1490
  import { consola as consola4 } from "consola";
1491
+ var __filename = fileURLToPath3(import.meta.url);
1492
+ var __dirname = dirname3(__filename);
1493
+ var PACKAGE_ROOT_CANDIDATES = [
1494
+ resolve5(__dirname, ".."),
1495
+ // from dist/
1496
+ resolve5(__dirname, "../.."),
1497
+ // from dist/bin/ or src/core/
1498
+ resolve5(__dirname, "../../..")
1499
+ // from src/core/ -> repo root
1500
+ ];
1490
1501
  var LANGUAGE_GRAMMAR_MAP = {
1491
1502
  javascript: "tree-sitter-javascript",
1492
1503
  typescript: "tree-sitter-typescript",
@@ -1654,6 +1665,11 @@ var ASTParser = class {
1654
1665
  resolve5("node_modules", grammarName, wasmFileName),
1655
1666
  resolve5("node_modules", grammarName, `${language}.wasm`),
1656
1667
  resolve5("node_modules", grammarName, "wasm", wasmFileName),
1668
+ ...PACKAGE_ROOT_CANDIDATES.flatMap((root) => [
1669
+ resolve5(root, "node_modules", grammarName, wasmFileName),
1670
+ resolve5(root, "node_modules", grammarName, `${language}.wasm`),
1671
+ resolve5(root, "node_modules", grammarName, "wasm", wasmFileName)
1672
+ ]),
1657
1673
  join2(GRAMMAR_CACHE_DIR, wasmFileName)
1658
1674
  ];
1659
1675
  for (const p of possiblePaths) {
@@ -1780,7 +1796,7 @@ function filterSuppressedFindings(findings, fileContent) {
1780
1796
  // src/core/cache.ts
1781
1797
  import { readFileSync as readFileSync6, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2, existsSync as existsSync5, rmSync } from "fs";
1782
1798
  import { createHash } from "crypto";
1783
- import { resolve as resolve6, dirname as dirname3 } from "path";
1799
+ import { resolve as resolve6, dirname as dirname4 } from "path";
1784
1800
  import { consola as consola5 } from "consola";
1785
1801
  var ScanCache = class {
1786
1802
  cachePath;
@@ -1865,7 +1881,7 @@ var ScanCache = class {
1865
1881
  save() {
1866
1882
  if (!this.enabled || !this.dirty) return;
1867
1883
  try {
1868
- const dir = dirname3(this.cachePath);
1884
+ const dir = dirname4(this.cachePath);
1869
1885
  if (!existsSync5(dir)) {
1870
1886
  mkdirSync2(dir, { recursive: true });
1871
1887
  }
@@ -2157,7 +2173,7 @@ function generateFingerprint(ruleId, filePath, line, snippet) {
2157
2173
 
2158
2174
  // src/core/baseline.ts
2159
2175
  import { existsSync as existsSync6, mkdirSync as mkdirSync3, readFileSync as readFileSync7, writeFileSync as writeFileSync3 } from "fs";
2160
- import { dirname as dirname4 } from "path";
2176
+ import { dirname as dirname5 } from "path";
2161
2177
  function loadBaseline(filePath) {
2162
2178
  if (!existsSync6(filePath)) {
2163
2179
  throw new Error(`Baseline file not found: ${filePath}`);
@@ -2184,7 +2200,7 @@ function saveBaseline(filePath, findings) {
2184
2200
  count: fingerprints.length,
2185
2201
  fingerprints
2186
2202
  };
2187
- const dir = dirname4(filePath);
2203
+ const dir = dirname5(filePath);
2188
2204
  if (dir && !existsSync6(dir)) {
2189
2205
  mkdirSync3(dir, { recursive: true });
2190
2206
  }
@@ -2228,7 +2244,7 @@ function applyBaseline(result, baselineFingerprints) {
2228
2244
 
2229
2245
  // src/config/loader.ts
2230
2246
  import { readFileSync as readFileSync8, existsSync as existsSync7 } from "fs";
2231
- import { resolve as resolve8, dirname as dirname5 } from "path";
2247
+ import { resolve as resolve8, dirname as dirname6 } from "path";
2232
2248
  import yaml3 from "js-yaml";
2233
2249
  import { consola as consola7 } from "consola";
2234
2250
  var CONFIG_FILES = [
@@ -2296,7 +2312,7 @@ function findConfigFile(startDir) {
2296
2312
  return filePath;
2297
2313
  }
2298
2314
  }
2299
- const parentDir = dirname5(currentDir);
2315
+ const parentDir = dirname6(currentDir);
2300
2316
  if (parentDir === currentDir) break;
2301
2317
  currentDir = parentDir;
2302
2318
  }
@@ -2430,7 +2446,7 @@ import chalk from "chalk";
2430
2446
 
2431
2447
  // src/reporters/base-reporter.ts
2432
2448
  import { writeFileSync as writeFileSync4, mkdirSync as mkdirSync4, existsSync as existsSync8 } from "fs";
2433
- import { dirname as dirname6 } from "path";
2449
+ import { dirname as dirname7 } from "path";
2434
2450
  var BaseReporter = class {
2435
2451
  /**
2436
2452
  * Write the generated report to the specified file path.
@@ -2447,7 +2463,7 @@ var BaseReporter = class {
2447
2463
  * if necessary.
2448
2464
  */
2449
2465
  ensureDirectoryExists(filePath) {
2450
- const dir = dirname6(filePath);
2466
+ const dir = dirname7(filePath);
2451
2467
  if (!existsSync8(dir)) {
2452
2468
  mkdirSync4(dir, { recursive: true });
2453
2469
  }
@@ -10323,7 +10339,7 @@ var QualityScanner = class {
10323
10339
  import { resolve as resolve10 } from "path";
10324
10340
 
10325
10341
  // src/scanners/cve/parsers/package-parser.ts
10326
- import { basename as basename2, dirname as dirname7, extname as extname3, join as join3, resolve as resolve9 } from "path";
10342
+ import { basename as basename2, dirname as dirname8, extname as extname3, join as join3, resolve as resolve9 } from "path";
10327
10343
  import { existsSync as existsSync9, readFileSync as readFileSync9 } from "fs";
10328
10344
  import yaml4 from "js-yaml";
10329
10345
  function normalizePkgName(name, ecosystem) {
@@ -10354,23 +10370,36 @@ function findCoveringLockfile(manifestPath) {
10354
10370
  if (!candidates) return null;
10355
10371
  const hasDirSep = /[\\/]/.test(manifestPath);
10356
10372
  const maxLevels = hasDirSep ? 4 : 0;
10357
- let currentDir = dirname7(resolve9(manifestPath));
10373
+ let currentDir = dirname8(resolve9(manifestPath));
10358
10374
  for (let level = 0; level <= maxLevels; level++) {
10359
10375
  for (const candidate of candidates) {
10360
10376
  const lockPath = join3(currentDir, candidate);
10361
10377
  if (existsSync9(lockPath)) {
10362
- return { lockPath, lockType: candidate.toLowerCase() };
10378
+ return { lockPath, lockType: candidate.toLowerCase(), isParent: level > 0 };
10363
10379
  }
10364
10380
  }
10365
10381
  if (existsSync9(join3(currentDir, ".git"))) {
10366
10382
  break;
10367
10383
  }
10368
- const parent = dirname7(currentDir);
10384
+ const parent = dirname8(currentDir);
10369
10385
  if (parent === currentDir) break;
10370
10386
  currentDir = parent;
10371
10387
  }
10372
10388
  return null;
10373
10389
  }
10390
+ function isNpmWorkspaceRoot(dir) {
10391
+ if (existsSync9(join3(dir, "pnpm-workspace.yaml"))) {
10392
+ return true;
10393
+ }
10394
+ const rootPkgPath = join3(dir, "package.json");
10395
+ if (!existsSync9(rootPkgPath)) return false;
10396
+ try {
10397
+ const pkg = JSON.parse(readFileSync9(rootPkgPath, "utf-8"));
10398
+ return Boolean(pkg && typeof pkg === "object" && pkg.workspaces);
10399
+ } catch {
10400
+ return false;
10401
+ }
10402
+ }
10374
10403
  function loadLockfileMap(lockPath, ecosystem) {
10375
10404
  const lockedVersions = /* @__PURE__ */ new Map();
10376
10405
  let lockDeps = [];
@@ -10450,16 +10479,36 @@ function parseDependencies(content, filePath) {
10450
10479
  }
10451
10480
  function parsePackageJson(content, filePath) {
10452
10481
  const deps = [];
10482
+ let pkg;
10483
+ try {
10484
+ pkg = JSON.parse(content);
10485
+ } catch {
10486
+ return deps;
10487
+ }
10488
+ if (!pkg || typeof pkg !== "object") return deps;
10453
10489
  let hasLockfile = false;
10454
10490
  let lockedVersions = /* @__PURE__ */ new Map();
10455
10491
  let lockDeps = [];
10456
10492
  if (filePath) {
10457
10493
  const coveringLock = findCoveringLockfile(filePath);
10458
10494
  if (coveringLock) {
10459
- hasLockfile = true;
10460
10495
  const loaded = loadLockfileMap(coveringLock.lockPath, "npm");
10461
- lockedVersions = loaded.lockedVersions;
10462
- lockDeps = loaded.lockDeps;
10496
+ const declaredNames = [];
10497
+ for (const section of ["dependencies", "devDependencies"]) {
10498
+ const entries = pkg[section];
10499
+ if (entries && typeof entries === "object") {
10500
+ declaredNames.push(...Object.keys(entries));
10501
+ }
10502
+ }
10503
+ const matchedCount = declaredNames.filter(
10504
+ (name) => loaded.lockedVersions.has(normalizePkgName(name, "npm"))
10505
+ ).length;
10506
+ const applies = !coveringLock.isParent || declaredNames.length === 0 || matchedCount > 0 || isNpmWorkspaceRoot(dirname8(coveringLock.lockPath));
10507
+ if (applies) {
10508
+ hasLockfile = true;
10509
+ lockedVersions = loaded.lockedVersions;
10510
+ lockDeps = loaded.lockDeps;
10511
+ }
10463
10512
  }
10464
10513
  }
10465
10514
  const seen = /* @__PURE__ */ new Set();
@@ -10471,33 +10520,29 @@ function parsePackageJson(content, filePath) {
10471
10520
  deps.push(dep);
10472
10521
  }
10473
10522
  };
10474
- try {
10475
- const pkg = JSON.parse(content);
10476
- for (const [section, isDev] of [["dependencies", false], ["devDependencies", true]]) {
10477
- const entries = pkg[section];
10478
- if (!entries || typeof entries !== "object") continue;
10479
- for (const [name, version] of Object.entries(entries)) {
10480
- if (hasLockfile) {
10481
- const locked = lockedVersions.get(normalizePkgName(name, "npm"));
10482
- if (locked) {
10483
- addDep({ name, version: locked, ecosystem: "npm", isDev, isDirect: true });
10484
- }
10485
- } else {
10486
- const cleaned = cleanVersion(String(version));
10487
- if (isValidResolvedVersion(cleaned)) {
10488
- addDep({ name, version: cleaned, ecosystem: "npm", isDev, isDirect: true });
10489
- }
10523
+ for (const [section, isDev] of [["dependencies", false], ["devDependencies", true]]) {
10524
+ const entries = pkg[section];
10525
+ if (!entries || typeof entries !== "object") continue;
10526
+ for (const [name, version] of Object.entries(entries)) {
10527
+ if (hasLockfile) {
10528
+ const locked = lockedVersions.get(normalizePkgName(name, "npm"));
10529
+ if (locked) {
10530
+ addDep({ name, version: locked, ecosystem: "npm", isDev, isDirect: true });
10531
+ }
10532
+ } else {
10533
+ const cleaned = cleanVersion(String(version));
10534
+ if (isValidResolvedVersion(cleaned)) {
10535
+ addDep({ name, version: cleaned, ecosystem: "npm", isDev, isDirect: true });
10490
10536
  }
10491
10537
  }
10492
10538
  }
10493
- if (hasLockfile) {
10494
- for (const td of lockDeps) {
10495
- if (!td.isDev) {
10496
- addDep({ ...td, isDirect: td.isDirect ?? false });
10497
- }
10539
+ }
10540
+ if (hasLockfile) {
10541
+ for (const td of lockDeps) {
10542
+ if (!td.isDev) {
10543
+ addDep({ ...td, isDirect: td.isDirect ?? false });
10498
10544
  }
10499
10545
  }
10500
- } catch {
10501
10546
  }
10502
10547
  return deps;
10503
10548
  }
@@ -11740,4 +11785,4 @@ export {
11740
11785
  QualityScanner,
11741
11786
  CVEScanner
11742
11787
  };
11743
- //# sourceMappingURL=chunk-KITQQYNW.js.map
11788
+ //# sourceMappingURL=chunk-4TWV5TES.js.map