@openai/codex-security 0.1.26 → 0.1.27
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 +398 -30
- package/_bundled_plugin/.mcp.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs +24 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/native/COPYRIGHT-library.html +5556 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +5989 -0
- package/_bundled_plugin/mcp/native/darwin-arm64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/darwin-x64/unix.node +0 -0
- package/_bundled_plugin/mcp/native/licenses/Apache-2.0.txt +73 -0
- package/_bundled_plugin/mcp/native/licenses/BSD-2-Clause.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/MIT.txt +9 -0
- package/_bundled_plugin/mcp/native/licenses/Unicode-3.0.txt +39 -0
- package/_bundled_plugin/mcp/native/linux-arm64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-arm64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-gnu/unix.node +0 -0
- package/_bundled_plugin/mcp/native/linux-x64-musl/unix.node +0 -0
- package/_bundled_plugin/mcp/native/win32-arm64/windows.node +0 -0
- package/_bundled_plugin/mcp/native/win32-x64/windows.node +0 -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 -0
- package/_bundled_plugin/references/core-scan.md +1 -1
- package/_bundled_plugin/references/scan-contract.md +35 -35
- package/_bundled_plugin/references/security-guidance.md +7 -1
- package/_bundled_plugin/scripts/generate_in_scope_files.py +2 -2
- package/_bundled_plugin/scripts/generate_rank_input.py +8 -1
- package/_bundled_plugin/scripts/launch_codex_security_mcp +6 -0
- package/_bundled_plugin/scripts/launch_codex_security_mcp.cmd +43 -9
- package/_bundled_plugin/scripts/rank_preview.py +4 -1
- package/_bundled_plugin/scripts/workbench_cli.py +4 -0
- package/_bundled_plugin/scripts/workbench_db.py +33 -29
- package/_bundled_plugin/scripts/workbench_scan_history.py +117 -2
- package/_bundled_plugin/scripts/workbench_validation.py +4 -0
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +3 -3
- package/dist/api.d.ts +7 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +481 -60
- package/dist/api.js.map +1 -1
- package/dist/auth.js +10 -0
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts +18 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +962 -276
- package/dist/cli.js.map +1 -1
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +2 -207
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-plan.d.ts.map +1 -1
- package/dist/component-plan.js +116 -32
- package/dist/component-plan.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +17 -2
- package/dist/config.js.map +1 -1
- package/dist/contract.d.ts +5 -10
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js.map +1 -1
- package/dist/cost-model.d.ts +16 -0
- package/dist/cost-model.d.ts.map +1 -1
- package/dist/cost-model.js +57 -3
- package/dist/cost-model.js.map +1 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +18 -3
- package/dist/cost.js.map +1 -1
- package/dist/custom-validation-prompt.js +1 -1
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/deduplication/codex-review.d.ts +6 -1
- package/dist/deduplication/codex-review.d.ts.map +1 -1
- package/dist/deduplication/codex-review.js +72 -17
- package/dist/deduplication/codex-review.js.map +1 -1
- package/dist/deduplication/deduplication.d.ts +2 -0
- package/dist/deduplication/deduplication.d.ts.map +1 -1
- package/dist/deduplication/deduplication.js +99 -26
- package/dist/deduplication/deduplication.js.map +1 -1
- package/dist/deduplication/retry.d.ts +3 -0
- package/dist/deduplication/retry.d.ts.map +1 -0
- package/dist/deduplication/retry.js +15 -0
- package/dist/deduplication/retry.js.map +1 -0
- package/dist/deduplication/scan.d.ts +2 -0
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +4 -2
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/feedback.d.ts +20 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +121 -0
- package/dist/feedback.js.map +1 -0
- package/dist/findings-client.d.ts +7 -1
- package/dist/findings-client.d.ts.map +1 -1
- package/dist/findings-client.js +55 -10
- package/dist/findings-client.js.map +1 -1
- package/dist/findings-import.d.ts +44 -0
- package/dist/findings-import.d.ts.map +1 -0
- package/dist/findings-import.js +302 -0
- package/dist/findings-import.js.map +1 -0
- package/dist/import-scan.d.ts +27 -0
- package/dist/import-scan.d.ts.map +1 -0
- package/dist/import-scan.js +236 -0
- package/dist/import-scan.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -1
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +2 -2
- package/dist/knowledge-base.js.map +1 -1
- package/dist/multiscan.d.ts +2 -0
- package/dist/multiscan.d.ts.map +1 -1
- package/dist/multiscan.js +144 -52
- package/dist/multiscan.js.map +1 -1
- package/dist/publication-events.d.ts.map +1 -1
- package/dist/publication-events.js +7 -2
- package/dist/publication-events.js.map +1 -1
- package/dist/runtime.d.ts +5 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +8 -2
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +19 -6
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-logs.d.ts +29 -0
- package/dist/scan-logs.d.ts.map +1 -1
- package/dist/scan-logs.js +36 -5
- package/dist/scan-logs.js.map +1 -1
- package/dist/security-policy-cli.d.ts +39 -0
- package/dist/security-policy-cli.d.ts.map +1 -0
- package/dist/security-policy-cli.js +193 -0
- package/dist/security-policy-cli.js.map +1 -0
- package/dist/security-policy.d.ts +80 -0
- package/dist/security-policy.d.ts.map +1 -0
- package/dist/security-policy.js +672 -0
- package/dist/security-policy.js.map +1 -0
- package/dist/targets.d.ts +8 -1
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +243 -14
- package/dist/targets.js.map +1 -1
- package/package.json +8 -4
- package/_bundled_plugin/scripts/resolve_security_md.py +0 -158
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import { isAbsolute, join, posix } from "node:path";
|
|
4
|
+
import Ajv2020 from "ajv/dist/2020.js";
|
|
5
|
+
import { z } from "incur";
|
|
6
|
+
import Papa from "papaparse";
|
|
7
|
+
import { CodexSecurityError } from "./errors.js";
|
|
8
|
+
export const CSV_TARGET_ID = "codex-security-csv-import";
|
|
9
|
+
const EXPORTED_CSV_ESCAPE = /^'(?:[\t\r\n]|\s*[=+\-@=+-@])/u;
|
|
10
|
+
const csvFindingRowSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
occurrence_id: z.string().regex(/^occ_[a-f0-9]{24}$/u, {
|
|
13
|
+
error: "has an invalid occurrence_id",
|
|
14
|
+
}),
|
|
15
|
+
finding_id: z.string().regex(/^csf_[a-f0-9]{24}$/u, {
|
|
16
|
+
error: "has an invalid finding_id",
|
|
17
|
+
}),
|
|
18
|
+
candidate_id: z
|
|
19
|
+
.string()
|
|
20
|
+
.optional()
|
|
21
|
+
.transform((value) => value === undefined || value.trim() === "" ? undefined : value),
|
|
22
|
+
title: requiredCsvText("title"),
|
|
23
|
+
summary: requiredCsvText("summary"),
|
|
24
|
+
severity: z.enum(["critical", "high", "medium", "low", "informational"], {
|
|
25
|
+
error: "has an invalid severity",
|
|
26
|
+
}),
|
|
27
|
+
confidence: z.enum(["high", "medium", "low"], {
|
|
28
|
+
error: "has an invalid confidence",
|
|
29
|
+
}),
|
|
30
|
+
status: z.enum(["open", "closed"], {
|
|
31
|
+
error: "has an invalid status",
|
|
32
|
+
}),
|
|
33
|
+
close_reason: z
|
|
34
|
+
.union([
|
|
35
|
+
z.literal(""),
|
|
36
|
+
z.enum(["already_fixed", "wont_fix", "false_positive"]),
|
|
37
|
+
], { error: "has an invalid close_reason" })
|
|
38
|
+
.transform((value) => (value === "" ? undefined : value)),
|
|
39
|
+
note: z
|
|
40
|
+
.string()
|
|
41
|
+
.transform((value) => (value.trim() === "" ? undefined : value)),
|
|
42
|
+
remediation: requiredCsvText("remediation"),
|
|
43
|
+
path: z.string().refine(safeFindingPath, {
|
|
44
|
+
error: "has an invalid path",
|
|
45
|
+
}),
|
|
46
|
+
start_line: z
|
|
47
|
+
.string()
|
|
48
|
+
.refine(validCsvLine, { error: "has an invalid start_line" })
|
|
49
|
+
.transform(Number),
|
|
50
|
+
end_line: z
|
|
51
|
+
.string()
|
|
52
|
+
.refine((value) => value === "" || validCsvLine(value), {
|
|
53
|
+
error: "has an invalid end_line",
|
|
54
|
+
})
|
|
55
|
+
.transform((value) => (value === "" ? undefined : Number(value))),
|
|
56
|
+
})
|
|
57
|
+
.superRefine((row, context) => {
|
|
58
|
+
if ((row.status === "open" && row.close_reason !== undefined) ||
|
|
59
|
+
(row.status === "closed" && row.close_reason === undefined)) {
|
|
60
|
+
context.addIssue({
|
|
61
|
+
code: "custom",
|
|
62
|
+
path: ["close_reason"],
|
|
63
|
+
message: "has an invalid close_reason",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (row.status === "closed" &&
|
|
67
|
+
(row.close_reason === "false_positive" ||
|
|
68
|
+
row.close_reason === "wont_fix") &&
|
|
69
|
+
row.note === undefined) {
|
|
70
|
+
context.addIssue({
|
|
71
|
+
code: "custom",
|
|
72
|
+
path: ["note"],
|
|
73
|
+
message: "requires a note for its close_reason",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (row.end_line !== undefined && row.end_line < row.start_line) {
|
|
77
|
+
context.addIssue({
|
|
78
|
+
code: "custom",
|
|
79
|
+
path: ["end_line"],
|
|
80
|
+
message: "has end_line before start_line",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const CSV_COLUMNS = Object.keys(csvFindingRowSchema.shape);
|
|
85
|
+
const REQUIRED_CSV_COLUMNS = CSV_COLUMNS.filter((column) => !csvFindingRowSchema.shape[column].isOptional());
|
|
86
|
+
export async function parseImportedFindings(source, format, pluginRoot) {
|
|
87
|
+
if (format === "csv") {
|
|
88
|
+
return parseFindingsCsv(source).map((row) => ({
|
|
89
|
+
...csvRowFinding(row, "import"),
|
|
90
|
+
findingId: row.finding_id,
|
|
91
|
+
occurrenceId: row.occurrence_id,
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
let payload;
|
|
95
|
+
try {
|
|
96
|
+
// Exported findings files often start with a UTF-8 byte order mark, which
|
|
97
|
+
// the CSV parser already skips.
|
|
98
|
+
payload = JSON.parse(source.replace(/^\uFEFF/u, ""));
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw new CodexSecurityError("Findings JSON could not be parsed.", {
|
|
102
|
+
cause: error,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
if (payload === null ||
|
|
106
|
+
typeof payload !== "object" ||
|
|
107
|
+
Array.isArray(payload)) {
|
|
108
|
+
throw new CodexSecurityError("Findings JSON must contain a findings document or an object with a findings array.");
|
|
109
|
+
}
|
|
110
|
+
const hasDocumentMetadata = ["documentType", "schemaVersion", "scanId"].some((key) => Object.hasOwn(payload, key));
|
|
111
|
+
const document = hasDocumentMetadata
|
|
112
|
+
? payload
|
|
113
|
+
: {
|
|
114
|
+
documentType: "codex-security.findings",
|
|
115
|
+
schemaVersion: "1.0",
|
|
116
|
+
scanId: "import",
|
|
117
|
+
...payload,
|
|
118
|
+
};
|
|
119
|
+
const schema = JSON.parse(await readFile(join(pluginRoot, "schemas", "findings.schema.json"), "utf8"));
|
|
120
|
+
const validate = new Ajv2020({ strict: false }).compile(schema);
|
|
121
|
+
if (!validate(document)) {
|
|
122
|
+
const error = validate.errors?.[0];
|
|
123
|
+
throw new CodexSecurityError(`Findings JSON does not match the Codex Security findings schema${error ? ` at ${error.instancePath || "/"}: ${error.message}` : ""}.`);
|
|
124
|
+
}
|
|
125
|
+
const occurrenceIds = new Set();
|
|
126
|
+
for (const [index, finding] of document.findings.entries()) {
|
|
127
|
+
if (occurrenceIds.has(finding.occurrenceId)) {
|
|
128
|
+
throw new CodexSecurityError(`Findings JSON finding ${index + 1} has a duplicate occurrenceId.`);
|
|
129
|
+
}
|
|
130
|
+
occurrenceIds.add(finding.occurrenceId);
|
|
131
|
+
}
|
|
132
|
+
return document.findings;
|
|
133
|
+
}
|
|
134
|
+
export function bindImportedFindings(findings, format, scanId, targetId) {
|
|
135
|
+
return findings.map((finding) => {
|
|
136
|
+
const ruleId = `import.${format}`;
|
|
137
|
+
const anchor = finding.occurrenceId;
|
|
138
|
+
const fingerprint = `codex-security/v1:sha256:${sha256(["codex-security/v1", targetId, ruleId, anchor, ""].join("\0"))}`;
|
|
139
|
+
// A source report path names another scan's artifact. Preserve it as
|
|
140
|
+
// provenance without treating the imported path as permission to read it.
|
|
141
|
+
const { writeup, ...content } = finding;
|
|
142
|
+
return {
|
|
143
|
+
...content,
|
|
144
|
+
findingId: `csf_${sha256(fingerprint).slice(0, 24)}`,
|
|
145
|
+
occurrenceId: `occ_${sha256([scanId, fingerprint].join("\0")).slice(0, 24)}`,
|
|
146
|
+
ruleId,
|
|
147
|
+
identity: { anchor },
|
|
148
|
+
fingerprints: {
|
|
149
|
+
algorithm: "codex-security/v1",
|
|
150
|
+
primary: fingerprint,
|
|
151
|
+
},
|
|
152
|
+
provenance: { source: `${format}_import` },
|
|
153
|
+
extensions: {
|
|
154
|
+
...finding.extensions,
|
|
155
|
+
import: {
|
|
156
|
+
format,
|
|
157
|
+
sourceFindingId: finding.findingId,
|
|
158
|
+
sourceOccurrenceId: finding.occurrenceId,
|
|
159
|
+
sourceRuleId: finding.ruleId,
|
|
160
|
+
sourceIdentity: finding.identity,
|
|
161
|
+
sourceFingerprints: finding.fingerprints,
|
|
162
|
+
sourceProvenance: finding.provenance,
|
|
163
|
+
...(writeup === undefined ? {} : { sourceWriteup: writeup }),
|
|
164
|
+
...(finding.extensions?.["import"] === undefined
|
|
165
|
+
? {}
|
|
166
|
+
: { previousImport: finding.extensions["import"] }),
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
export function parseFindingsCsv(source) {
|
|
173
|
+
const { data: rows, errors, meta, } = Papa.parse(source, {
|
|
174
|
+
header: true,
|
|
175
|
+
delimiter: ",",
|
|
176
|
+
skipEmptyLines: "greedy",
|
|
177
|
+
transform: decodeExportedCsvCell,
|
|
178
|
+
});
|
|
179
|
+
const fieldMismatch = errors.find((error) => error.code === "TooFewFields" || error.code === "TooManyFields");
|
|
180
|
+
if (fieldMismatch?.row !== undefined) {
|
|
181
|
+
throw csvRowError(fieldMismatch.row + 2, "must match the header columns");
|
|
182
|
+
}
|
|
183
|
+
if (errors.length > 0) {
|
|
184
|
+
throw new CodexSecurityError(`Findings CSV could not be parsed: ${errors[0].message}`);
|
|
185
|
+
}
|
|
186
|
+
const headers = meta.fields;
|
|
187
|
+
const allowed = new Set(CSV_COLUMNS);
|
|
188
|
+
if (headers === undefined ||
|
|
189
|
+
!REQUIRED_CSV_COLUMNS.every((name) => headers.includes(name)) ||
|
|
190
|
+
headers.some((name) => !allowed.has(name)) ||
|
|
191
|
+
new Set(headers).size !== headers.length) {
|
|
192
|
+
throw new CodexSecurityError(`Findings CSV must use the Codex Security export columns: ${REQUIRED_CSV_COLUMNS.join(", ")} (candidate_id is optional).`);
|
|
193
|
+
}
|
|
194
|
+
if (rows.length === 0) {
|
|
195
|
+
throw new CodexSecurityError("Findings CSV must contain at least one finding.");
|
|
196
|
+
}
|
|
197
|
+
const findingIds = new Set();
|
|
198
|
+
const occurrenceIds = new Set();
|
|
199
|
+
return rows.map((record, index) => {
|
|
200
|
+
const rowNumber = index + 2;
|
|
201
|
+
const parsed = csvFindingRowSchema.safeParse(record);
|
|
202
|
+
if (!parsed.success) {
|
|
203
|
+
throw csvRowError(rowNumber, parsed.error.issues[0].message);
|
|
204
|
+
}
|
|
205
|
+
const row = parsed.data;
|
|
206
|
+
if (findingIds.has(row.finding_id)) {
|
|
207
|
+
throw csvRowError(rowNumber, "has a duplicate finding_id");
|
|
208
|
+
}
|
|
209
|
+
if (occurrenceIds.has(row.occurrence_id)) {
|
|
210
|
+
throw csvRowError(rowNumber, "has a duplicate occurrence_id");
|
|
211
|
+
}
|
|
212
|
+
findingIds.add(row.finding_id);
|
|
213
|
+
occurrenceIds.add(row.occurrence_id);
|
|
214
|
+
return row;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
function decodeExportedCsvCell(value) {
|
|
218
|
+
return EXPORTED_CSV_ESCAPE.test(value) ? value.slice(1) : value;
|
|
219
|
+
}
|
|
220
|
+
export function csvRowFinding(row, scanId) {
|
|
221
|
+
const ruleId = "import.csv";
|
|
222
|
+
const anchor = row.finding_id;
|
|
223
|
+
const fingerprint = `codex-security/v1:sha256:${sha256(["codex-security/v1", CSV_TARGET_ID, ruleId, anchor, ""].join("\0"))}`;
|
|
224
|
+
const findingId = `csf_${sha256(fingerprint).slice(0, 24)}`;
|
|
225
|
+
const occurrenceId = `occ_${sha256([scanId, fingerprint].join("\0")).slice(0, 24)}`;
|
|
226
|
+
return {
|
|
227
|
+
findingId,
|
|
228
|
+
occurrenceId,
|
|
229
|
+
ruleId,
|
|
230
|
+
identity: { anchor },
|
|
231
|
+
fingerprints: {
|
|
232
|
+
algorithm: "codex-security/v1",
|
|
233
|
+
primary: fingerprint,
|
|
234
|
+
},
|
|
235
|
+
title: row.title,
|
|
236
|
+
summary: row.summary,
|
|
237
|
+
severity: { level: row.severity },
|
|
238
|
+
confidence: {
|
|
239
|
+
level: row.confidence,
|
|
240
|
+
rationale: "Imported from a Codex Security findings CSV.",
|
|
241
|
+
},
|
|
242
|
+
taxonomy: { category: "imported", cwe: [] },
|
|
243
|
+
locations: [
|
|
244
|
+
{
|
|
245
|
+
path: row.path,
|
|
246
|
+
startLine: row.start_line,
|
|
247
|
+
...(row.end_line === undefined ? {} : { endLine: row.end_line }),
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
remediation: row.remediation,
|
|
251
|
+
validation: {
|
|
252
|
+
method: "Source-reported CSV import metadata",
|
|
253
|
+
status: row.status,
|
|
254
|
+
summary: [
|
|
255
|
+
`Source finding ID: ${row.finding_id}`,
|
|
256
|
+
`Source occurrence ID: ${row.occurrence_id}`,
|
|
257
|
+
`Source status: ${row.status}`,
|
|
258
|
+
...(row.close_reason === undefined
|
|
259
|
+
? []
|
|
260
|
+
: [`Source close reason: ${row.close_reason}`]),
|
|
261
|
+
...(row.note === undefined ? [] : [`Source note: ${row.note}`]),
|
|
262
|
+
].join("\n"),
|
|
263
|
+
},
|
|
264
|
+
provenance: { source: "csv_import" },
|
|
265
|
+
extensions: {
|
|
266
|
+
...(row.candidate_id === undefined
|
|
267
|
+
? {}
|
|
268
|
+
: { candidateId: row.candidate_id }),
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function requiredCsvText(column) {
|
|
273
|
+
return z.string().refine((value) => value.trim().length > 0, {
|
|
274
|
+
error: `requires ${column}`,
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
function validCsvLine(value) {
|
|
278
|
+
if (!/^[1-9]\d*$/u.test(value))
|
|
279
|
+
return false;
|
|
280
|
+
const line = Number(value);
|
|
281
|
+
return Number.isSafeInteger(line);
|
|
282
|
+
}
|
|
283
|
+
function safeFindingPath(value) {
|
|
284
|
+
if (value.trim().length === 0 ||
|
|
285
|
+
value === "." ||
|
|
286
|
+
isAbsolute(value) ||
|
|
287
|
+
/^[A-Za-z]:/u.test(value) ||
|
|
288
|
+
value.includes("\\") ||
|
|
289
|
+
/[\u0000-\u001F]/u.test(value) ||
|
|
290
|
+
value.split("/").includes("..")) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
const normalized = posix.normalize(value).replace(/\/+$/u, "");
|
|
294
|
+
return normalized !== "." && !normalized.startsWith("../");
|
|
295
|
+
}
|
|
296
|
+
function csvRowError(rowNumber, detail) {
|
|
297
|
+
return new CodexSecurityError(`Findings CSV row ${rowNumber} ${detail}.`);
|
|
298
|
+
}
|
|
299
|
+
function sha256(value) {
|
|
300
|
+
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
301
|
+
}
|
|
302
|
+
//# sourceMappingURL=findings-import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findings-import.js","sourceRoot":"","sources":["../src/findings-import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,OAAO,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,CAAC,EAAE,MAAM,OAAO,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGjD,MAAM,CAAC,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAGzD,MAAM,mBAAmB,GAAG,gCAAgC,CAAC;AAC7D,MAAM,mBAAmB,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,qBAAqB,EAAE;QACrD,KAAK,EAAE,8BAA8B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AAC;QACjB,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC;QACzB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QACpB,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9B,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC/B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC/D,OAAO,UAAU,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,WAAW,CAAC,SAAiB,EAAE,MAAc;IACpD,OAAO,IAAI,kBAAkB,CAAC,oBAAoB,SAAS,IAAI,MAAM,GAAG,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,MAAM,CAAC,KAAa;IAC3B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { readFile } from \"node:fs/promises\";\nimport { isAbsolute, join, posix } from \"node:path\";\nimport Ajv2020 from \"ajv/dist/2020.js\";\nimport { z } from \"incur\";\nimport Papa from \"papaparse\";\nimport { CodexSecurityError } from \"./errors.js\";\nimport type { Finding, FindingsDocument } from \"./models.js\";\n\nexport const CSV_TARGET_ID = \"codex-security-csv-import\";\nexport type FindingsImportFormat = \"csv\" | \"json\";\n\nconst EXPORTED_CSV_ESCAPE = /^'(?:[\\t\\r\\n]|\\s*[=+\\-@=+-@])/u;\nconst csvFindingRowSchema = z\n .object({\n occurrence_id: z.string().regex(/^occ_[a-f0-9]{24}$/u, {\n error: \"has an invalid occurrence_id\",\n }),\n finding_id: z.string().regex(/^csf_[a-f0-9]{24}$/u, {\n error: \"has an invalid finding_id\",\n }),\n candidate_id: z\n .string()\n .optional()\n .transform((value) =>\n value === undefined || value.trim() === \"\" ? undefined : value,\n ),\n title: requiredCsvText(\"title\"),\n summary: requiredCsvText(\"summary\"),\n severity: z.enum([\"critical\", \"high\", \"medium\", \"low\", \"informational\"], {\n error: \"has an invalid severity\",\n }),\n confidence: z.enum([\"high\", \"medium\", \"low\"], {\n error: \"has an invalid confidence\",\n }),\n status: z.enum([\"open\", \"closed\"], {\n error: \"has an invalid status\",\n }),\n close_reason: z\n .union(\n [\n z.literal(\"\"),\n z.enum([\"already_fixed\", \"wont_fix\", \"false_positive\"]),\n ],\n { error: \"has an invalid close_reason\" },\n )\n .transform((value) => (value === \"\" ? undefined : value)),\n note: z\n .string()\n .transform((value) => (value.trim() === \"\" ? undefined : value)),\n remediation: requiredCsvText(\"remediation\"),\n path: z.string().refine(safeFindingPath, {\n error: \"has an invalid path\",\n }),\n start_line: z\n .string()\n .refine(validCsvLine, { error: \"has an invalid start_line\" })\n .transform(Number),\n end_line: z\n .string()\n .refine((value) => value === \"\" || validCsvLine(value), {\n error: \"has an invalid end_line\",\n })\n .transform((value) => (value === \"\" ? undefined : Number(value))),\n })\n .superRefine((row, context) => {\n if (\n (row.status === \"open\" && row.close_reason !== undefined) ||\n (row.status === \"closed\" && row.close_reason === undefined)\n ) {\n context.addIssue({\n code: \"custom\",\n path: [\"close_reason\"],\n message: \"has an invalid close_reason\",\n });\n }\n if (\n row.status === \"closed\" &&\n (row.close_reason === \"false_positive\" ||\n row.close_reason === \"wont_fix\") &&\n row.note === undefined\n ) {\n context.addIssue({\n code: \"custom\",\n path: [\"note\"],\n message: \"requires a note for its close_reason\",\n });\n }\n if (row.end_line !== undefined && row.end_line < row.start_line) {\n context.addIssue({\n code: \"custom\",\n path: [\"end_line\"],\n message: \"has end_line before start_line\",\n });\n }\n });\ntype CsvFindingRow = z.infer<typeof csvFindingRowSchema>;\ntype CsvColumn = keyof typeof csvFindingRowSchema.shape;\nconst CSV_COLUMNS = Object.keys(csvFindingRowSchema.shape) as CsvColumn[];\nconst REQUIRED_CSV_COLUMNS = CSV_COLUMNS.filter(\n (column) => !csvFindingRowSchema.shape[column].isOptional(),\n);\n\nexport async function parseImportedFindings(\n source: string,\n format: FindingsImportFormat,\n pluginRoot: string,\n): Promise<Finding[]> {\n if (format === \"csv\") {\n return parseFindingsCsv(source).map((row) => ({\n ...csvRowFinding(row, \"import\"),\n findingId: row.finding_id,\n occurrenceId: row.occurrence_id,\n }));\n }\n\n let payload: unknown;\n try {\n // Exported findings files often start with a UTF-8 byte order mark, which\n // the CSV parser already skips.\n payload = JSON.parse(source.replace(/^\\uFEFF/u, \"\"));\n } catch (error) {\n throw new CodexSecurityError(\"Findings JSON could not be parsed.\", {\n cause: error,\n });\n }\n if (\n payload === null ||\n typeof payload !== \"object\" ||\n Array.isArray(payload)\n ) {\n throw new CodexSecurityError(\n \"Findings JSON must contain a findings document or an object with a findings array.\",\n );\n }\n const hasDocumentMetadata = [\"documentType\", \"schemaVersion\", \"scanId\"].some(\n (key) => Object.hasOwn(payload, key),\n );\n const document = hasDocumentMetadata\n ? payload\n : {\n documentType: \"codex-security.findings\",\n schemaVersion: \"1.0\",\n scanId: \"import\",\n ...payload,\n };\n const schema = JSON.parse(\n await readFile(join(pluginRoot, \"schemas\", \"findings.schema.json\"), \"utf8\"),\n );\n const validate = new Ajv2020({ strict: false }).compile<FindingsDocument>(\n schema,\n );\n if (!validate(document)) {\n const error = validate.errors?.[0];\n throw new CodexSecurityError(\n `Findings JSON does not match the Codex Security findings schema${error ? ` at ${error.instancePath || \"/\"}: ${error.message}` : \"\"}.`,\n );\n }\n const occurrenceIds = new Set<string>();\n for (const [index, finding] of document.findings.entries()) {\n if (occurrenceIds.has(finding.occurrenceId)) {\n throw new CodexSecurityError(\n `Findings JSON finding ${index + 1} has a duplicate occurrenceId.`,\n );\n }\n occurrenceIds.add(finding.occurrenceId);\n }\n return document.findings;\n}\n\nexport function bindImportedFindings(\n findings: Finding[],\n format: FindingsImportFormat,\n scanId: string,\n targetId: string,\n): Finding[] {\n return findings.map((finding) => {\n const ruleId = `import.${format}`;\n const anchor = finding.occurrenceId;\n const fingerprint = `codex-security/v1:sha256:${sha256(\n [\"codex-security/v1\", targetId, ruleId, anchor, \"\"].join(\"\\0\"),\n )}`;\n // A source report path names another scan's artifact. Preserve it as\n // provenance without treating the imported path as permission to read it.\n const { writeup, ...content } = finding;\n return {\n ...content,\n findingId: `csf_${sha256(fingerprint).slice(0, 24)}`,\n occurrenceId: `occ_${sha256([scanId, fingerprint].join(\"\\0\")).slice(0, 24)}`,\n ruleId,\n identity: { anchor },\n fingerprints: {\n algorithm: \"codex-security/v1\",\n primary: fingerprint,\n },\n provenance: { source: `${format}_import` },\n extensions: {\n ...finding.extensions,\n import: {\n format,\n sourceFindingId: finding.findingId,\n sourceOccurrenceId: finding.occurrenceId,\n sourceRuleId: finding.ruleId,\n sourceIdentity: finding.identity,\n sourceFingerprints: finding.fingerprints,\n sourceProvenance: finding.provenance,\n ...(writeup === undefined ? {} : { sourceWriteup: writeup }),\n ...(finding.extensions?.[\"import\"] === undefined\n ? {}\n : { previousImport: finding.extensions[\"import\"] }),\n },\n },\n };\n });\n}\n\nexport function parseFindingsCsv(source: string): CsvFindingRow[] {\n const {\n data: rows,\n errors,\n meta,\n } = Papa.parse<Record<string, string>>(source, {\n header: true,\n delimiter: \",\",\n skipEmptyLines: \"greedy\",\n transform: decodeExportedCsvCell,\n });\n const fieldMismatch = errors.find(\n (error) => error.code === \"TooFewFields\" || error.code === \"TooManyFields\",\n );\n if (fieldMismatch?.row !== undefined) {\n throw csvRowError(fieldMismatch.row + 2, \"must match the header columns\");\n }\n if (errors.length > 0) {\n throw new CodexSecurityError(\n `Findings CSV could not be parsed: ${errors[0]!.message}`,\n );\n }\n const headers = meta.fields;\n const allowed = new Set<string>(CSV_COLUMNS);\n if (\n headers === undefined ||\n !REQUIRED_CSV_COLUMNS.every((name) => headers.includes(name)) ||\n headers.some((name) => !allowed.has(name)) ||\n new Set(headers).size !== headers.length\n ) {\n throw new CodexSecurityError(\n `Findings CSV must use the Codex Security export columns: ${REQUIRED_CSV_COLUMNS.join(\", \")} (candidate_id is optional).`,\n );\n }\n if (rows.length === 0) {\n throw new CodexSecurityError(\n \"Findings CSV must contain at least one finding.\",\n );\n }\n\n const findingIds = new Set<string>();\n const occurrenceIds = new Set<string>();\n return rows.map((record, index) => {\n const rowNumber = index + 2;\n const parsed = csvFindingRowSchema.safeParse(record);\n if (!parsed.success) {\n throw csvRowError(rowNumber, parsed.error.issues[0]!.message);\n }\n const row = parsed.data;\n if (findingIds.has(row.finding_id)) {\n throw csvRowError(rowNumber, \"has a duplicate finding_id\");\n }\n if (occurrenceIds.has(row.occurrence_id)) {\n throw csvRowError(rowNumber, \"has a duplicate occurrence_id\");\n }\n findingIds.add(row.finding_id);\n occurrenceIds.add(row.occurrence_id);\n return row;\n });\n}\n\nfunction decodeExportedCsvCell(value: string): string {\n return EXPORTED_CSV_ESCAPE.test(value) ? value.slice(1) : value;\n}\n\nexport function csvRowFinding(row: CsvFindingRow, scanId: string): Finding {\n const ruleId = \"import.csv\";\n const anchor = row.finding_id;\n const fingerprint = `codex-security/v1:sha256:${sha256(\n [\"codex-security/v1\", CSV_TARGET_ID, ruleId, anchor, \"\"].join(\"\\0\"),\n )}`;\n const findingId = `csf_${sha256(fingerprint).slice(0, 24)}`;\n const occurrenceId = `occ_${sha256([scanId, fingerprint].join(\"\\0\")).slice(\n 0,\n 24,\n )}`;\n return {\n findingId,\n occurrenceId,\n ruleId,\n identity: { anchor },\n fingerprints: {\n algorithm: \"codex-security/v1\",\n primary: fingerprint,\n },\n title: row.title,\n summary: row.summary,\n severity: { level: row.severity },\n confidence: {\n level: row.confidence,\n rationale: \"Imported from a Codex Security findings CSV.\",\n },\n taxonomy: { category: \"imported\", cwe: [] },\n locations: [\n {\n path: row.path,\n startLine: row.start_line,\n ...(row.end_line === undefined ? {} : { endLine: row.end_line }),\n },\n ],\n remediation: row.remediation,\n validation: {\n method: \"Source-reported CSV import metadata\",\n status: row.status,\n summary: [\n `Source finding ID: ${row.finding_id}`,\n `Source occurrence ID: ${row.occurrence_id}`,\n `Source status: ${row.status}`,\n ...(row.close_reason === undefined\n ? []\n : [`Source close reason: ${row.close_reason}`]),\n ...(row.note === undefined ? [] : [`Source note: ${row.note}`]),\n ].join(\"\\n\"),\n },\n provenance: { source: \"csv_import\" },\n extensions: {\n ...(row.candidate_id === undefined\n ? {}\n : { candidateId: row.candidate_id }),\n },\n };\n}\n\nfunction requiredCsvText(column: string) {\n return z.string().refine((value) => value.trim().length > 0, {\n error: `requires ${column}`,\n });\n}\n\nfunction validCsvLine(value: string): boolean {\n if (!/^[1-9]\\d*$/u.test(value)) return false;\n const line = Number(value);\n return Number.isSafeInteger(line);\n}\n\nfunction safeFindingPath(value: string): boolean {\n if (\n value.trim().length === 0 ||\n value === \".\" ||\n isAbsolute(value) ||\n /^[A-Za-z]:/u.test(value) ||\n value.includes(\"\\\\\") ||\n /[\\u0000-\\u001F]/u.test(value) ||\n value.split(\"/\").includes(\"..\")\n ) {\n return false;\n }\n const normalized = posix.normalize(value).replace(/\\/+$/u, \"\");\n return normalized !== \".\" && !normalized.startsWith(\"../\");\n}\n\nfunction csvRowError(rowNumber: number, detail: string): CodexSecurityError {\n return new CodexSecurityError(`Findings CSV row ${rowNumber} ${detail}.`);\n}\n\nfunction sha256(value: string): string {\n return createHash(\"sha256\").update(value, \"utf8\").digest(\"hex\");\n}\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CodexSecurityConfig } from "./config.js";
|
|
2
|
+
import { ScanResult } from "./result.js";
|
|
3
|
+
import { resolvePluginPython, runWorkbench, type ProcessEnvironment } from "./runtime.js";
|
|
4
|
+
export interface ImportScanOptions {
|
|
5
|
+
sourcePath: string;
|
|
6
|
+
format: "csv" | "json";
|
|
7
|
+
config?: CodexSecurityConfig;
|
|
8
|
+
outputDir?: string;
|
|
9
|
+
archiveExisting?: boolean;
|
|
10
|
+
dryRun?: boolean;
|
|
11
|
+
parentScanId?: string;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}
|
|
14
|
+
export interface ImportScanPreview {
|
|
15
|
+
dryRun: true;
|
|
16
|
+
inputPath: string;
|
|
17
|
+
format: "csv" | "json";
|
|
18
|
+
findingCount: number;
|
|
19
|
+
}
|
|
20
|
+
export interface ImportScanDependencies {
|
|
21
|
+
environment?: ProcessEnvironment;
|
|
22
|
+
runWorkbench?: typeof runWorkbench;
|
|
23
|
+
resolvePluginPython?: typeof resolvePluginPython;
|
|
24
|
+
}
|
|
25
|
+
/** Save supplied findings through the normal scan completion and indexing flow. */
|
|
26
|
+
export declare function importScan(options: ImportScanOptions, dependencies?: ImportScanDependencies): Promise<ScanResult | ImportScanPreview>;
|
|
27
|
+
//# sourceMappingURL=import-scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-scan.d.ts","sourceRoot":"","sources":["../src/import-scan.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAWvD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAWL,mBAAmB,EACnB,YAAY,EAEZ,KAAK,kBAAkB,EAExB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,IAAI,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,KAAK,GAAG,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,kBAAkB,CAAC;IACjC,YAAY,CAAC,EAAE,OAAO,YAAY,CAAC;IACnC,mBAAmB,CAAC,EAAE,OAAO,mBAAmB,CAAC;CAClD;AAmDD,mFAAmF;AACnF,wBAAsB,UAAU,CAC9B,OAAO,EAAE,iBAAiB,EAC1B,YAAY,GAAE,sBAA2B,GACxC,OAAO,CAAC,UAAU,GAAG,iBAAiB,CAAC,CA0OzC"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { constants } from "node:fs";
|
|
3
|
+
import { lstat, mkdir, mkdtemp, open, readFile, realpath, writeFile, } from "node:fs/promises";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
6
|
+
import { loadContract, sameCheckedFileDevice } from "./contract.js";
|
|
7
|
+
import { CodexSecurityError, ScanInterruptedError, safeErrorMessage, } from "./errors.js";
|
|
8
|
+
import { bindImportedFindings, parseImportedFindings, } from "./findings-import.js";
|
|
9
|
+
import { ScanResult } from "./result.js";
|
|
10
|
+
import { cleanupSdkDirectory, codexSecurityStateDirectory, expandHome, pluginMetadata, prepareOutputDir, preparePersistentOutputRoot, requireOutputOutsideRepository, requirePrivateOutputDirectory, requireSecureOutputAncestry, resolvePluginPath, resolvePluginPython, runWorkbench, validateOutputDir, } from "./runtime.js";
|
|
11
|
+
const IMPORT_DESCRIPTION = "Imported findings; no security analysis was performed. Coverage is unknown. Source locations describe the imported reports.";
|
|
12
|
+
async function readImportSource(inputPath, signal) {
|
|
13
|
+
signal?.throwIfAborted();
|
|
14
|
+
const selected = await lstat(inputPath, { bigint: true });
|
|
15
|
+
if (!selected.isFile()) {
|
|
16
|
+
throw new CodexSecurityError("Import source must be a regular file.");
|
|
17
|
+
}
|
|
18
|
+
for (let parent = dirname(inputPath);; parent = dirname(parent)) {
|
|
19
|
+
signal?.throwIfAborted();
|
|
20
|
+
if ((await lstat(parent)).isSymbolicLink()) {
|
|
21
|
+
throw new CodexSecurityError("Import source must not traverse directory links. Use the direct filesystem path.");
|
|
22
|
+
}
|
|
23
|
+
if (dirname(parent) === parent)
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
const path = join(await realpath(dirname(inputPath)), basename(inputPath));
|
|
27
|
+
const file = await open(path, constants.O_RDONLY |
|
|
28
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
29
|
+
(constants.O_NONBLOCK ?? 0));
|
|
30
|
+
try {
|
|
31
|
+
signal?.throwIfAborted();
|
|
32
|
+
const opened = await file.stat({ bigint: true });
|
|
33
|
+
const current = await lstat(path, { bigint: true });
|
|
34
|
+
if (!opened.isFile() ||
|
|
35
|
+
!current.isFile() ||
|
|
36
|
+
current.dev !== selected.dev ||
|
|
37
|
+
current.ino !== selected.ino ||
|
|
38
|
+
!(await sameCheckedFileDevice(file, { path, metadata: selected }, opened))) {
|
|
39
|
+
throw new CodexSecurityError("Import source must remain the selected regular file.");
|
|
40
|
+
}
|
|
41
|
+
return await file.readFile({ signal });
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await file.close();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Save supplied findings through the normal scan completion and indexing flow. */
|
|
48
|
+
export async function importScan(options, dependencies = {}) {
|
|
49
|
+
const { signal } = options;
|
|
50
|
+
const environment = dependencies.environment ?? process.env;
|
|
51
|
+
const inputPath = resolve(expandHome(options.sourcePath, environment));
|
|
52
|
+
const source = await readImportSource(inputPath, signal);
|
|
53
|
+
const workspace = await mkdtemp(join(await realpath(tmpdir()), "codex-security-import-"));
|
|
54
|
+
const workbench = dependencies.runWorkbench ?? runWorkbench;
|
|
55
|
+
let activeScan;
|
|
56
|
+
let scanDir = "";
|
|
57
|
+
try {
|
|
58
|
+
const pluginRoot = await resolvePluginPath(options.config?.pluginPath, workspace, signal);
|
|
59
|
+
const findings = await parseImportedFindings(source.toString("utf8"), options.format, pluginRoot);
|
|
60
|
+
signal?.throwIfAborted();
|
|
61
|
+
await validateOutputDir(options.outputDir, options.archiveExisting);
|
|
62
|
+
if (options.dryRun) {
|
|
63
|
+
return {
|
|
64
|
+
dryRun: true,
|
|
65
|
+
inputPath,
|
|
66
|
+
format: options.format,
|
|
67
|
+
findingCount: findings.length,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const plugin = await pluginMetadata(pluginRoot);
|
|
71
|
+
const stateDirectory = codexSecurityStateDirectory(environment);
|
|
72
|
+
const digest = createHash("sha256")
|
|
73
|
+
.update(options.format)
|
|
74
|
+
.update("\0")
|
|
75
|
+
.update(source)
|
|
76
|
+
.digest("hex");
|
|
77
|
+
// A retained input directory is the scan target, independent of the caller's repository.
|
|
78
|
+
const repository = await preparePersistentOutputRoot(stateDirectory, "imports", `${options.format}-${digest}`);
|
|
79
|
+
requirePrivateOutputDirectory(await lstat(repository), repository);
|
|
80
|
+
await requireSecureOutputAncestry(repository);
|
|
81
|
+
const sourcePath = join(repository, `source.${options.format}`);
|
|
82
|
+
try {
|
|
83
|
+
await writeFile(sourcePath, source, { flag: "wx", signal });
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (error.code !== "EEXIST")
|
|
87
|
+
throw error;
|
|
88
|
+
if (!(await readFile(sourcePath, { signal })).equals(source)) {
|
|
89
|
+
throw new CodexSecurityError("The retained import source has changed.");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const python = await (dependencies.resolvePluginPython ?? resolvePluginPython)({
|
|
93
|
+
configuredPath: options.config?.pythonPath,
|
|
94
|
+
environment,
|
|
95
|
+
protectedRoot: repository,
|
|
96
|
+
signal,
|
|
97
|
+
});
|
|
98
|
+
const outputRoot = options.outputDir === undefined
|
|
99
|
+
? await preparePersistentOutputRoot(stateDirectory, "scans", "imports")
|
|
100
|
+
: undefined;
|
|
101
|
+
let archivedScanDir;
|
|
102
|
+
scanDir = await prepareOutputDir(options.outputDir, "import", outputRoot, (path) => requireOutputOutsideRepository(repository, path), options.archiveExisting, (path) => {
|
|
103
|
+
archivedScanDir = path;
|
|
104
|
+
});
|
|
105
|
+
const workbenchOptions = {
|
|
106
|
+
python,
|
|
107
|
+
pluginRoot,
|
|
108
|
+
environment: { ...environment, CODEX_SECURITY_STATE_DIR: stateDirectory },
|
|
109
|
+
signal,
|
|
110
|
+
failureMessage: "Could not save the imported scan",
|
|
111
|
+
};
|
|
112
|
+
const registration = await workbench(workbenchOptions, [
|
|
113
|
+
"register-cli-scan",
|
|
114
|
+
"--repository",
|
|
115
|
+
repository,
|
|
116
|
+
"--scan-dir",
|
|
117
|
+
scanDir,
|
|
118
|
+
"--registration-json-stdin",
|
|
119
|
+
...(options.archiveExisting ? ["--archive-existing"] : []),
|
|
120
|
+
...(archivedScanDir === undefined
|
|
121
|
+
? []
|
|
122
|
+
: ["--archived-scan-dir", archivedScanDir]),
|
|
123
|
+
...(options.parentScanId === undefined
|
|
124
|
+
? []
|
|
125
|
+
: ["--parent-scan-id", options.parentScanId]),
|
|
126
|
+
], JSON.stringify({
|
|
127
|
+
recipe: {
|
|
128
|
+
repository,
|
|
129
|
+
target: { kind: "repository", paths: [] },
|
|
130
|
+
mode: "standard",
|
|
131
|
+
pluginVersion: plugin.version,
|
|
132
|
+
config: {},
|
|
133
|
+
import: { format: options.format, sourcePath },
|
|
134
|
+
},
|
|
135
|
+
}));
|
|
136
|
+
const scanId = registration["scanId"];
|
|
137
|
+
const targetId = registration["targetId"];
|
|
138
|
+
if (typeof scanId !== "string" ||
|
|
139
|
+
typeof targetId !== "string" ||
|
|
140
|
+
registration["scanDir"] !== scanDir) {
|
|
141
|
+
throw new CodexSecurityError("The workbench returned an invalid import scan registration.");
|
|
142
|
+
}
|
|
143
|
+
activeScan = { id: scanId, options: workbenchOptions };
|
|
144
|
+
const bound = bindImportedFindings(findings, options.format, scanId, targetId);
|
|
145
|
+
const sourceRef = `artifacts/import/source.${options.format}`;
|
|
146
|
+
await mkdir(join(scanDir, "artifacts", "import"), { recursive: true });
|
|
147
|
+
await writeFile(join(scanDir, sourceRef), source, { flag: "wx", signal });
|
|
148
|
+
const documents = {
|
|
149
|
+
"scan-manifest.json": {
|
|
150
|
+
scan: {
|
|
151
|
+
target: { kind: "directory_snapshot" },
|
|
152
|
+
scope: {
|
|
153
|
+
summary: IMPORT_DESCRIPTION,
|
|
154
|
+
runtimeStatus: "imported",
|
|
155
|
+
limitations: [IMPORT_DESCRIPTION],
|
|
156
|
+
},
|
|
157
|
+
extensions: {
|
|
158
|
+
import: {
|
|
159
|
+
format: options.format,
|
|
160
|
+
sourceRef,
|
|
161
|
+
findingCount: findings.length,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
"findings.json": { findings: bound },
|
|
167
|
+
"coverage.json": {
|
|
168
|
+
completeness: "unknown",
|
|
169
|
+
inventoryStrategy: "custom",
|
|
170
|
+
surfaces: [
|
|
171
|
+
{
|
|
172
|
+
id: "import",
|
|
173
|
+
label: basename(inputPath),
|
|
174
|
+
disposition: "reported",
|
|
175
|
+
receiptRefs: [sourceRef],
|
|
176
|
+
notes: IMPORT_DESCRIPTION,
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
explicitExclusions: [],
|
|
180
|
+
deferred: [],
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
for (const [name, document] of Object.entries(documents)) {
|
|
184
|
+
await writeFile(join(scanDir, name), `${JSON.stringify(document, null, 2)}\n`, { flag: "wx", signal });
|
|
185
|
+
}
|
|
186
|
+
await workbench(workbenchOptions, [
|
|
187
|
+
"prepare-scan-completion",
|
|
188
|
+
"--scan-id",
|
|
189
|
+
scanId,
|
|
190
|
+
]);
|
|
191
|
+
// Finalization normally recovers partial output. An import must retain every supplied row.
|
|
192
|
+
const contract = await loadContract(scanDir, {
|
|
193
|
+
pluginRoot,
|
|
194
|
+
expectedScanId: scanId,
|
|
195
|
+
workbenchValidated: true,
|
|
196
|
+
signal,
|
|
197
|
+
});
|
|
198
|
+
const expectedIds = new Set(bound.map((finding) => finding.findingId));
|
|
199
|
+
if (contract.findings.findings.length !== findings.length ||
|
|
200
|
+
contract.findings.findings.some((finding) => !expectedIds.delete(finding.findingId)) ||
|
|
201
|
+
expectedIds.size !== 0) {
|
|
202
|
+
throw new CodexSecurityError("Import finalization did not preserve every input finding; the scan was not completed.");
|
|
203
|
+
}
|
|
204
|
+
await workbench(workbenchOptions, ["complete-scan", "--scan-id", scanId]);
|
|
205
|
+
activeScan = undefined;
|
|
206
|
+
return new ScanResult({
|
|
207
|
+
...contract,
|
|
208
|
+
scanDir,
|
|
209
|
+
threadId: "",
|
|
210
|
+
turnResult: {
|
|
211
|
+
status: "completed",
|
|
212
|
+
imported: true,
|
|
213
|
+
finalResponse: IMPORT_DESCRIPTION,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (activeScan !== undefined) {
|
|
219
|
+
await workbench({ ...activeScan.options, signal: undefined }, [
|
|
220
|
+
"fail-scan",
|
|
221
|
+
"--scan-id",
|
|
222
|
+
activeScan.id,
|
|
223
|
+
"--message",
|
|
224
|
+
safeErrorMessage(error).slice(0, 2400),
|
|
225
|
+
]).catch(() => undefined);
|
|
226
|
+
}
|
|
227
|
+
if (signal?.aborted) {
|
|
228
|
+
throw new ScanInterruptedError("Codex Security import was interrupted.", scanDir, { cause: error });
|
|
229
|
+
}
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
await cleanupSdkDirectory(workspace);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=import-scan.js.map
|