@openai/codex-security 0.1.21 → 0.1.24
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 +549 -1
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -1
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/server.mjs.br.part-001 +0 -0
- package/_bundled_plugin/references/config-preflight.md +2 -30
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/final-report.md +1 -1
- package/_bundled_plugin/references/finding-detail-fields.md +5 -10
- package/_bundled_plugin/references/sarif-adapter.md +1 -1
- package/_bundled_plugin/references/scan-contract.md +10 -0
- package/_bundled_plugin/scripts/config_preflight.py +2 -8
- package/_bundled_plugin/scripts/deep_scan_workbench.py +6 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +115 -76
- package/_bundled_plugin/scripts/finding_preview.py +22 -4
- package/_bundled_plugin/scripts/generate_in_scope_files.py +29 -9
- package/_bundled_plugin/scripts/generate_rank_input.py +1 -5
- package/_bundled_plugin/scripts/rank_preview.py +1 -0
- package/_bundled_plugin/scripts/report_projection.py +8 -14
- package/_bundled_plugin/scripts/validate_scan_contract.py +1 -3
- package/_bundled_plugin/scripts/windows_scan_local_files.py +90 -6
- package/_bundled_plugin/scripts/workbench_cli.py +27 -1
- package/_bundled_plugin/scripts/workbench_dashboard.py +138 -0
- package/_bundled_plugin/scripts/workbench_db.py +110 -539
- package/_bundled_plugin/scripts/workbench_finding_index.py +42 -24
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +208 -0
- package/_bundled_plugin/scripts/workbench_findings.py +221 -0
- package/_bundled_plugin/scripts/workbench_native_indexes.py +1 -2
- package/_bundled_plugin/scripts/workbench_publication.py +520 -0
- package/_bundled_plugin/scripts/workbench_remediation.py +37 -0
- package/_bundled_plugin/scripts/workbench_saved_results.py +322 -89
- package/_bundled_plugin/scripts/workbench_scan_history.py +1 -2
- package/_bundled_plugin/scripts/workbench_scan_usage.py +9 -33
- package/_bundled_plugin/scripts/workbench_schema.py +276 -58
- package/_bundled_plugin/scripts/workbench_target.py +30 -6
- package/_bundled_plugin/scripts/workbench_validation.py +1 -5
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +1 -5
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +6 -1
- package/_bundled_plugin/skills/track-findings/SKILL.md +2 -0
- package/dist/api.d.ts +5 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +135 -27
- package/dist/api.js.map +1 -1
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +158 -62
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.js +5 -1
- package/dist/cloud-publish.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +9 -0
- package/dist/contract.js.map +1 -1
- package/dist/custom-publish.d.ts +22 -0
- package/dist/custom-publish.d.ts.map +1 -0
- package/dist/custom-publish.js +47 -0
- package/dist/custom-publish.js.map +1 -0
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts +16 -0
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -0
- package/dist/deduplication/checkpointed-review.js +76 -0
- package/dist/deduplication/checkpointed-review.js.map +1 -0
- package/dist/deduplication/codex-review.d.ts +21 -0
- package/dist/deduplication/codex-review.d.ts.map +1 -0
- package/dist/deduplication/codex-review.js +252 -0
- package/dist/deduplication/codex-review.js.map +1 -0
- package/dist/deduplication/deduplication-prompts.d.ts +8 -0
- package/dist/deduplication/deduplication-prompts.d.ts.map +1 -0
- package/dist/deduplication/deduplication-prompts.js +35 -0
- package/dist/deduplication/deduplication-prompts.js.map +1 -0
- package/dist/deduplication/deduplication-reviewer.d.ts +46 -0
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -0
- package/dist/deduplication/deduplication-reviewer.js +105 -0
- package/dist/deduplication/deduplication-reviewer.js.map +1 -0
- package/dist/deduplication/deduplication.d.ts +6 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -0
- package/dist/deduplication/deduplication.js +85 -0
- package/dist/deduplication/deduplication.js.map +1 -0
- package/dist/deduplication/scan.d.ts +16 -0
- package/dist/deduplication/scan.d.ts.map +1 -0
- package/dist/deduplication/scan.js +101 -0
- package/dist/deduplication/scan.js.map +1 -0
- package/dist/deep-progress.d.ts +21 -0
- package/dist/deep-progress.d.ts.map +1 -0
- package/dist/deep-progress.js +108 -0
- package/dist/deep-progress.js.map +1 -0
- package/dist/finding-dedupe-groups.d.ts +7 -0
- package/dist/finding-dedupe-groups.d.ts.map +1 -0
- package/dist/finding-dedupe-groups.js +2 -0
- package/dist/finding-dedupe-groups.js.map +1 -0
- package/dist/finding-retrieval.d.ts +13 -0
- package/dist/finding-retrieval.d.ts.map +1 -0
- package/dist/finding-retrieval.js +2 -0
- package/dist/finding-retrieval.js.map +1 -0
- package/dist/finding-workflow.d.ts +53 -0
- package/dist/finding-workflow.d.ts.map +1 -0
- package/dist/finding-workflow.js +117 -0
- package/dist/finding-workflow.js.map +1 -0
- package/dist/findings-client.d.ts +15 -0
- package/dist/findings-client.d.ts.map +1 -0
- package/dist/findings-client.js +60 -0
- package/dist/findings-client.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/publication.js +28 -40
- package/dist/publication.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +119 -13
- package/dist/runtime.js.map +1 -1
- package/dist/saved-scan.d.ts +15 -0
- package/dist/saved-scan.d.ts.map +1 -0
- package/dist/saved-scan.js +68 -0
- package/dist/saved-scan.js.map +1 -0
- package/dist/scan-activity.d.ts.map +1 -1
- package/dist/scan-activity.js +12 -2
- package/dist/scan-activity.js.map +1 -1
- package/dist/scan-comparison.d.ts +3 -2
- package/dist/scan-comparison.d.ts.map +1 -1
- package/dist/scan-comparison.js +1 -1
- package/dist/scan-comparison.js.map +1 -1
- package/dist/server/dashboard/THIRD_PARTY_NOTICES.txt +276 -0
- package/dist/server/dashboard/app.css +2 -0
- package/dist/server/dashboard/app.js +66 -0
- package/dist/server/dashboard/index.html +18 -0
- package/dist/server/dashboard-types.d.ts +45 -0
- package/dist/server/dashboard-types.d.ts.map +1 -0
- package/dist/server/dashboard-types.js +2 -0
- package/dist/server/dashboard-types.js.map +1 -0
- package/dist/server/dashboard.d.ts +6 -0
- package/dist/server/dashboard.d.ts.map +1 -0
- package/dist/server/dashboard.js +45 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/server/embeddings.d.ts +16 -0
- package/dist/server/embeddings.d.ts.map +1 -0
- package/dist/server/embeddings.js +114 -0
- package/dist/server/embeddings.js.map +1 -0
- package/dist/server/errors.d.ts +5 -0
- package/dist/server/errors.d.ts.map +1 -0
- package/dist/server/errors.js +8 -0
- package/dist/server/errors.js.map +1 -0
- package/dist/server/findings-service.d.ts +20 -0
- package/dist/server/findings-service.d.ts.map +1 -0
- package/dist/server/findings-service.js +31 -0
- package/dist/server/findings-service.js.map +1 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +6 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes.d.ts +6 -0
- package/dist/server/routes.d.ts.map +1 -0
- package/dist/server/routes.js +86 -0
- package/dist/server/routes.js.map +1 -0
- package/dist/server/serve.d.ts +2 -0
- package/dist/server/serve.d.ts.map +1 -0
- package/dist/server/serve.js +28 -0
- package/dist/server/serve.js.map +1 -0
- package/dist/server/server.d.ts +10 -0
- package/dist/server/server.d.ts.map +1 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/sqlite-store.d.ts +22 -0
- package/dist/server/sqlite-store.d.ts.map +1 -0
- package/dist/server/sqlite-store.js +82 -0
- package/dist/server/sqlite-store.js.map +1 -0
- package/dist/server/storage.d.ts +32 -0
- package/dist/server/storage.d.ts.map +1 -0
- package/dist/server/storage.js +2 -0
- package/dist/server/storage.js.map +1 -0
- package/dist/server/validation.d.ts +17 -0
- package/dist/server/validation.d.ts.map +1 -0
- package/dist/server/validation.js +53 -0
- package/dist/server/validation.js.map +1 -0
- package/dist/trusted-executable.d.ts.map +1 -1
- package/dist/trusted-executable.js +2 -1
- package/dist/trusted-executable.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +17 -5
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
const DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;
|
|
2
|
+
export class DeepScanProgressTracker {
|
|
3
|
+
#options;
|
|
4
|
+
#timer = null;
|
|
5
|
+
#pending = null;
|
|
6
|
+
#abortController = null;
|
|
7
|
+
#lastProgress = null;
|
|
8
|
+
#stopped = false;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.#options = options;
|
|
11
|
+
}
|
|
12
|
+
start() {
|
|
13
|
+
if (this.#timer !== null || this.#stopped)
|
|
14
|
+
return;
|
|
15
|
+
const poll = () => {
|
|
16
|
+
void this.refresh().catch((error) => {
|
|
17
|
+
this.#options.onError?.(error);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
this.#timer = setInterval(poll, this.#options.pollIntervalMs ?? DEEP_PROGRESS_POLL_INTERVAL_MS);
|
|
21
|
+
this.#timer.unref();
|
|
22
|
+
poll();
|
|
23
|
+
}
|
|
24
|
+
async refresh() {
|
|
25
|
+
if (this.#stopped)
|
|
26
|
+
return;
|
|
27
|
+
if (this.#pending !== null)
|
|
28
|
+
return await this.#pending;
|
|
29
|
+
const abortController = new AbortController();
|
|
30
|
+
this.#abortController = abortController;
|
|
31
|
+
let update = null;
|
|
32
|
+
update = (async () => {
|
|
33
|
+
try {
|
|
34
|
+
const progress = deepScanProgressFromWorkbench(await this.#options.read(abortController.signal));
|
|
35
|
+
if (this.#stopped ||
|
|
36
|
+
abortController.signal.aborted ||
|
|
37
|
+
progress === null ||
|
|
38
|
+
sameProgress(progress, this.#lastProgress)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.#lastProgress = progress;
|
|
42
|
+
this.#options.onProgress(progress);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (this.#stopped || abortController.signal.aborted)
|
|
46
|
+
return;
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
if (this.#pending === update)
|
|
51
|
+
this.#pending = null;
|
|
52
|
+
if (this.#abortController === abortController) {
|
|
53
|
+
this.#abortController = null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
})();
|
|
57
|
+
this.#pending = update;
|
|
58
|
+
await update;
|
|
59
|
+
}
|
|
60
|
+
stop() {
|
|
61
|
+
if (this.#stopped)
|
|
62
|
+
return;
|
|
63
|
+
this.#stopped = true;
|
|
64
|
+
if (this.#timer !== null) {
|
|
65
|
+
clearInterval(this.#timer);
|
|
66
|
+
this.#timer = null;
|
|
67
|
+
}
|
|
68
|
+
this.#abortController?.abort();
|
|
69
|
+
this.#abortController = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function deepScanProgressFromWorkbench(result) {
|
|
73
|
+
if (!isRecord(result) || !isRecord(result["scan"]))
|
|
74
|
+
return null;
|
|
75
|
+
const progress = result["scan"]["progress"];
|
|
76
|
+
if (!isRecord(progress))
|
|
77
|
+
return null;
|
|
78
|
+
const independentReviews = progress["independentReviews"];
|
|
79
|
+
if (independentReviews === undefined)
|
|
80
|
+
return null;
|
|
81
|
+
if (!isRecord(independentReviews) ||
|
|
82
|
+
!isCount(independentReviews["completed"]) ||
|
|
83
|
+
!isCount(independentReviews["active"]) ||
|
|
84
|
+
!isPositiveCount(independentReviews["maximum"])) {
|
|
85
|
+
throw new Error("Codex Security workbench returned invalid Deep Scan progress.");
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
completed: independentReviews["completed"],
|
|
89
|
+
active: independentReviews["active"],
|
|
90
|
+
maximum: independentReviews["maximum"],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function sameProgress(left, right) {
|
|
94
|
+
return (right !== null &&
|
|
95
|
+
left.completed === right.completed &&
|
|
96
|
+
left.active === right.active &&
|
|
97
|
+
left.maximum === right.maximum);
|
|
98
|
+
}
|
|
99
|
+
function isCount(value) {
|
|
100
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
101
|
+
}
|
|
102
|
+
function isPositiveCount(value) {
|
|
103
|
+
return isCount(value) && value > 0;
|
|
104
|
+
}
|
|
105
|
+
function isRecord(value) {
|
|
106
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=deep-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-progress.js","sourceRoot":"","sources":["../src/deep-progress.ts"],"names":[],"mappings":"AAaA,MAAM,8BAA8B,GAAG,KAAK,CAAC;AAE7C,MAAM,OAAO,uBAAuB;IACzB,QAAQ,CAAiC;IAClD,MAAM,GAA0B,IAAI,CAAC;IACrC,QAAQ,GAAyB,IAAI,CAAC;IACtC,gBAAgB,GAA2B,IAAI,CAAC;IAChD,aAAa,GAA4B,IAAI,CAAC;IAC9C,QAAQ,GAAG,KAAK,CAAC;IAEjB,YAAmB,OAAuC;QACxD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK;QACV,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAClD,MAAM,IAAI,GAAG,GAAG,EAAE;YAChB,KAAK,IAAI,CAAC,OAAO,E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O,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACzC,CAAC,OAAO,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC,eAAe,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC,EAC/C,CAAC;QACD,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;IACJ,CAAC;IACD,OAAO;QACL,SAAS,EAAE,kBAAkB,CAAC,WAAW,CAAC;QAC1C,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC;QACpC,OAAO,EAAE,kBAAkB,CAAC,SAAS,CAAC;KACvC,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAAsB,EACtB,KAA8B;IAE9B,OAAO,CACL,KAAK,KAAK,IAAI;QACd,IAAI,CAAC,SAAS,KAAK,KAAK,CAAC,SAAS;QAClC,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM;QAC5B,IAAI,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,CAC/B,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC7B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAChF,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC","sourcesContent":["export interface DeepScanProgress {\n completed: number;\n active: number;\n maximum: number;\n}\n\ninterface DeepScanProgressTrackerOptions {\n read: (signal: AbortSignal) => Promise<unknown>;\n onProgress: (progress: DeepScanProgress) => void;\n onError?: (error: unknown) => void;\n pollIntervalMs?: number;\n}\n\nconst DEEP_PROGRESS_POLL_INTERVAL_MS = 5_000;\n\nexport class DeepScanProgressTracker {\n readonly #options: DeepScanProgressTrackerOptions;\n #timer: NodeJS.Timeout | null = null;\n #pending: Promise<void> | null = null;\n #abortController: AbortController | null = null;\n #lastProgress: DeepScanProgress | null = null;\n #stopped = false;\n\n public constructor(options: DeepScanProgressTrackerOptions) {\n this.#options = options;\n }\n\n public start(): void {\n if (this.#timer !== null || this.#stopped) return;\n const poll = () => {\n void this.refresh().catch((error: unknown) => {\n this.#options.onError?.(error);\n });\n };\n this.#timer = setInterval(\n poll,\n this.#options.pollIntervalMs ?? DEEP_PROGRESS_POLL_INTERVAL_MS,\n );\n this.#timer.unref();\n poll();\n }\n\n public async refresh(): Promise<void> {\n if (this.#stopped) return;\n if (this.#pending !== null) return await this.#pending;\n const abortController = new AbortController();\n this.#abortController = abortController;\n let update: Promise<void> | null = null;\n update = (async () => {\n try {\n const progress = deepScanProgressFromWorkbench(\n await this.#options.read(abortController.signal),\n );\n if (\n this.#stopped ||\n abortController.signal.aborted ||\n progress === null ||\n sameProgress(progress, this.#lastProgress)\n ) {\n return;\n }\n this.#lastProgress = progress;\n this.#options.onProgress(progress);\n } catch (error) {\n if (this.#stopped || abortController.signal.aborted) return;\n throw error;\n } finally {\n if (this.#pending === update) this.#pending = null;\n if (this.#abortController === abortController) {\n this.#abortController = null;\n }\n }\n })();\n this.#pending = update;\n await update;\n }\n\n public stop(): void {\n if (this.#stopped) return;\n this.#stopped = true;\n if (this.#timer !== null) {\n clearInterval(this.#timer);\n this.#timer = null;\n }\n this.#abortController?.abort();\n this.#abortController = null;\n }\n}\n\nexport function deepScanProgressFromWorkbench(\n result: unknown,\n): DeepScanProgress | null {\n if (!isRecord(result) || !isRecord(result[\"scan\"])) return null;\n const progress = result[\"scan\"][\"progress\"];\n if (!isRecord(progress)) return null;\n const independentReviews = progress[\"independentReviews\"];\n if (independentReviews === undefined) return null;\n if (\n !isRecord(independentReviews) ||\n !isCount(independentReviews[\"completed\"]) ||\n !isCount(independentReviews[\"active\"]) ||\n !isPositiveCount(independentReviews[\"maximum\"])\n ) {\n throw new Error(\n \"Codex Security workbench returned invalid Deep Scan progress.\",\n );\n }\n return {\n completed: independentReviews[\"completed\"],\n active: independentReviews[\"active\"],\n maximum: independentReviews[\"maximum\"],\n };\n}\n\nfunction sameProgress(\n left: DeepScanProgress,\n right: DeepScanProgress | null,\n): boolean {\n return (\n right !== null &&\n left.completed === right.completed &&\n left.active === right.active &&\n left.maximum === right.maximum\n );\n}\n\nfunction isCount(value: unknown): value is number {\n return typeof value === \"number\" && Number.isSafeInteger(value) && value >= 0;\n}\n\nfunction isPositiveCount(value: unknown): value is number {\n return isCount(value) && value > 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === \"object\" && !Array.isArray(value);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finding-dedupe-groups.d.ts","sourceRoot":"","sources":["../src/finding-dedupe-groups.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finding-dedupe-groups.js","sourceRoot":"","sources":["../src/finding-dedupe-groups.ts"],"names":[],"mappings":"","sourcesContent":["/** A reviewed set of duplicate findings. A finding may belong to multiple groups. */\nexport interface FindingDedupeGroup {\n groupId: string;\n findingIds: string[];\n createdAt: string;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Finding } from "./models.js";
|
|
2
|
+
export type FindingSearchScope = {
|
|
3
|
+
repositoryId: string;
|
|
4
|
+
allRepositories?: never;
|
|
5
|
+
} | {
|
|
6
|
+
allRepositories: true;
|
|
7
|
+
repositoryId?: never;
|
|
8
|
+
};
|
|
9
|
+
export interface FindingNeighborhood {
|
|
10
|
+
finding: Finding;
|
|
11
|
+
potentialDuplicates: Finding[];
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=finding-retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finding-retrieval.d.ts","sourceRoot":"","sources":["../src/finding-retrieval.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,MAAM,kBAAkB,GAC1B;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,KAAK,CAAA;CAAE,GACjD;IAAE,eAAe,EAAE,IAAI,CAAC;IAAC,YAAY,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEpD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB,EAAE,OAAO,EAAE,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finding-retrieval.js","sourceRoot":"","sources":["../src/finding-retrieval.ts"],"names":[],"mappings":"","sourcesContent":["import type { Finding } from \"./models.js\";\n\nexport type FindingSearchScope =\n | { repositoryId: string; allRepositories?: never }\n | { allRepositories: true; repositoryId?: never };\n\nexport interface FindingNeighborhood {\n finding: Finding;\n potentialDuplicates: Finding[];\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { JsonObject } from "./config.js";
|
|
2
|
+
import type { FindingSearchScope } from "./finding-retrieval.js";
|
|
3
|
+
import { runWorkbench } from "./runtime.js";
|
|
4
|
+
export type WorkflowStage = "scan" | "publish" | "dedupe";
|
|
5
|
+
export interface WorkflowBinding {
|
|
6
|
+
repositoryPath?: string;
|
|
7
|
+
scanRequestDigest?: string;
|
|
8
|
+
scanId?: string;
|
|
9
|
+
scanDir?: string;
|
|
10
|
+
artifactDigest?: string;
|
|
11
|
+
destination?: string;
|
|
12
|
+
scope?: FindingSearchScope;
|
|
13
|
+
}
|
|
14
|
+
export interface WorkflowState extends WorkflowBinding {
|
|
15
|
+
id: string;
|
|
16
|
+
stages: Record<WorkflowStage, {
|
|
17
|
+
status: "pending" | "running" | "failed" | "completed";
|
|
18
|
+
result?: unknown;
|
|
19
|
+
error?: string;
|
|
20
|
+
pendingWrite?: {
|
|
21
|
+
groups: string[][];
|
|
22
|
+
};
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
25
|
+
export declare function workflowDigest(value: unknown): string;
|
|
26
|
+
export declare function workflowDestination(url: string): string;
|
|
27
|
+
/** State lives in the workbench database, never in sealed scan artifacts. */
|
|
28
|
+
export declare class FindingWorkflow {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
private readonly environment;
|
|
31
|
+
private readonly workbench;
|
|
32
|
+
private readonly pythonPath?;
|
|
33
|
+
private options?;
|
|
34
|
+
constructor(id: string, environment?: NodeJS.ProcessEnv, workbench?: typeof runWorkbench, pythonPath?: string | undefined);
|
|
35
|
+
protectArtifacts(scanDir: string): Promise<void>;
|
|
36
|
+
get(): Promise<WorkflowState | null>;
|
|
37
|
+
bind(binding: WorkflowBinding): Promise<WorkflowState>;
|
|
38
|
+
begin(stage: WorkflowStage): Promise<WorkflowState>;
|
|
39
|
+
complete(stage: WorkflowStage, result: unknown): Promise<WorkflowState>;
|
|
40
|
+
fail(stage: WorkflowStage, error: unknown): Promise<void>;
|
|
41
|
+
run<T>(stage: WorkflowStage, operation: () => Promise<T>): Promise<T>;
|
|
42
|
+
registeredScan(scanId: string): Promise<JsonObject>;
|
|
43
|
+
sourceSnapshot(repository: string): Promise<JsonObject>;
|
|
44
|
+
getReview(key: string): Promise<unknown>;
|
|
45
|
+
saveReview(key: string, binding: object, result: unknown): Promise<void>;
|
|
46
|
+
prepareDedupe(result: unknown, pendingWrite: {
|
|
47
|
+
groups: string[][];
|
|
48
|
+
}): Promise<void>;
|
|
49
|
+
private command;
|
|
50
|
+
private request;
|
|
51
|
+
private call;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=finding-workflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finding-workflow.d.ts","sourceRoot":"","sources":["../src/finding-workflow.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAKL,YAAY,EAEb,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,SAAS,GAAG,QAAQ,CAAC;AAC1D,MAAM,WAAW,eAAe;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,kBAAkB,CAAC;CAC5B;AACD,MAAM,WAAW,aAAc,SAAQ,eAAe;IACpD,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CACZ,aAAa,EACb;QACE,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;QACvD,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE;YAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;SAAE,CAAC;KACvC,CACF,CAAC;CACH;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASrD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMvD;AAED,6EAA6E;AAC7E,qBAAa,eAAe;IAIxB,QAAQ,CAAC,EAAE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EAAE;QAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAA;KAAE,GACnC,OAAO,CAAC,IAAI,CAAC;YASF,OAAO;YAKP,OAAO;YAOP,IAAI;CAkBnB"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { isAbsolute, relative, sep } from "node:path";
|
|
3
|
+
import { CodexSecurityError, safeErrorMessage } from "./errors.js";
|
|
4
|
+
import { bundledPluginRoot, canonicalizeModelSafePath, codexSecurityStateDirectory, resolvePluginPython, runWorkbench, } from "./runtime.js";
|
|
5
|
+
export function workflowDigest(value) {
|
|
6
|
+
const json = JSON.stringify(value, (_key, item) => item !== null && typeof item === "object" && !Array.isArray(item)
|
|
7
|
+
? Object.fromEntries(Object.entries(item).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)))
|
|
8
|
+
: item);
|
|
9
|
+
return createHash("sha256").update(json).digest("hex");
|
|
10
|
+
}
|
|
11
|
+
export function workflowDestination(url) {
|
|
12
|
+
const route = "v1/bulk/findings";
|
|
13
|
+
const destination = new URL(route, url.endsWith("/") ? url : `${url}/`);
|
|
14
|
+
destination.username = "";
|
|
15
|
+
destination.password = "";
|
|
16
|
+
return destination.href.slice(0, -route.length);
|
|
17
|
+
}
|
|
18
|
+
/** State lives in the workbench database, never in sealed scan artifacts. */
|
|
19
|
+
export class FindingWorkflow {
|
|
20
|
+
id;
|
|
21
|
+
environment;
|
|
22
|
+
workbench;
|
|
23
|
+
pythonPath;
|
|
24
|
+
options;
|
|
25
|
+
constructor(id, environment = process.env, workbench = runWorkbench, pythonPath) {
|
|
26
|
+
this.id = id;
|
|
27
|
+
this.environment = environment;
|
|
28
|
+
this.workbench = workbench;
|
|
29
|
+
this.pythonPath = pythonPath;
|
|
30
|
+
if (!id.trim())
|
|
31
|
+
throw new CodexSecurityError("workflowId must be a nonempty string.");
|
|
32
|
+
}
|
|
33
|
+
async protectArtifacts(scanDir) {
|
|
34
|
+
const path = relative(await canonicalizeModelSafePath(scanDir), await canonicalizeModelSafePath(codexSecurityStateDirectory(this.environment)));
|
|
35
|
+
if (path === "" ||
|
|
36
|
+
(!isAbsolute(path) && path !== ".." && !path.startsWith(`..${sep}`))) {
|
|
37
|
+
throw new CodexSecurityError("Workflow state must be outside the sealed scan artifacts.");
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async get() {
|
|
41
|
+
return (await this.command({ action: "get" }));
|
|
42
|
+
}
|
|
43
|
+
async bind(binding) {
|
|
44
|
+
return (await this.command({ action: "bind", binding }));
|
|
45
|
+
}
|
|
46
|
+
async begin(stage) {
|
|
47
|
+
return (await this.command({ action: "begin", stage }));
|
|
48
|
+
}
|
|
49
|
+
async complete(stage, result) {
|
|
50
|
+
return (await this.command({ action: "complete", stage, result }));
|
|
51
|
+
}
|
|
52
|
+
async fail(stage, error) {
|
|
53
|
+
await this.command({
|
|
54
|
+
action: "fail",
|
|
55
|
+
stage,
|
|
56
|
+
error: safeErrorMessage(error),
|
|
57
|
+
}).catch(() => undefined);
|
|
58
|
+
}
|
|
59
|
+
async run(stage, operation) {
|
|
60
|
+
const state = await this.begin(stage);
|
|
61
|
+
if (state.stages[stage].status === "completed")
|
|
62
|
+
return state.stages[stage].result;
|
|
63
|
+
try {
|
|
64
|
+
const result = await operation();
|
|
65
|
+
await this.complete(stage, result);
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
await this.fail(stage, error);
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async registeredScan(scanId) {
|
|
74
|
+
const context = await this.call(["get-scan", "--scan-id", scanId]);
|
|
75
|
+
return context["scan"];
|
|
76
|
+
}
|
|
77
|
+
async sourceSnapshot(repository) {
|
|
78
|
+
return (await this.request({ action: "source", repository }))["source"];
|
|
79
|
+
}
|
|
80
|
+
async getReview(key) {
|
|
81
|
+
return (await this.request({ action: "get-review", key }))["review"];
|
|
82
|
+
}
|
|
83
|
+
async saveReview(key, binding, result) {
|
|
84
|
+
await this.request({ action: "save-review", key, binding, result });
|
|
85
|
+
}
|
|
86
|
+
async prepareDedupe(result, pendingWrite) {
|
|
87
|
+
await this.command({
|
|
88
|
+
action: "prepare-dedupe",
|
|
89
|
+
stage: "dedupe",
|
|
90
|
+
result,
|
|
91
|
+
pendingWrite,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async command(payload) {
|
|
95
|
+
const result = await this.request(payload);
|
|
96
|
+
return result["workflow"];
|
|
97
|
+
}
|
|
98
|
+
async request(payload) {
|
|
99
|
+
return await this.call(["finding-workflow"], JSON.stringify({ id: this.id, ...payload }));
|
|
100
|
+
}
|
|
101
|
+
async call(args, input) {
|
|
102
|
+
this.options ??= (async () => ({
|
|
103
|
+
pluginRoot: await bundledPluginRoot(),
|
|
104
|
+
python: await resolvePluginPython({
|
|
105
|
+
environment: this.environment,
|
|
106
|
+
configuredPath: this.pythonPath,
|
|
107
|
+
}),
|
|
108
|
+
environment: {
|
|
109
|
+
...this.environment,
|
|
110
|
+
CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(this.environment),
|
|
111
|
+
},
|
|
112
|
+
failureMessage: "Could not save or resume the findings workflow",
|
|
113
|
+
}))();
|
|
114
|
+
return await this.workbench(await this.options, args, input);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=finding-workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finding-workflow.js","sourceRoot":"","sources":["../src/finding-workflow.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,2BAA2B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AiB,EAAE;YACrC,MAAM,EAAE,MAAM,mBAAmB,CAAC;gBAChC,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,cAAc,EAAE,IAAI,CAAC,UAAU;aAChC,CAAC;YACF,WAAW,EAAE;gBACX,GAAG,IAAI,CAAC,WAAW;gBACnB,wBAAwB,EAAE,2BAA2B,CAAC,IAAI,CAAC,WAAW,CAAC;aACxE;YACD,cAAc,EAAE,gDAAgD;SACjE,CAAC,CAAC,EAAE,CAAC;QACN,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;CACF","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { isAbsolute, relative, sep } from \"node:path\";\nimport type { JsonObject } from \"./config.js\";\nimport { CodexSecurityError, safeErrorMessage } from \"./errors.js\";\nimport type { FindingSearchScope } from \"./finding-retrieval.js\";\nimport {\n bundledPluginRoot,\n canonicalizeModelSafePath,\n codexSecurityStateDirectory,\n resolvePluginPython,\n runWorkbench,\n type WorkbenchCommandOptions,\n} from \"./runtime.js\";\n\nexport type WorkflowStage = \"scan\" | \"publish\" | \"dedupe\";\nexport interface WorkflowBinding {\n repositoryPath?: string;\n scanRequestDigest?: string;\n scanId?: string;\n scanDir?: string;\n artifactDigest?: string;\n destination?: string;\n scope?: FindingSearchScope;\n}\nexport interface WorkflowState extends WorkflowBinding {\n id: string;\n stages: Record<\n WorkflowStage,\n {\n status: \"pending\" | \"running\" | \"failed\" | \"completed\";\n result?: unknown;\n error?: string;\n pendingWrite?: { groups: string[][] };\n }\n >;\n}\n\nexport function workflowDigest(value: unknown): string {\n const json = JSON.stringify(value, (_key, item: unknown) =>\n item !== null && typeof item === \"object\" && !Array.isArray(item)\n ? Object.fromEntries(\n Object.entries(item).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),\n )\n : item,\n );\n return createHash(\"sha256\").update(json).digest(\"hex\");\n}\n\nexport function workflowDestination(url: string): string {\n const route = \"v1/bulk/findings\";\n const destination = new URL(route, url.endsWith(\"/\") ? url : `${url}/`);\n destination.username = \"\";\n destination.password = \"\";\n return destination.href.slice(0, -route.length);\n}\n\n/** State lives in the workbench database, never in sealed scan artifacts. */\nexport class FindingWorkflow {\n private options?: Promise<WorkbenchCommandOptions>;\n\n constructor(\n readonly id: string,\n private readonly environment: NodeJS.ProcessEnv = process.env,\n private readonly workbench: typeof runWorkbench = runWorkbench,\n private readonly pythonPath?: string,\n ) {\n if (!id.trim())\n throw new CodexSecurityError(\"workflowId must be a nonempty string.\");\n }\n\n async protectArtifacts(scanDir: string): Promise<void> {\n const path = relative(\n await canonicalizeModelSafePath(scanDir),\n await canonicalizeModelSafePath(\n codexSecurityStateDirectory(this.environment),\n ),\n );\n if (\n path === \"\" ||\n (!isAbsolute(path) && path !== \"..\" && !path.startsWith(`..${sep}`))\n ) {\n throw new CodexSecurityError(\n \"Workflow state must be outside the sealed scan artifacts.\",\n );\n }\n }\n\n async get(): Promise<WorkflowState | null> {\n return (await this.command({ action: \"get\" })) as WorkflowState | null;\n }\n\n async bind(binding: WorkflowBinding): Promise<WorkflowState> {\n return (await this.command({ action: \"bind\", binding }))!;\n }\n\n async begin(stage: WorkflowStage): Promise<WorkflowState> {\n return (await this.command({ action: \"begin\", stage }))!;\n }\n\n async complete(\n stage: WorkflowStage,\n result: unknown,\n ): Promise<WorkflowState> {\n return (await this.command({ action: \"complete\", stage, result }))!;\n }\n\n async fail(stage: WorkflowStage, error: unknown): Promise<void> {\n await this.command({\n action: \"fail\",\n stage,\n error: safeErrorMessage(error),\n }).catch(() => undefined);\n }\n\n async run<T>(stage: WorkflowStage, operation: () => Promise<T>): Promise<T> {\n const state = await this.begin(stage);\n if (state.stages[stage].status === \"completed\")\n return state.stages[stage].result as T;\n try {\n const result = await operation();\n await this.complete(stage, result);\n return result;\n } catch (error) {\n await this.fail(stage, error);\n throw error;\n }\n }\n\n async registeredScan(scanId: string): Promise<JsonObject> {\n const context = await this.call([\"get-scan\", \"--scan-id\", scanId]);\n return context[\"scan\"] as JsonObject;\n }\n\n async sourceSnapshot(repository: string): Promise<JsonObject> {\n return (await this.request({ action: \"source\", repository }))[\n \"source\"\n ] as JsonObject;\n }\n\n async getReview(key: string): Promise<unknown> {\n return (await this.request({ action: \"get-review\", key }))[\"review\"];\n }\n\n async saveReview(\n key: string,\n binding: object,\n result: unknown,\n ): Promise<void> {\n await this.request({ action: \"save-review\", key, binding, result });\n }\n\n async prepareDedupe(\n result: unknown,\n pendingWrite: { groups: string[][] },\n ): Promise<void> {\n await this.command({\n action: \"prepare-dedupe\",\n stage: \"dedupe\",\n result,\n pendingWrite,\n });\n }\n\n private async command(payload: object): Promise<WorkflowState | null> {\n const result = await this.request(payload);\n return result[\"workflow\"] as unknown as WorkflowState | null;\n }\n\n private async request(payload: object): Promise<JsonObject> {\n return await this.call(\n [\"finding-workflow\"],\n JSON.stringify({ id: this.id, ...payload }),\n );\n }\n\n private async call(\n args: readonly string[],\n input?: string,\n ): Promise<JsonObject> {\n this.options ??= (async () => ({\n pluginRoot: await bundledPluginRoot(),\n python: await resolvePluginPython({\n environment: this.environment,\n configuredPath: this.pythonPath,\n }),\n environment: {\n ...this.environment,\n CODEX_SECURITY_STATE_DIR: codexSecurityStateDirectory(this.environment),\n },\n failureMessage: \"Could not save or resume the findings workflow\",\n }))();\n return await this.workbench(await this.options, args, input);\n }\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Finding } from "./models.js";
|
|
2
|
+
import type { FindingNeighborhood, FindingSearchScope } from "./finding-retrieval.js";
|
|
3
|
+
export type FindingsRequest = (url: URL, init: RequestInit) => Promise<Response>;
|
|
4
|
+
export declare class FindingsClient {
|
|
5
|
+
private readonly url;
|
|
6
|
+
private readonly signal?;
|
|
7
|
+
private readonly request;
|
|
8
|
+
constructor(url: string, signal?: AbortSignal | undefined, request?: FindingsRequest);
|
|
9
|
+
potentialDuplicates(findingId: string, scope: FindingSearchScope): Promise<FindingNeighborhood>;
|
|
10
|
+
publish(findings: readonly Finding[], repositoryId: string): Promise<string[]>;
|
|
11
|
+
storeDedupeGroups(groups: readonly string[][]): Promise<void>;
|
|
12
|
+
private endpoint;
|
|
13
|
+
private post;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=findings-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findings-client.d.ts","sourceRoot":"","sources":["../src/findings-client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,eAAe,GAAG,CAC5B,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,WAAW,KACd,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEvB,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,WAAW,YAAA,EACpB,OAAO,GAAE,eAAuB;IAG7C,mBAAmB,CACvB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,kBAAkB,GACxB,OAAO,CAAC,mBAAmB,CAAC;IAoBzB,OAAO,CACX,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,EAAE,CAAC;IAmBd,iBAAiB,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnE,OAAO,CAAC,QAAQ;YAIF,IAAI;CAcnB"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { CodexSecurityError } from "./errors.js";
|
|
2
|
+
export class FindingsClient {
|
|
3
|
+
url;
|
|
4
|
+
signal;
|
|
5
|
+
request;
|
|
6
|
+
constructor(url, signal, request = fetch) {
|
|
7
|
+
this.url = url;
|
|
8
|
+
this.signal = signal;
|
|
9
|
+
this.request = request;
|
|
10
|
+
}
|
|
11
|
+
async potentialDuplicates(findingId, scope) {
|
|
12
|
+
const url = this.endpoint(`v1/finding/${encodeURIComponent(findingId)}/potential-duplicates`);
|
|
13
|
+
if (scope.allRepositories === true)
|
|
14
|
+
url.searchParams.set("allRepositories", "true");
|
|
15
|
+
else
|
|
16
|
+
url.searchParams.set("repositoryId", scope.repositoryId);
|
|
17
|
+
const response = await this.request(url, { signal: this.signal });
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
throw new CodexSecurityError(`Potential-duplicates lookup for ${findingId} failed (HTTP ${response.status}).${response.status === 404
|
|
20
|
+
? " Import the finding with its repositoryId through POST /v1/bulk/findings before deduplicating."
|
|
21
|
+
: ""}`);
|
|
22
|
+
}
|
|
23
|
+
return (await response.json());
|
|
24
|
+
}
|
|
25
|
+
async publish(findings, repositoryId) {
|
|
26
|
+
const receipt = await this.post("v1/bulk/findings", {
|
|
27
|
+
findings,
|
|
28
|
+
repositoryId,
|
|
29
|
+
});
|
|
30
|
+
const expected = new Set(findings.map((finding) => finding.findingId));
|
|
31
|
+
if (!Array.isArray(receipt) ||
|
|
32
|
+
receipt.length !== findings.length ||
|
|
33
|
+
new Set(receipt).size !== expected.size ||
|
|
34
|
+
receipt.some((id) => !expected.has(id))) {
|
|
35
|
+
throw new CodexSecurityError("The findings API did not acknowledge all published finding IDs. Check the service before retrying.");
|
|
36
|
+
}
|
|
37
|
+
return receipt;
|
|
38
|
+
}
|
|
39
|
+
async storeDedupeGroups(groups) {
|
|
40
|
+
if (groups.length === 0)
|
|
41
|
+
return;
|
|
42
|
+
await this.post("v1/dedupe-groups", { groups });
|
|
43
|
+
}
|
|
44
|
+
endpoint(path) {
|
|
45
|
+
return new URL(path, this.url.endsWith("/") ? this.url : `${this.url}/`);
|
|
46
|
+
}
|
|
47
|
+
async post(path, body) {
|
|
48
|
+
const response = await this.request(this.endpoint(path), {
|
|
49
|
+
method: "POST",
|
|
50
|
+
headers: { "Content-Type": "application/json" },
|
|
51
|
+
body: JSON.stringify(body),
|
|
52
|
+
signal: this.signal,
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
throw new CodexSecurityError(`Findings API POST /${path} failed (HTTP ${response.status}).`);
|
|
56
|
+
}
|
|
57
|
+
return await response.json();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=findings-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findings-client.js","sourceRoot":"","sources":["../src/findings-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAYjD,MAAM,OAAO,cAAc;IAEN;IACA;IACA;IAHnB,YACmB,GAAW,EACX,MAAoB,EACpB,UAA2B,KAAK;QAFhC,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAc;QACpB,YAAO,GAAP,OAAO,CAAyB;IAChD,CAAC;IAEJ,KAAK,CAAC,mBAAmB,CACvB,SAAiB,EACjB,KAAyB;QAEzB,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CACvB,cAAc,kBAAkB,CAAC,SAAS,CAAC,uBAAuB,CACnE,CAAC;QACF,IAAI,KAAK,CAAC,eAAe,KAAK,IAAI;YAChC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC;;YAC7C,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;QAC9D,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAClE,IAAI,CAAC,QA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IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC;IAC3E,CAAC;IAEO,KAAK,CAAC,IAAI,CAAC,IAAY,EAAE,IAAa;QAC5C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YACvD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAC1B,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,kBAAkB,CAC1B,sBAAsB,IAAI,iBAAiB,QAAQ,CAAC,MAAM,IAAI,CAC/D,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC/B,CAAC;CACF","sourcesContent":["import { CodexSecurityError } from \"./errors.js\";\nimport type { Finding } from \"./models.js\";\nimport type {\n FindingNeighborhood,\n FindingSearchScope,\n} from \"./finding-retrieval.js\";\n\nexport type FindingsRequest = (\n url: URL,\n init: RequestInit,\n) => Promise<Response>;\n\nexport class FindingsClient {\n constructor(\n private readonly url: string,\n private readonly signal?: AbortSignal,\n private readonly request: FindingsRequest = fetch,\n ) {}\n\n async potentialDuplicates(\n findingId: string,\n scope: FindingSearchScope,\n ): Promise<FindingNeighborhood> {\n const url = this.endpoint(\n `v1/finding/${encodeURIComponent(findingId)}/potential-duplicates`,\n );\n if (scope.allRepositories === true)\n url.searchParams.set(\"allRepositories\", \"true\");\n else url.searchParams.set(\"repositoryId\", scope.repositoryId);\n const response = await this.request(url, { signal: this.signal });\n if (!response.ok) {\n throw new CodexSecurityError(\n `Potential-duplicates lookup for ${findingId} failed (HTTP ${response.status}).${\n response.status === 404\n ? \" Import the finding with its repositoryId through POST /v1/bulk/findings before deduplicating.\"\n : \"\"\n }`,\n );\n }\n return (await response.json()) as FindingNeighborhood;\n }\n\n async publish(\n findings: readonly Finding[],\n repositoryId: string,\n ): Promise<string[]> {\n const receipt = await this.post(\"v1/bulk/findings\", {\n findings,\n repositoryId,\n });\n const expected = new Set(findings.map((finding) => finding.findingId));\n if (\n !Array.isArray(receipt) ||\n receipt.length !== findings.length ||\n new Set(receipt).size !== expected.size ||\n receipt.some((id) => !expected.has(id))\n ) {\n throw new CodexSecurityError(\n \"The findings API did not acknowledge all published finding IDs. Check the service before retrying.\",\n );\n }\n return receipt as string[];\n }\n\n async storeDedupeGroups(groups: readonly string[][]): Promise<void> {\n if (groups.length === 0) return;\n await this.post(\"v1/dedupe-groups\", { groups });\n }\n\n private endpoint(path: string): URL {\n return new URL(path, this.url.endsWith(\"/\") ? this.url : `${this.url}/`);\n }\n\n private async post(path: string, body: unknown): Promise<unknown> {\n const response = await this.request(this.endpoint(path), {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n signal: this.signal,\n });\n if (!response.ok) {\n throw new CodexSecurityError(\n `Findings API POST /${path} failed (HTTP ${response.status}).`,\n );\n }\n return await response.json();\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export { normalizeComponentPlan, planComponents } from "./component-plan.js";
|
|
|
5
5
|
export type { ComponentPlan, ComponentPlanningOptions, } from "./component-plan.js";
|
|
6
6
|
export { estimateScanCost } from "./cost.js";
|
|
7
7
|
export type { ScanCost, ScanSessionEvent } from "./cost.js";
|
|
8
|
+
export type { DeepScanProgress } from "./deep-progress.js";
|
|
8
9
|
export type { CustomValidationResult } from "./custom-validation.js";
|
|
9
10
|
export type { ScanActivity, ScanActivityStatus } from "./scan-activity.js";
|
|
10
11
|
export type { CodexSecurityMetadata, DeepScanOptions, ScanAuthMode, ScanAuthentication, ScanOptions, ScanPreflight, ScanReconnectDetails, ScanTrustedAccessStatus, ScanWarningDetails, ValidationOptions, ValidationResult, } from "./api.js";
|
|
@@ -19,6 +20,10 @@ export { loadContract, requireScanFile } from "./contract.js";
|
|
|
19
20
|
export type { LoadedContract, ScanExpectation } from "./contract.js";
|
|
20
21
|
export type * from "./models.js";
|
|
21
22
|
export { checkScanPublication, publishScan } from "./publish.js";
|
|
23
|
+
export { publishScanToCustom } from "./custom-publish.js";
|
|
24
|
+
export type { PublishScanToCustomOptions, CustomPublicationResult, } from "./custom-publish.js";
|
|
25
|
+
export { deduplicateScan } from "./deduplication/scan.js";
|
|
26
|
+
export type { DeduplicateScanOptions, DeduplicateScanResult, } from "./deduplication/scan.js";
|
|
22
27
|
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
23
28
|
export type { GitHubCodeScanningImportOptions, ImportedGitHubCodeScanningAlert, } from "./github.js";
|
|
24
29
|
export type { CheckScanPublicationOptions, CheckScanPublicationResult, PublishScanOptions, PublishScanProgress, PublishScanResult, } from "./publish.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC7E,YAAY,EACV,aAAa,EACb,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,YAAY,E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EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@ export { AuthenticationRequiredError, CodexSecurityError, ConfigurationError, Co
|
|
|
7
7
|
export { DEFAULT_CODEX_CONFIG, mergedCodexConfig, writeCodexConfig, } from "./config.js";
|
|
8
8
|
export { loadContract, requireScanFile } from "./contract.js";
|
|
9
9
|
export { checkScanPublication, publishScan } from "./publish.js";
|
|
10
|
+
export { publishScanToCustom } from "./custom-publish.js";
|
|
11
|
+
export { deduplicateScan } from "./deduplication/scan.js";
|
|
10
12
|
export { importGitHubCodeScanningAlerts } from "./github.js";
|
|
11
13
|
export { ScanResult } from "./result.js";
|
|
12
14
|
export { bootstrapPlugin, bundledPluginRoot, cleanupSdkDirectory, createIsolatedHome, createMarketplace, extractPluginZip, importAmbientAuth, MARKETPLACE_NAME, pluginExecutionEnvironment, pluginMetadata, PLUGIN_NAME, prepareOutputDir, resolveCodexCommand, resolvePluginPath, resolvePluginPython, validateOutputDir, } from "./runtime.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAQxD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAK7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,q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c,CAAC","sourcesContent":["export { CodexSecurity, createSecurity } from \"./api.js\";\nexport { runComponentScans } from \"./component-scan.js\";\nexport type {\n ComponentDeduplicationSummary,\n ComponentReceipt,\n ComponentScanOptions,\n ComponentScanEvent,\n ComponentScanResult,\n} from \"./component-scan.js\";\nexport { normalizeComponentPlan, planComponents } from \"./component-plan.js\";\nexport type {\n ComponentPlan,\n ComponentPlanningOptions,\n} from \"./component-plan.js\";\nexport { estimateScanCost } from \"./cost.js\";\nexport type { ScanCost, ScanSessionEvent } from \"./cost.js\";\nexport type { DeepScanProgress } from \"./deep-progress.js\";\nexport type { CustomValidationResult } from \"./custom-validation.js\";\nexport type { ScanActivity, ScanActivityStatus } from \"./scan-activity.js\";\nexport type {\n CodexSecurityMetadata,\n DeepScanOptions,\n ScanAuthMode,\n ScanAuthentication,\n ScanOptions,\n ScanPreflight,\n ScanReconnectDetails,\n ScanTrustedAccessStatus,\n ScanWarningDetails,\n ValidationOptions,\n ValidationResult,\n} from \"./api.js\";\nexport type {\n ScanPhase,\n ScanProgress,\n ScanWorkerPhase,\n ScanWorkerStatus,\n} from \"./worker-progress.js\";\nexport { CodexLoginHandle } from \"./auth.js\";\nexport type { AccountStatus, LoginResult } from \"./auth.js\";\n\nexport {\n AuthenticationRequiredError,\n CodexSecurityError,\n ConfigurationError,\n ContractValidationError,\n IncompleteScanError,\n InvalidTargetError,\n OutputDirectoryError,\n OutputDirectoryNotEmptyError,\n OutputInsideProtectedRootError,\n PluginBootstrapError,\n PluginPythonUnavailableError,\n ScanCostLimitExceededError,\n ScanInterruptedError,\n} from \"./errors.js\";\nexport type { ProtectedScanPathKind } from \"./errors.js\";\nexport {\n DEFAULT_CODEX_CONFIG,\n mergedCodexConfig,\n writeCodexConfig,\n} from \"./config.js\";\nexport type { CodexSecurityConfig, JsonObject, JsonValue } from \"./config.js\";\nexport { loadContract, requireScanFile } from \"./contract.js\";\nexport type { LoadedContract, ScanExpectation } from \"./contract.js\";\nexport type * from \"./models.js\";\nexport { checkScanPublication, publishScan } from \"./publish.js\";\nexport { publishScanToCustom } from \"./custom-publish.js\";\nexport type {\n PublishScanToCustomOptions,\n CustomPublicationResult,\n} from \"./custom-publish.js\";\nexport { deduplicateScan } from \"./deduplication/scan.js\";\nexport type {\n DeduplicateScanOptions,\n DeduplicateScanResult,\n} from \"./deduplication/scan.js\";\nexport { importGitHubCodeScanningAlerts } from \"./github.js\";\nexport type {\n GitHubCodeScanningImportOptions,\n ImportedGitHubCodeScanningAlert,\n} from \"./github.js\";\nexport type {\n CheckScanPublicationOptions,\n CheckScanPublicationResult,\n PublishScanOptions,\n PublishScanProgress,\n PublishScanResult,\n} from \"./publish.js\";\nexport { ScanResult } from \"./result.js\";\nexport type {\n RepositoryFinding,\n ScanResultOptions,\n TurnResultMetadata,\n} from \"./result.js\";\nexport {\n bootstrapPlugin,\n bundledPluginRoot,\n cleanupSdkDirectory,\n createIsolatedHome,\n createMarketplace,\n extractPluginZip,\n importAmbientAuth,\n MARKETPLACE_NAME,\n pluginExecutionEnvironment,\n pluginMetadata,\n PLUGIN_NAME,\n prepareOutputDir,\n resolveCodexCommand,\n resolvePluginPath,\n resolvePluginPython,\n validateOutputDir,\n} from \"./runtime.js\";\nexport type {\n CodexCommand,\n PluginInstall,\n PluginPythonOptions,\n ProcessEnvironment,\n} from \"./runtime.js\";\nexport {\n DiffTarget,\n normalizeRepository,\n normalizeTarget,\n repositoryRevision,\n validateMode,\n} from \"./targets.js\";\nexport type { NormalizedTarget, ScanMode, ScanTarget } from \"./targets.js\";\nexport { BUNDLED_PLUGIN_VERSION, VERSION } from \"./version.js\";\n"]}
|
package/dist/publication.js
CHANGED
|
@@ -52,45 +52,10 @@ export async function prepareScanPublication(scanDirectory, options) {
|
|
|
52
52
|
function renderFindingDescription(contract, finding, uploadedAt) {
|
|
53
53
|
const { coverage } = contract;
|
|
54
54
|
const { scan } = contract.manifest;
|
|
55
|
-
const lines = [
|
|
56
|
-
|
|
57
|
-
"",
|
|
58
|
-
|
|
59
|
-
`**Finding ID:** ${finding.findingId}`,
|
|
60
|
-
`**Occurrence ID:** ${finding.occurrenceId}`,
|
|
61
|
-
`**Fingerprint:** ${finding.fingerprints.primary}`,
|
|
62
|
-
`**Severity:** ${finding.severity.level.toUpperCase()}`,
|
|
63
|
-
`**Confidence:** ${finding.confidence.level.toUpperCase()}`,
|
|
64
|
-
...(finding.taxonomy.cwe.length === 0
|
|
65
|
-
? []
|
|
66
|
-
: [`**CWE:** ${finding.taxonomy.cwe.join(", ")}`]),
|
|
67
|
-
"",
|
|
68
|
-
"## Scanned code",
|
|
69
|
-
"",
|
|
70
|
-
`**Repository:** ${scan.target.displayName}`,
|
|
71
|
-
...(scan.target.remote === undefined
|
|
72
|
-
? []
|
|
73
|
-
: [`**Remote:** ${scan.target.remote}`]),
|
|
74
|
-
...renderTargetIdentity(scan.target),
|
|
75
|
-
`**Scanned scope:** ${scan.scope.includePaths.join(", ") || "entire repository"}`,
|
|
76
|
-
...(scan.scope.excludePaths.length === 0
|
|
77
|
-
? []
|
|
78
|
-
: [`**Excluded scope:** ${scan.scope.excludePaths.join(", ")}`]),
|
|
79
|
-
`**Coverage:** ${coverage.completeness}`,
|
|
80
|
-
`**Coverage mode:** ${coverage.mode}`,
|
|
81
|
-
`**Scan mode:** ${scanMode(coverage.mode)}`,
|
|
82
|
-
`**Started:** ${scan.startedAt}`,
|
|
83
|
-
`**Completed:** ${scan.completedAt}`,
|
|
84
|
-
`**Uploaded:** ${uploadedAt}`,
|
|
85
|
-
"",
|
|
86
|
-
"### Affected locations",
|
|
87
|
-
"",
|
|
88
|
-
...finding.locations.map((location) => renderLocation(scan.target, location)),
|
|
89
|
-
"",
|
|
90
|
-
"## Summary",
|
|
91
|
-
"",
|
|
92
|
-
finding.summary,
|
|
93
|
-
];
|
|
55
|
+
const lines = ["## Summary", "", finding.summary];
|
|
56
|
+
if (finding.attackPath?.summary !== undefined) {
|
|
57
|
+
lines.push("", "## Reproduction summary", "", finding.attackPath.summary);
|
|
58
|
+
}
|
|
94
59
|
const rootCause = finding.rootCause;
|
|
95
60
|
if (typeof rootCause === "string") {
|
|
96
61
|
lines.push("", "## Root cause", "", rootCause);
|
|
@@ -101,13 +66,36 @@ function renderFindingDescription(contract, finding, uploadedAt) {
|
|
|
101
66
|
lines.push("", fencedCode(rootCause.code, rootCause.language));
|
|
102
67
|
}
|
|
103
68
|
}
|
|
69
|
+
lines.push("", "## Remediation", "", finding.remediation);
|
|
70
|
+
const validation = finding.validation;
|
|
71
|
+
const limits = [
|
|
72
|
+
...new Set([
|
|
73
|
+
...(validation?.limitations ?? []),
|
|
74
|
+
...(validation?.counterEvidence ?? []),
|
|
75
|
+
...(finding.attackPath?.limitations ?? []),
|
|
76
|
+
]),
|
|
77
|
+
];
|
|
78
|
+
if (validation?.summary || validation?.method || limits.length > 0) {
|
|
79
|
+
lines.push("", "## Validation", "");
|
|
80
|
+
if (validation?.summary)
|
|
81
|
+
lines.push(validation.summary, "");
|
|
82
|
+
if (validation?.method)
|
|
83
|
+
lines.push(`**Method:** ${validation.method}`, "");
|
|
84
|
+
lines.push(...limits.map((limit) => `- ${limit}`));
|
|
85
|
+
}
|
|
104
86
|
if (finding.codeEvidence !== undefined && finding.codeEvidence.length > 0) {
|
|
105
87
|
lines.push("", "## Source-code evidence");
|
|
106
88
|
for (const evidence of finding.codeEvidence) {
|
|
107
89
|
lines.push("", ...renderCodeEvidence(scan.target, evidence));
|
|
108
90
|
}
|
|
109
91
|
}
|
|
110
|
-
lines.push("", "##
|
|
92
|
+
lines.push("", "---", "", "## Codex Security finding", "", `**Scan ID:** ${scan.id}`, `**Finding ID:** ${finding.findingId}`, `**Occurrence ID:** ${finding.occurrenceId}`, `**Fingerprint:** ${finding.fingerprints.primary}`, `**Severity:** ${finding.severity.level.toUpperCase()}`, `**Confidence:** ${finding.confidence.level.toUpperCase()}`, ...(finding.taxonomy.cwe.length === 0
|
|
93
|
+
? []
|
|
94
|
+
: [`**CWE:** ${finding.taxonomy.cwe.join(", ")}`]), "", "## Scanned code", "", `**Repository:** ${scan.target.displayName}`, ...(scan.target.remote === undefined
|
|
95
|
+
? []
|
|
96
|
+
: [`**Remote:** ${scan.target.remote}`]), ...renderTargetIdentity(scan.target), `**Scanned scope:** ${scan.scope.includePaths.join(", ") || "entire repository"}`, ...(scan.scope.excludePaths.length === 0
|
|
97
|
+
? []
|
|
98
|
+
: [`**Excluded scope:** ${scan.scope.excludePaths.join(", ")}`]), `**Coverage:** ${coverage.completeness}`, `**Coverage mode:** ${coverage.mode}`, `**Scan mode:** ${scanMode(coverage.mode)}`, `**Started:** ${scan.startedAt}`, `**Completed:** ${scan.completedAt}`, `**Uploaded:** ${uploadedAt}`, "", "### Affected locations", "", ...finding.locations.map((location) => renderLocation(scan.target, location)));
|
|
111
99
|
return `${lines.join("\n")}\n`;
|
|
112
100
|
}
|
|
113
101
|
function renderTargetIdentity(target) {
|