@dailephd/my-dev-kit-lab 0.2.0 → 0.2.2
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/LICENSE +21 -0
- package/README.md +35 -22
- package/dist/scripts/security/resolveToolRoot.js +16 -0
- package/dist/scripts/security/runCodeql.js +2 -1
- package/dist/scripts/security/runDependencyChecks.js +2 -1
- package/dist/scripts/security/runPackageChecks.js +2 -1
- package/dist/scripts/security/runSemgrep.js +2 -1
- package/dist/scripts/security/validate.js +70 -30
- package/dist/src/core/localProjectTarget.js +4 -0
- package/dist/src/core/runMeasuredCommand.js +10 -6
- package/dist/src/securityValidation/attackScenarios/attackProfile.js +20 -0
- package/dist/src/securityValidation/attackScenarios/attackResult.js +37 -0
- package/dist/src/securityValidation/attackScenarios/attackRunner.js +153 -0
- package/dist/src/securityValidation/attackScenarios/attackScenario.js +21 -0
- package/dist/src/securityValidation/attackScenarios/boundedSourceScan.js +100 -0
- package/dist/src/securityValidation/attackScenarios/exploitEvidence.js +69 -0
- package/dist/src/securityValidation/attackScenarios/payloadCorpus.js +0 -0
- package/dist/src/securityValidation/attackScenarios/profiles/localToolProfile.js +10 -0
- package/dist/src/securityValidation/attackScenarios/profiles/nodeCliPackageProfile.js +20 -0
- package/dist/src/securityValidation/attackScenarios/profiles/npmPackageProfile.js +10 -0
- package/dist/src/securityValidation/attackScenarios/reportSchemaGuard.js +41 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/configInjectionScenario.js +144 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/networkAssumptionScenario.js +129 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/outputBoundaryScenario.js +69 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/packageBoundaryScenario.js +118 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/pathTraversalScenario.js +119 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/reportPoisoningScenario.js +176 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/secretLeakageScenario.js +143 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/subprocessInjectionScenario.js +117 -0
- package/dist/src/securityValidation/attackScenarios/scenarios/targetSandboxScenario.js +118 -0
- package/dist/src/securityValidation/attackScenarios/targetSnapshot.js +70 -0
- package/dist/src/securityValidation/packageChecks/forbiddenPackageContents.js +4 -1
- package/dist/src/securityValidation/report/renderSecurityReport.js +153 -12
- package/dist/src/securityValidation/types.js +7 -0
- package/dist/src/securityValidation/validate/cliOptions.js +182 -0
- package/dist/src/securityValidation/validate/runCliSecuritySuiteCheck.js +124 -0
- package/dist/src/securityValidation/validate/runSecurityValidation.js +135 -67
- package/dist/src/securityValidation/validate/verdict.js +147 -0
- package/package.json +14 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dailephd LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
# my-dev-kit-lab
|
|
2
2
|
|
|
3
|
-
my-dev-kit-lab is the experiment, evidence, reporting, and
|
|
3
|
+
my-dev-kit-lab is the experiment, evidence, reporting, security-validation, and future audit companion for my-dev-kit. It runs reproducible experiments that test whether my-dev-kit's graph-guided retrieval helps coding-agent workflows, collects metrics, renders reports, generates plots, captures screenshots, builds gallery outputs, and performs automated CLI/package security validation.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The current package is v0.2.2, release-prepared but not yet published to npm. Its generic experiment-plugin framework was introduced in v0.2.0. The first plugin is `context-strategy-comparison`, which preserves the existing raw-full-file vs my-dev-kit-guided workflow through the plugin runner.
|
|
6
|
+
|
|
7
|
+
my-dev-kit is most useful when the repository is larger than the task. It helps coding agents work with large codebases through reusable structural indexing, graph-guided retrieval, targeted source slices, and auditable context selection. Results are scoped evidence; the project does not claim that my-dev-kit always saves tokens.
|
|
6
8
|
|
|
7
9
|
**my-dev-kit** is the repo indexing and graph-guided retrieval engine.
|
|
8
10
|
**my-dev-kit-lab** is the separate lab layer that feeds it benchmark inputs and records evaluation outputs.
|
|
@@ -29,7 +31,7 @@ As of v0.2.0, my-dev-kit-lab also exposes a generic experiment-plugin framework
|
|
|
29
31
|
- First experiment plugin: `context-strategy-comparison`
|
|
30
32
|
- Target-aware experiment execution for local projects via `experiment:run -- --target <path>`
|
|
31
33
|
- Plugin-aware JSON and HTML reports with plugin, target, variant, metric, artifact, warning, skip, and failure metadata
|
|
32
|
-
- Security validation framework: dependency audit, package tarball inspection, CLI adversarial tests, static scans (CodeQL/Semgrep), bounded fuzz smoke, and
|
|
34
|
+
- Security validation framework: dependency audit, package tarball inspection, CLI adversarial tests, static scans (CodeQL/Semgrep), bounded fuzz smoke, attack-scenario checks, and structured verdict/report output — runnable against any local project via `security:validate --target <path>`
|
|
33
35
|
|
|
34
36
|
---
|
|
35
37
|
|
|
@@ -37,19 +39,14 @@ As of v0.2.0, my-dev-kit-lab also exposes a generic experiment-plugin framework
|
|
|
37
39
|
|
|
38
40
|
```mermaid
|
|
39
41
|
flowchart TD
|
|
40
|
-
A[
|
|
41
|
-
B --> C[
|
|
42
|
-
C --> D[Controlled
|
|
43
|
-
D --> E[
|
|
44
|
-
E --> F[
|
|
45
|
-
E --> G[
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
G --> J[SVG Charts]
|
|
49
|
-
H --> K[Demo Artifacts]
|
|
50
|
-
I --> L[Gallery]
|
|
51
|
-
J --> L
|
|
52
|
-
K --> L
|
|
42
|
+
A[scripts/experiments] --> B[Experiment plugin registry + runner]
|
|
43
|
+
B --> C[context-strategy-comparison]
|
|
44
|
+
C --> D[Controlled experiment foundations]
|
|
45
|
+
D --> E[Plugin + legacy artifacts]
|
|
46
|
+
E --> F[Plugin-aware reports]
|
|
47
|
+
E --> G[Plots / screenshots / gallery]
|
|
48
|
+
H[scripts/security] --> I[Automated security validation]
|
|
49
|
+
I --> J[Security reports + verdict]
|
|
53
50
|
```
|
|
54
51
|
|
|
55
52
|
---
|
|
@@ -205,7 +202,7 @@ See [docs/METRICS.md](docs/METRICS.md) for full metric definitions.
|
|
|
205
202
|
|
|
206
203
|
## Current baseline release positioning
|
|
207
204
|
|
|
208
|
-
my-dev-kit-lab is at a working baseline. The raw-vs-indexed experiment pipeline is fully implemented and produces reproducible artifacts. Real-agent campaign support exists for Codex and Claude. v0.2.
|
|
205
|
+
my-dev-kit-lab is at a working baseline. The raw-vs-indexed experiment pipeline is fully implemented and produces reproducible artifacts. Real-agent campaign support exists for Codex and Claude. The current package version is `v0.2.2`, which implements the automated security-validation fortification work described below and has passed pre-release readiness and cross-platform validation. `v0.2.2` has not yet been published to npm.
|
|
209
206
|
|
|
210
207
|
---
|
|
211
208
|
|
|
@@ -223,7 +220,7 @@ This is not a web application pentest framework. **my-dev-kit** is a local CLI/p
|
|
|
223
220
|
- database-free
|
|
224
221
|
- safe to run on local repositories
|
|
225
222
|
|
|
226
|
-
The
|
|
223
|
+
The automated validation gate is implemented. It combines static scans, dependency/package checks, adversarial CLI tests, bounded fuzz smoke tests, and attack-scenario checks with structured text/JSON reports and a four-category verdict.
|
|
227
224
|
|
|
228
225
|
### Security commands
|
|
229
226
|
|
|
@@ -233,13 +230,23 @@ The release gate is implemented as of v0.1.4. It combines static scans, dependen
|
|
|
233
230
|
| `npm run security:package` | npm pack --dry-run, forbidden content detection |
|
|
234
231
|
| `npm run security:codeql` | CodeQL CLI availability check; skipped gracefully when absent |
|
|
235
232
|
| `npm run security:semgrep` | Semgrep scan via local binary or npx; skipped gracefully when both absent |
|
|
236
|
-
| `npm run test:security` |
|
|
233
|
+
| `npm run test:security` | Automated security and adversarial CLI tests (path traversal, read-only boundaries, malformed artifacts, JSON safety, and related checks) |
|
|
237
234
|
| `npm run test:fuzz:smoke` | 9 bounded fuzz targets, seeded PRNG, completes in under 1 second |
|
|
238
|
-
| `npm run security:validate` |
|
|
235
|
+
| `npm run security:validate` | Runs selected security checks, applies profile-aware defaults when requested, and writes text/JSON reports according to `--format` |
|
|
236
|
+
|
|
237
|
+
CodeQL, Semgrep, and OSV-Scanner are optional. When unavailable locally, they are recorded as `skipped` in the report, not as passed. That can lead to `ready except optional manual checks`; it does not silently turn missing tooling into a clean pass.
|
|
238
|
+
|
|
239
|
+
Each security command can validate my-dev-kit-lab itself or another local project via `--target <path>`. When `--target` is omitted, the framework performs self-validation. Target projects are inspected in place: their source files are not modified by default, generated artifacts stay under `reports/security/` unless `--out` is used, and external-target reports identify the tool root, target root, target package metadata, target git metadata, command cwd, exit code, and stdout/stderr summaries.
|
|
240
|
+
|
|
241
|
+
`security:validate` supports `--checks`, `--profile`, `--format`, `--fail-on`, `--out`, and `--report-prefix`. The no-flag path remains backward compatible and still runs the classic implemented check groups: `deps`, `package`, `static`, `cli-adversarial`, and `fuzz`. Supplying `--profile` without `--checks` swaps in that profile's default checks; supplying explicit `--checks` always wins over profile defaults.
|
|
242
|
+
|
|
243
|
+
The current attack-scenario checks cover boundary, subprocess, secrets, and network assumptions. They are automated adversarial checks, not a manual pentest. `verdictImpact` metadata from each registered scenario drives blocker categorization in report reasoning, and narrowed `--checks` runs are labeled as scoped rather than described as a full release gate.
|
|
239
244
|
|
|
240
|
-
|
|
245
|
+
JSON report poisoning/config-injection checks use a baseline-diff schema guard so legitimate additive JSON fields do not fail the guard while payload-created trusted top-level fields still do. Text reports are sanitized to strip ANSI/control-byte payloads before rendering.
|
|
241
246
|
|
|
242
|
-
|
|
247
|
+
Known limits remain intentionally explicit: secret scanning is bounded rather than exhaustive, the network/local-first check is a bounded static assumption check rather than proof of runtime isolation, package-boundary severity is still result-level rather than per-evidence-item, and profile-specific scenario behavior is limited to profile-based scenario selection/default checks.
|
|
248
|
+
|
|
249
|
+
For external-target validation, `security:validate` reads the target `package.json`, detects `scripts.test:security`, and runs `npm run test:security` in the target project root when that script exists. This behavior is validated both from the source checkout and from an installed packed tarball because published-package execution differs from local source execution.
|
|
243
250
|
|
|
244
251
|
Generated security reports under `reports/security/` are excluded from git by default. They are produced locally or in CI as release-gate evidence and are not committed to the repository.
|
|
245
252
|
|
|
@@ -247,6 +254,12 @@ See [docs/COMMANDS.md](docs/COMMANDS.md) for full command options and [docs/secu
|
|
|
247
254
|
|
|
248
255
|
---
|
|
249
256
|
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
MIT License. See [LICENSE](LICENSE) for the full text.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
250
263
|
## Support
|
|
251
264
|
|
|
252
265
|
my-dev-kit-lab is an independent project by dailephd LLC, developed and maintained by Dai Le.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
export function resolveToolRoot(moduleUrl) {
|
|
5
|
+
let current = path.dirname(fileURLToPath(moduleUrl));
|
|
6
|
+
while (true) {
|
|
7
|
+
if (fs.existsSync(path.join(current, "package.json"))) {
|
|
8
|
+
return current;
|
|
9
|
+
}
|
|
10
|
+
const parent = path.dirname(current);
|
|
11
|
+
if (parent === current) {
|
|
12
|
+
return process.cwd();
|
|
13
|
+
}
|
|
14
|
+
current = parent;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { runCodeqlCheck } from "../../src/securityValidation/staticScans/codeql.js";
|
|
3
3
|
import { resolveValidationTarget } from "../../src/securityValidation/validate/resolveTarget.js";
|
|
4
|
+
import { resolveToolRoot } from "./resolveToolRoot.js";
|
|
4
5
|
const rawArgs = process.argv.slice(2);
|
|
5
6
|
const args = parseArgs(rawArgs);
|
|
6
|
-
const toolRoot =
|
|
7
|
+
const toolRoot = resolveToolRoot(import.meta.url);
|
|
7
8
|
let targetRoot;
|
|
8
9
|
try {
|
|
9
10
|
const target = resolveValidationTarget(args.target, toolRoot);
|
|
@@ -3,9 +3,10 @@ import path from "node:path";
|
|
|
3
3
|
import { runDependencyChecks } from "../../src/securityValidation/index.js";
|
|
4
4
|
import { DEFAULT_SECURITY_CONFIG } from "../../src/securityValidation/index.js";
|
|
5
5
|
import { resolveValidationTarget } from "../../src/securityValidation/validate/resolveTarget.js";
|
|
6
|
+
import { resolveToolRoot } from "./resolveToolRoot.js";
|
|
6
7
|
const rawArgs = process.argv.slice(2);
|
|
7
8
|
const args = parseArgs(rawArgs);
|
|
8
|
-
const toolRoot =
|
|
9
|
+
const toolRoot = resolveToolRoot(import.meta.url);
|
|
9
10
|
let targetRoot;
|
|
10
11
|
try {
|
|
11
12
|
const target = resolveValidationTarget(args.target, toolRoot);
|
|
@@ -3,9 +3,10 @@ import path from "node:path";
|
|
|
3
3
|
import { runPackageChecks } from "../../src/securityValidation/index.js";
|
|
4
4
|
import { DEFAULT_SECURITY_CONFIG } from "../../src/securityValidation/index.js";
|
|
5
5
|
import { resolveValidationTarget } from "../../src/securityValidation/validate/resolveTarget.js";
|
|
6
|
+
import { resolveToolRoot } from "./resolveToolRoot.js";
|
|
6
7
|
const rawArgs = process.argv.slice(2);
|
|
7
8
|
const args = parseArgs(rawArgs);
|
|
8
|
-
const toolRoot =
|
|
9
|
+
const toolRoot = resolveToolRoot(import.meta.url);
|
|
9
10
|
let targetRoot;
|
|
10
11
|
try {
|
|
11
12
|
const target = resolveValidationTarget(args.target, toolRoot);
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { runSemgrepCheck } from "../../src/securityValidation/staticScans/semgrep.js";
|
|
4
4
|
import { resolveValidationTarget } from "../../src/securityValidation/validate/resolveTarget.js";
|
|
5
|
+
import { resolveToolRoot } from "./resolveToolRoot.js";
|
|
5
6
|
const rawArgs = process.argv.slice(2);
|
|
6
7
|
const args = parseArgs(rawArgs);
|
|
7
|
-
const toolRoot =
|
|
8
|
+
const toolRoot = resolveToolRoot(import.meta.url);
|
|
8
9
|
let targetRoot;
|
|
9
10
|
try {
|
|
10
11
|
const target = resolveValidationTarget(args.target, toolRoot);
|
|
@@ -4,10 +4,34 @@ import fs from "node:fs";
|
|
|
4
4
|
import { runSecurityValidation } from "../../src/securityValidation/validate/runSecurityValidation.js";
|
|
5
5
|
import { resolveValidationTarget, reportFilenamePrefix } from "../../src/securityValidation/validate/resolveTarget.js";
|
|
6
6
|
import { renderTextReport, renderJsonReport } from "../../src/securityValidation/report/renderSecurityReport.js";
|
|
7
|
+
import { parseSecurityValidateArgs, normalizeSecurityValidateConfig, applyProfileDefaultChecksIfApplicable, } from "../../src/securityValidation/validate/cliOptions.js";
|
|
8
|
+
import { resolveAttackProfile } from "../../src/securityValidation/attackScenarios/attackProfile.js";
|
|
9
|
+
import { findingsBreachFailOnThreshold } from "../../src/securityValidation/validate/verdict.js";
|
|
10
|
+
import { resolveToolRoot } from "./resolveToolRoot.js";
|
|
11
|
+
const USAGE = "Usage: npm run security:validate -- [--target <path>] [--out <dir>] [--report-prefix <name>] " +
|
|
12
|
+
"[--checks deps,package,static,cli-adversarial,fuzz,boundary,subprocess,secrets,network] " +
|
|
13
|
+
"[--profile node-cli-package|local-tool|npm-package] [--format text,json] [--fail-on blocker|high|medium|low]";
|
|
7
14
|
// Parse CLI arguments from process.argv (after the node/tsx and script path).
|
|
8
15
|
const rawArgs = process.argv.slice(2);
|
|
9
|
-
const
|
|
10
|
-
|
|
16
|
+
const toolRoot = resolveToolRoot(import.meta.url);
|
|
17
|
+
let args;
|
|
18
|
+
let config;
|
|
19
|
+
try {
|
|
20
|
+
args = parseSecurityValidateArgs(rawArgs);
|
|
21
|
+
config = normalizeSecurityValidateConfig(args, toolRoot);
|
|
22
|
+
// v0.2.2 Batch 5: --profile with no --checks uses that profile's declared
|
|
23
|
+
// default checks. No-op unless the user passed --profile without --checks
|
|
24
|
+
// (see applyProfileDefaultChecksIfApplicable's guard) — the true no-flag
|
|
25
|
+
// case and any explicit --checks case are always unaffected.
|
|
26
|
+
config = applyProfileDefaultChecksIfApplicable(config, resolveAttackProfile(config.profile).defaultCheckIds);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
30
|
+
console.error(`\nERROR: ${msg}`);
|
|
31
|
+
console.error(USAGE);
|
|
32
|
+
process.exitCode = 1;
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
11
35
|
// Resolve and validate target early so we can fail fast with a clean error.
|
|
12
36
|
let target;
|
|
13
37
|
try {
|
|
@@ -16,7 +40,7 @@ try {
|
|
|
16
40
|
catch (err) {
|
|
17
41
|
const msg = err instanceof Error ? err.message : String(err);
|
|
18
42
|
console.error(`\nERROR: ${msg}`);
|
|
19
|
-
console.error(
|
|
43
|
+
console.error(USAGE);
|
|
20
44
|
process.exitCode = 1;
|
|
21
45
|
process.exit(1);
|
|
22
46
|
}
|
|
@@ -32,13 +56,30 @@ if (!target.isSelf) {
|
|
|
32
56
|
else {
|
|
33
57
|
console.log(`Mode : self-validation`);
|
|
34
58
|
}
|
|
59
|
+
if (!config.checksWereDefault) {
|
|
60
|
+
console.log(`Checks : ${config.checks.join(", ")}`);
|
|
61
|
+
}
|
|
62
|
+
if (config.plannedChecksRequested.length > 0) {
|
|
63
|
+
console.log(`Note : ${config.plannedChecksRequested.join(", ")} are routed through the attack-scenario framework rather than the classic check-group runners. Review the attack-scenario section in the report for their concrete results.`);
|
|
64
|
+
}
|
|
35
65
|
console.log("");
|
|
36
66
|
const summary = await runSecurityValidation({
|
|
37
67
|
cwd: toolRoot,
|
|
38
68
|
targetPath: args.target,
|
|
39
69
|
fuzzIterations: parseInt(process.env["FUZZ_ITERATIONS"] ?? "50", 10),
|
|
40
70
|
fuzzSeed: parseInt(process.env["FUZZ_SEED"] ?? "0xDEADBEEF", 16),
|
|
71
|
+
// Full selection (implemented + planned/attack-scenario ids) — the runner
|
|
72
|
+
// gates both implemented check groups and attack-scenario checks off the
|
|
73
|
+
// same selectedChecks set.
|
|
74
|
+
selectedChecks: config.checks,
|
|
75
|
+
profile: config.profile,
|
|
41
76
|
});
|
|
77
|
+
// v0.2.2 Batch 5: --fail-on breach is additive to (never a substitute for)
|
|
78
|
+
// the existing verdict-based exit decision below — it can only escalate
|
|
79
|
+
// exit 0 to exit 1 (e.g. --fail-on medium/low catching minor/informational
|
|
80
|
+
// findings the verdict policy doesn't already treat as blocking), never
|
|
81
|
+
// downgrade an existing blocker.
|
|
82
|
+
const failOnBreached = findingsBreachFailOnThreshold(summary.findings, config.failOnThreshold);
|
|
42
83
|
// Build report object
|
|
43
84
|
const report = {
|
|
44
85
|
metadata: {
|
|
@@ -54,19 +95,25 @@ const report = {
|
|
|
54
95
|
isSelf: summary.isSelf,
|
|
55
96
|
generatedAt: summary.finishedAt,
|
|
56
97
|
totalDurationMs: new Date(summary.finishedAt).getTime() - new Date(summary.startedAt).getTime(),
|
|
98
|
+
profile: config.profile,
|
|
99
|
+
selectedChecks: config.checks,
|
|
100
|
+
failOnThreshold: config.failOnThreshold,
|
|
101
|
+
formats: config.formats,
|
|
102
|
+
failOnBreached,
|
|
103
|
+
isFullReleaseGate: summary.isFullReleaseGate,
|
|
57
104
|
},
|
|
58
105
|
sections: [],
|
|
59
106
|
allChecks: summary.checks,
|
|
60
107
|
allFindings: summary.findings,
|
|
61
108
|
verdict: summary.verdict,
|
|
62
109
|
recommendedNextStep: summary.recommendedNextStep,
|
|
110
|
+
attackResults: summary.attackResults,
|
|
111
|
+
verdictReasonSummary: summary.verdictReasonSummary,
|
|
63
112
|
};
|
|
64
113
|
const textReport = renderTextReport(report);
|
|
65
114
|
const jsonReport = renderJsonReport(report);
|
|
66
115
|
// Determine output directory
|
|
67
|
-
const reportsDir =
|
|
68
|
-
? path.resolve(args.out)
|
|
69
|
-
: path.join(toolRoot, "reports", "security");
|
|
116
|
+
const reportsDir = config.out;
|
|
70
117
|
if (!fs.existsSync(reportsDir)) {
|
|
71
118
|
fs.mkdirSync(reportsDir, { recursive: true });
|
|
72
119
|
}
|
|
@@ -74,14 +121,22 @@ if (!fs.existsSync(reportsDir)) {
|
|
|
74
121
|
const prefix = args.reportPrefix ?? reportFilenamePrefix(target);
|
|
75
122
|
const txtPath = path.join(reportsDir, `${prefix}-security-validation.txt`);
|
|
76
123
|
const jsonPath = path.join(reportsDir, `${prefix}-security-validation.json`);
|
|
77
|
-
|
|
78
|
-
|
|
124
|
+
const writtenPaths = [];
|
|
125
|
+
if (config.formats.includes("text")) {
|
|
126
|
+
fs.writeFileSync(txtPath, textReport, "utf8");
|
|
127
|
+
writtenPaths.push(txtPath);
|
|
128
|
+
}
|
|
129
|
+
if (config.formats.includes("json")) {
|
|
130
|
+
fs.writeFileSync(jsonPath, jsonReport, "utf8");
|
|
131
|
+
writtenPaths.push(jsonPath);
|
|
132
|
+
}
|
|
79
133
|
// Print report to stdout
|
|
80
134
|
console.log(textReport);
|
|
81
135
|
console.log(`\nReports written:`);
|
|
82
|
-
|
|
83
|
-
console.log(` ${
|
|
84
|
-
|
|
136
|
+
for (const p of writtenPaths) {
|
|
137
|
+
console.log(` ${p}`);
|
|
138
|
+
}
|
|
139
|
+
// Exit code based on verdict, escalated (never downgraded) by --fail-on.
|
|
85
140
|
const blockerExists = summary.verdict === "not-ready-security-blocker-remains";
|
|
86
141
|
const inconclusive = summary.verdict === "inconclusive-audit-environment-incomplete";
|
|
87
142
|
if (blockerExists) {
|
|
@@ -92,26 +147,11 @@ else if (inconclusive) {
|
|
|
92
147
|
console.warn("\nExit 2 — audit environment incomplete.");
|
|
93
148
|
process.exitCode = 2;
|
|
94
149
|
}
|
|
150
|
+
else if (failOnBreached) {
|
|
151
|
+
console.error(`\nExit 1 — --fail-on ${config.failOnThreshold} threshold breached.`);
|
|
152
|
+
process.exitCode = 1;
|
|
153
|
+
}
|
|
95
154
|
else {
|
|
96
155
|
console.log("\nExit 0 — validation completed.");
|
|
97
156
|
process.exitCode = 0;
|
|
98
157
|
}
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
// Argument parser
|
|
101
|
-
// ---------------------------------------------------------------------------
|
|
102
|
-
function parseArgs(argv) {
|
|
103
|
-
const result = {};
|
|
104
|
-
for (let i = 0; i < argv.length; i++) {
|
|
105
|
-
const arg = argv[i];
|
|
106
|
-
if ((arg === "--target" || arg === "-t") && i + 1 < argv.length) {
|
|
107
|
-
result.target = argv[++i];
|
|
108
|
-
}
|
|
109
|
-
else if (arg === "--out" && i + 1 < argv.length) {
|
|
110
|
-
result.out = argv[++i];
|
|
111
|
-
}
|
|
112
|
-
else if (arg === "--report-prefix" && i + 1 < argv.length) {
|
|
113
|
-
result.reportPrefix = argv[++i];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
@@ -27,6 +27,7 @@ export function resolveLocalProjectTarget(targetPathArg, toolRoot) {
|
|
|
27
27
|
packageName: packageMetadata.packageName,
|
|
28
28
|
packageVersion: packageMetadata.packageVersion,
|
|
29
29
|
hasPackageJson: packageMetadata.hasPackageJson,
|
|
30
|
+
hasSecurityTestScript: packageMetadata.hasSecurityTestScript,
|
|
30
31
|
hasLockfile: hasLockfile(resolvedTargetRoot),
|
|
31
32
|
...readGitMetadata(resolvedTargetRoot),
|
|
32
33
|
isSelf: resolvedTargetRoot === resolvedToolRoot,
|
|
@@ -36,10 +37,12 @@ function readPackageMetadata(targetRoot) {
|
|
|
36
37
|
try {
|
|
37
38
|
const pkgRaw = fs.readFileSync(path.join(targetRoot, "package.json"), "utf8");
|
|
38
39
|
const pkg = JSON.parse(pkgRaw);
|
|
40
|
+
const testSecurityScript = pkg.scripts && typeof pkg.scripts["test:security"] === "string";
|
|
39
41
|
return {
|
|
40
42
|
hasPackageJson: true,
|
|
41
43
|
packageName: typeof pkg.name === "string" ? pkg.name : null,
|
|
42
44
|
packageVersion: typeof pkg.version === "string" ? pkg.version : null,
|
|
45
|
+
hasSecurityTestScript: Boolean(testSecurityScript),
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
48
|
catch {
|
|
@@ -47,6 +50,7 @@ function readPackageMetadata(targetRoot) {
|
|
|
47
50
|
hasPackageJson: false,
|
|
48
51
|
packageName: null,
|
|
49
52
|
packageVersion: null,
|
|
53
|
+
hasSecurityTestScript: false,
|
|
50
54
|
};
|
|
51
55
|
}
|
|
52
56
|
}
|
|
@@ -70,9 +70,9 @@ export async function runMeasuredCommand(options) {
|
|
|
70
70
|
resolvedCommand: resolution
|
|
71
71
|
};
|
|
72
72
|
void Promise.all([
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
writeArtifact(stdoutPath, stdout),
|
|
74
|
+
writeArtifact(stderrPath, stderr),
|
|
75
|
+
writeArtifact(telemetryPath, JSON.stringify(measured, null, 2))
|
|
76
76
|
]).then(() => resolve(measured));
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
@@ -98,8 +98,8 @@ export async function runMeasuredCommand(options) {
|
|
|
98
98
|
}
|
|
99
99
|
const endedAt = new Date().toISOString();
|
|
100
100
|
const durationMs = Date.now() - started;
|
|
101
|
-
await
|
|
102
|
-
await
|
|
101
|
+
await writeArtifact(stdoutPath, stdout);
|
|
102
|
+
await writeArtifact(stderrPath, stderr);
|
|
103
103
|
const measured = {
|
|
104
104
|
commandId: options.commandId,
|
|
105
105
|
commandString: options.commandString,
|
|
@@ -119,12 +119,16 @@ export async function runMeasuredCommand(options) {
|
|
|
119
119
|
error: spawnError,
|
|
120
120
|
resolvedCommand: resolution
|
|
121
121
|
};
|
|
122
|
-
await
|
|
122
|
+
await writeArtifact(telemetryPath, JSON.stringify(measured, null, 2));
|
|
123
123
|
resolve(measured);
|
|
124
124
|
});
|
|
125
125
|
});
|
|
126
126
|
return result;
|
|
127
127
|
}
|
|
128
|
+
async function writeArtifact(filePath, value) {
|
|
129
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
130
|
+
await writeFile(filePath, value, "utf8");
|
|
131
|
+
}
|
|
128
132
|
function killProcessTree(pid) {
|
|
129
133
|
if (!pid) {
|
|
130
134
|
return;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SECURITY_PROFILE_IDS } from "../validate/cliOptions.js";
|
|
2
|
+
import { NODE_CLI_PACKAGE_PROFILE } from "./profiles/nodeCliPackageProfile.js";
|
|
3
|
+
import { LOCAL_TOOL_PROFILE } from "./profiles/localToolProfile.js";
|
|
4
|
+
import { NPM_PACKAGE_PROFILE } from "./profiles/npmPackageProfile.js";
|
|
5
|
+
const PROFILE_REGISTRY = {
|
|
6
|
+
"node-cli-package": NODE_CLI_PACKAGE_PROFILE,
|
|
7
|
+
"local-tool": LOCAL_TOOL_PROFILE,
|
|
8
|
+
"npm-package": NPM_PACKAGE_PROFILE,
|
|
9
|
+
};
|
|
10
|
+
// Resolves a profile id to its definition. Throws a clean, descriptive Error
|
|
11
|
+
// for unknown ids (mirrors Batch 1's --profile validation error style).
|
|
12
|
+
export function resolveAttackProfile(id) {
|
|
13
|
+
if (!SECURITY_PROFILE_IDS.includes(id)) {
|
|
14
|
+
throw new Error(`Unknown security profile: "${id}". Valid values are: ${SECURITY_PROFILE_IDS.join(", ")}.`);
|
|
15
|
+
}
|
|
16
|
+
return PROFILE_REGISTRY[id];
|
|
17
|
+
}
|
|
18
|
+
export function listAttackProfiles() {
|
|
19
|
+
return SECURITY_PROFILE_IDS.map((id) => PROFILE_REGISTRY[id]);
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Bridges an AttackResult into the existing SecurityCheckResult shape so it
|
|
2
|
+
// can flow through the existing verdict/report pipeline without redesigning
|
|
3
|
+
// either. "blocked" (scenario crashed) maps to a failed check with severity
|
|
4
|
+
// bumped to at least "major" so a scenario crash is never silently invisible.
|
|
5
|
+
export function toSecurityCheckResult(result) {
|
|
6
|
+
const now = new Date().toISOString();
|
|
7
|
+
const status = result.status === "blocked" ? "failed" : result.status;
|
|
8
|
+
const severity = result.status === "blocked" && result.severity === "skipped" ? "major" : result.severity;
|
|
9
|
+
return {
|
|
10
|
+
id: result.scenarioId,
|
|
11
|
+
name: result.scenarioTitle,
|
|
12
|
+
category: result.category,
|
|
13
|
+
status,
|
|
14
|
+
severity,
|
|
15
|
+
startedAt: now,
|
|
16
|
+
finishedAt: now,
|
|
17
|
+
durationMs: 0,
|
|
18
|
+
findings: result.status === "failed" || result.status === "blocked"
|
|
19
|
+
? [
|
|
20
|
+
{
|
|
21
|
+
id: `${result.scenarioId}-finding`,
|
|
22
|
+
title: result.scenarioTitle,
|
|
23
|
+
severity,
|
|
24
|
+
category: result.category,
|
|
25
|
+
description: result.status === "blocked"
|
|
26
|
+
? `Scenario execution error: ${result.errorSummary ?? "unknown error"}`
|
|
27
|
+
: `Attack scenario detected unsafe behavior for check group '${result.checkId}'.`,
|
|
28
|
+
evidence: result.evidence.map((e) => e.redactedPreview).filter(Boolean).join(" | ") || undefined,
|
|
29
|
+
recommendation: result.recommendation,
|
|
30
|
+
releaseImpact: severity === "blocker" ? "Must fix before release" : "Should fix before release",
|
|
31
|
+
},
|
|
32
|
+
]
|
|
33
|
+
: [],
|
|
34
|
+
skippedReason: result.skippedReason,
|
|
35
|
+
verdictImpact: result.verdictImpact,
|
|
36
|
+
};
|
|
37
|
+
}
|