@openai/codex-security 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -10
- package/_bundled_plugin/.codex-plugin/plugin.json +1 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-000 +0 -0
- package/_bundled_plugin/mcp/helpers.mjs.br.part-001 +0 -0
- package/_bundled_plugin/mcp/native/THIRD_PARTY_NOTICES.txt +4 -4
- 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/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/mcp/server.mjs.br.part-002 +0 -0
- package/_bundled_plugin/references/scan-artifacts.md +1 -1
- package/_bundled_plugin/scripts/finalize_scan_contract.py +37 -1
- package/_bundled_plugin/scripts/servicenow_avit.py +107 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +0 -17
- package/_bundled_plugin/scripts/workbench_db.py +1 -3
- package/_bundled_plugin/scripts/workbench_saved_results.py +0 -66
- package/_bundled_plugin/scripts/workbench_scan_start.py +4 -1
- package/_bundled_plugin/scripts/workbench_target.py +0 -108
- package/_bundled_plugin/skills/publish-findings/SKILL.md +9 -3
- package/_bundled_plugin/skills/resolve-dependency-alert/SKILL.md +18 -0
- package/_bundled_plugin/skills/resolve-dependency-alert/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/security-scan/SKILL.md +1 -1
- package/_bundled_plugin/skills/threat-model-visualize/SKILL.md +83 -0
- package/_bundled_plugin/skills/threat-model-visualize/agents/openai.yaml +4 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-overview.svg +366 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/context-reference-path.svg +558 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/control-effects.js +85 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.css +17 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.html +38 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/explorer.js +372 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/route-paths.js +71 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/source-roles.js +47 -0
- package/_bundled_plugin/skills/threat-model-visualize/assets/svg-layout.js +149 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/context-explorer.md +21 -0
- package/_bundled_plugin/skills/threat-model-visualize/references/view-model.md +49 -0
- package/_bundled_plugin/skills/threat-model-visualize/scripts/build_explorer.py +563 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +36 -15
- package/dist/api.js.map +1 -1
- package/dist/artifact-export.d.ts +12 -3
- package/dist/artifact-export.d.ts.map +1 -1
- package/dist/artifact-export.js +30 -10
- package/dist/artifact-export.js.map +1 -1
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli-help.d.ts.map +1 -1
- package/dist/cli-help.js +1 -0
- package/dist/cli-help.js.map +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +72 -50
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts +1 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +16 -12
- package/dist/contract.js.map +1 -1
- package/dist/custom-validation-prompt.d.ts.map +1 -1
- package/dist/custom-validation-prompt.js +12 -4
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.js +2 -2
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/deduplication-reviewer.d.ts.map +1 -1
- package/dist/deduplication/deduplication-reviewer.js +1 -1
- package/dist/deduplication/deduplication-reviewer.js.map +1 -1
- package/dist/deduplication/records-protocol.d.ts.map +1 -1
- package/dist/deduplication/records-protocol.js +36 -22
- package/dist/deduplication/records-protocol.js.map +1 -1
- package/dist/deduplication/records.d.ts +3 -1
- package/dist/deduplication/records.d.ts.map +1 -1
- package/dist/deduplication/records.js +12 -8
- package/dist/deduplication/records.js.map +1 -1
- package/dist/endor-findings.d.ts.map +1 -1
- package/dist/endor-findings.js +46 -61
- package/dist/endor-findings.js.map +1 -1
- package/dist/external-findings-import.d.ts.map +1 -1
- package/dist/external-findings-import.js +8 -6
- package/dist/external-findings-import.js.map +1 -1
- package/dist/external-findings-local.d.ts +3 -1
- package/dist/external-findings-local.d.ts.map +1 -1
- package/dist/external-findings-local.js +136 -36
- package/dist/external-findings-local.js.map +1 -1
- package/dist/external-findings-publish.d.ts +3 -1
- package/dist/external-findings-publish.d.ts.map +1 -1
- package/dist/external-findings-publish.js +56 -31
- package/dist/external-findings-publish.js.map +1 -1
- package/dist/external-findings-read.d.ts +2 -0
- package/dist/external-findings-read.d.ts.map +1 -1
- package/dist/external-findings-read.js +9 -0
- package/dist/external-findings-read.js.map +1 -1
- package/dist/external-findings.d.ts +11 -0
- package/dist/external-findings.d.ts.map +1 -1
- package/dist/external-findings.js +13 -1
- package/dist/external-findings.js.map +1 -1
- package/dist/external-import-models.d.ts +1 -1
- package/dist/external-import-models.d.ts.map +1 -1
- package/dist/external-import-models.js.map +1 -1
- package/dist/github-advisories.d.ts.map +1 -1
- package/dist/github-advisories.js +5 -5
- package/dist/github-advisories.js.map +1 -1
- package/dist/github-dependabot-findings.d.ts +6 -0
- package/dist/github-dependabot-findings.d.ts.map +1 -0
- package/dist/github-dependabot-findings.js +247 -0
- package/dist/github-dependabot-findings.js.map +1 -0
- package/dist/github-findings.d.ts.map +1 -1
- package/dist/github-findings.js +11 -4
- package/dist/github-findings.js.map +1 -1
- package/dist/github-identifiers.d.ts +4 -0
- package/dist/github-identifiers.d.ts.map +1 -0
- package/dist/github-identifiers.js +9 -0
- package/dist/github-identifiers.js.map +1 -0
- package/dist/github.d.ts.map +1 -1
- package/dist/github.js +4 -6
- package/dist/github.js.map +1 -1
- package/dist/host-protocol.d.ts +5 -0
- package/dist/host-protocol.d.ts.map +1 -1
- package/dist/host-protocol.js +27 -3
- package/dist/host-protocol.js.map +1 -1
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +13 -5
- package/dist/hosted-scan.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/inspector-findings.d.ts +9 -0
- package/dist/inspector-findings.d.ts.map +1 -0
- package/dist/inspector-findings.js +517 -0
- package/dist/inspector-findings.js.map +1 -0
- package/dist/patch-tui.d.ts +1 -1
- package/dist/patch-tui.d.ts.map +1 -1
- package/dist/patch-tui.js +4 -1
- package/dist/patch-tui.js.map +1 -1
- package/dist/runtime.d.ts +3 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +15 -5
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +25 -15
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scanner-import.d.ts +6 -2
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +23 -14
- package/dist/scanner-import.js.map +1 -1
- package/dist/semgrep-findings.d.ts.map +1 -1
- package/dist/semgrep-findings.js +39 -49
- package/dist/semgrep-findings.js.map +1 -1
- package/dist/snyk-findings.d.ts.map +1 -1
- package/dist/snyk-findings.js +78 -88
- package/dist/snyk-findings.js.map +1 -1
- package/docs/cli.md +52 -14
- package/docs/dedupe-records.md +17 -4
- package/docs/hosted-scans.md +14 -0
- package/package.json +5 -5
- package/schemas/external-findings.schema.json +1 -1
package/dist/endor-findings.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validateExternalEvidence } from "./external-import-contract.js";
|
|
2
2
|
import { isRecord } from "./record.js";
|
|
3
|
-
import { array, hasSarifExternalPropertyReferences, normalizeRecords, readScannerJson, record, relativePath, requiredText, sarifRunContextForResult, strings, text, } from "./scanner-import.js";
|
|
3
|
+
import { array, hasSarifExternalPropertyReferences, indexSarifRules, normalizeRecords, readScannerJson, record, relativePath, requiredText, sarifRunContextForResult, strings, text, } from "./scanner-import.js";
|
|
4
4
|
/** @internal Repository claims retained in the adapter's original SARIF context. */
|
|
5
5
|
export function endorRepositoryUrls(sourceData) {
|
|
6
6
|
if (!isRecord(sourceData))
|
|
@@ -29,7 +29,7 @@ export function normalizeEndorFindings(input, target = "cloud") {
|
|
|
29
29
|
: Array.isArray(input)
|
|
30
30
|
? input
|
|
31
31
|
: [input];
|
|
32
|
-
return normalizeRecords(values, (value
|
|
32
|
+
return normalizeRecords(values, (value) => {
|
|
33
33
|
const finding = record(value, "Endor finding");
|
|
34
34
|
const meta = record(finding["meta"], "Endor meta");
|
|
35
35
|
const spec = record(finding["spec"], "Endor spec");
|
|
@@ -86,31 +86,26 @@ export function normalizeEndorFindings(input, target = "cloud") {
|
|
|
86
86
|
: [];
|
|
87
87
|
const context = record(finding["context"] ?? {}, "Endor context");
|
|
88
88
|
const updated = text(meta["update_time"]);
|
|
89
|
-
return {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
]
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
packages,
|
|
110
|
-
locations,
|
|
111
|
-
source_data: structuredClone(finding),
|
|
112
|
-
}, target),
|
|
113
|
-
};
|
|
89
|
+
return validateExternalEvidence({
|
|
90
|
+
title: requiredText(meta["name"], "Endor finding title"),
|
|
91
|
+
description: [
|
|
92
|
+
text(spec["summary"]),
|
|
93
|
+
text(spec["explanation"]),
|
|
94
|
+
text(spec["remediation"]),
|
|
95
|
+
]
|
|
96
|
+
.filter(Boolean)
|
|
97
|
+
.join("\n\n") || text(meta["description"]),
|
|
98
|
+
severity,
|
|
99
|
+
branch: context["type"] === "CONTEXT_TYPE_REF" ? text(context["id"]) : null,
|
|
100
|
+
code_revision: text(record(spec["source_code_version"] ?? {}, "Endor source code version")["sha"]),
|
|
101
|
+
source_updated_at: updated === null ? null : Math.floor(Date.parse(updated) / 1000),
|
|
102
|
+
advisory_ids: [
|
|
103
|
+
...new Set([...(advisory ? [advisory] : []), ...aliases]),
|
|
104
|
+
],
|
|
105
|
+
packages,
|
|
106
|
+
locations,
|
|
107
|
+
source_data: structuredClone(finding),
|
|
108
|
+
}, target);
|
|
114
109
|
}, (value) => requiredText(record(value, "Endor finding")["uuid"], "Endor finding uuid"), target);
|
|
115
110
|
}
|
|
116
111
|
/** Endor's documented SARIF producer uses properties.finding-uuid, not its rule name. */
|
|
@@ -127,11 +122,7 @@ export function normalizeEndorSarif(input, target = "cloud") {
|
|
|
127
122
|
if (hasSarifExternalPropertyReferences(run["externalPropertyFileReferences"]))
|
|
128
123
|
throw new Error("Use a self-contained Endor SARIF report.");
|
|
129
124
|
const rules = array(driver["rules"] ?? [], "Endor rules").map((r) => record(r, "Endor rule"));
|
|
130
|
-
const rulesById =
|
|
131
|
-
for (const [index, rule] of rules.entries()) {
|
|
132
|
-
const id = rule["id"];
|
|
133
|
-
rulesById.set(id, rulesById.has(id) ? null : { rule, index });
|
|
134
|
-
}
|
|
125
|
+
const rulesById = indexSarifRules(rules);
|
|
135
126
|
const { runs: _runs, ...documentContext } = document;
|
|
136
127
|
const { results: _results, tool: _tool, ...runContext } = run;
|
|
137
128
|
const { rules: _rules, ...driverContext } = driver;
|
|
@@ -145,7 +136,7 @@ export function normalizeEndorSarif(input, target = "cloud") {
|
|
|
145
136
|
toolContext,
|
|
146
137
|
}));
|
|
147
138
|
});
|
|
148
|
-
return normalizeRecords(entries, ({ result: value, rulesById, ...context }
|
|
139
|
+
return normalizeRecords(entries, ({ result: value, rulesById, ...context }) => {
|
|
149
140
|
const result = record(value, "Endor result");
|
|
150
141
|
const properties = record(result["properties"], "Endor result properties");
|
|
151
142
|
requiredText(properties["project-uuid"], "Endor project-uuid");
|
|
@@ -202,34 +193,28 @@ export function normalizeEndorSarif(input, target = "cloud") {
|
|
|
202
193
|
},
|
|
203
194
|
];
|
|
204
195
|
});
|
|
205
|
-
return {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
runContext: sarifRunContextForResult(context.runContext, result, rule, context.documentContext, context.driverContext, context.toolContext),
|
|
228
|
-
rule,
|
|
229
|
-
result,
|
|
230
|
-
}),
|
|
231
|
-
}, target),
|
|
232
|
-
};
|
|
196
|
+
return validateExternalEvidence({
|
|
197
|
+
title: text(short["text"]) ?? text(rule["name"]) ?? ruleId,
|
|
198
|
+
url: text(properties["finding-url"]),
|
|
199
|
+
description: [
|
|
200
|
+
text(message["markdown"]) ?? text(message["text"]),
|
|
201
|
+
text(full["text"]),
|
|
202
|
+
text(help["markdown"]) ?? text(help["text"]),
|
|
203
|
+
]
|
|
204
|
+
.filter(Boolean)
|
|
205
|
+
.join("\n\n"),
|
|
206
|
+
// Diagnostic level and CVSS are not Endor's finding severity. Keep both as source evidence.
|
|
207
|
+
severity: "unknown",
|
|
208
|
+
locations: [
|
|
209
|
+
...new Map(locations.map((location) => [JSON.stringify(location), location])).values(),
|
|
210
|
+
],
|
|
211
|
+
source_data: structuredClone({
|
|
212
|
+
...context,
|
|
213
|
+
runContext: sarifRunContextForResult(context.runContext, result, rule, context.documentContext, context.driverContext, context.toolContext),
|
|
214
|
+
rule,
|
|
215
|
+
result,
|
|
216
|
+
}),
|
|
217
|
+
}, target);
|
|
233
218
|
}, ({ result }) => requiredText(record(record(result, "Endor result")["properties"], "Endor result properties")["finding-uuid"], "Endor finding-uuid"), target);
|
|
234
219
|
}
|
|
235
220
|
export async function readEndorFindings(path, target = "cloud") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endor-findings.js","sourceRoot":"","sources":["../src/endor-findings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,kCAAkC,EAClC,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,wBAAwB,EACxB,OAAO,EACP,IAAI,GACL,MAAM,qBAAqB,CAAC;AAE7B,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,UAAmB;IACrD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,GAAG,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACrC,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC3B,OAAO,KAAK,CACV,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC,0BAA0B,CAAC,IAAI,EAAE,EAClE,kCAAkC,CACnC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACd,YAAY,CACV,MAAM,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC,eAAe,CAAC,EAC7D,sBAAsB,CACvB,CACF,CAAC;AACJ,CAAC;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C1B,CAAC,cAAc,CAAC,EACjB,oBAAoB,CACrB,EACH,MAAM,CACP,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,MAAM,GAAyB,OAAO;IAEtC,OAAO,sBAAsB,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n hasSarifExternalPropertyReferences,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n sarifRunContextForResult,\n strings,\n text,\n} from \"./scanner-import.js\";\n\n/** @internal Repository claims retained in the adapter's original SARIF context. */\nexport function endorRepositoryUrls(sourceData: unknown): string[] {\n if (!isRecord(sourceData)) return [];\n const run = sourceData[\"runContext\"];\n if (run == null) return [];\n return array(\n record(run, \"Endor run context\")[\"versionControlProvenance\"] ?? [],\n \"Endor version control provenance\",\n ).map((entry) =>\n requiredText(\n record(entry, \"Endor repository provenance\")[\"repositoryUri\"],\n \"Endor repository URI\",\n ),\n );\n}\n\n/** Saved Endor Finding objects, an array, or an unmasked ListFindingsResponse. */\nexport function normalizeEndorFindings(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const root = Array.isArray(input) ? null : record(input, \"Endor report\");\n if (root?.[\"version\"] === \"2.1.0\" && root[\"runs\"] !== undefined)\n return normalizeEndorSarif(root, target);\n const list =\n root?.[\"list\"] === undefined ? null : record(root[\"list\"], \"Endor list\");\n if (list) {\n const response = record(list[\"response\"] ?? {}, \"Endor list response\");\n const token = response[\"next_page_token\"];\n if (\n text(response[\"next_page_id\"]) ||\n (token != null && token !== 0 && token !== \"0\" && token !== \"\")\n ) {\n throw new Error(\n \"The Endor list response has another page. Supply a complete export or an explicitly selected array.\",\n );\n }\n }\n const values = list\n ? array(list[\"objects\"] ?? [], \"Endor list.objects\")\n : Array.isArray(input)\n ? input\n : [input];\n return normalizeRecords(\n values,\n (value, id) => {\n const finding = record(value, \"Endor finding\");\n const meta = record(finding[\"meta\"], \"Endor meta\");\n const spec = record(finding[\"spec\"], \"Endor spec\");\n requiredText(spec[\"project_uuid\"], \"Endor project_uuid\");\n const name = text(spec[\"target_dependency_name\"]);\n const paths = [\n ...new Set(\n strings(spec[\"dependency_file_paths\"])\n .map(relativePath)\n .filter((p): p is string => p !== null),\n ),\n ];\n const metadata = record(\n spec[\"finding_metadata\"] ?? {},\n \"Endor finding_metadata\",\n );\n const codeLocations = [\"sast_data\", \"ai_sast_data\"].flatMap((field) => {\n const data = record(metadata[field] ?? {}, `Endor ${field}`);\n const location = record(\n data[\"location\"] ?? {},\n `Endor ${field} location`,\n );\n const path = relativePath(location[\"relative_path\"]);\n if (path === null) return [];\n const line = location[\"start_line\"];\n return [\n {\n path,\n line:\n typeof line === \"number\" && Number.isSafeInteger(line) && line > 0\n ? line\n : null,\n },\n ];\n });\n const locations = [\n ...paths\n .filter(\n (path) => !codeLocations.some((location) => location.path === path),\n )\n .map((path) => ({ path })),\n ...new Map(\n codeLocations.map((location) => [JSON.stringify(location), location]),\n ).values(),\n ];\n const vulnerability = record(\n metadata[\"vulnerability\"] ?? {},\n \"Endor vulnerability\",\n );\n const advisory = text(\n record(vulnerability[\"meta\"] ?? {}, \"Vulnerability meta\")[\"name\"],\n );\n const aliases = strings(\n record(vulnerability[\"spec\"] ?? {}, \"Vulnerability spec\")[\"aliases\"],\n );\n const level = text(spec[\"level\"])\n ?.replace(/^FINDING_LEVEL_/u, \"\")\n .toLowerCase();\n const severity =\n level && [\"critical\", \"high\", \"medium\", \"low\"].includes(level)\n ? level\n : \"unknown\";\n // A recommended version can refer to an introducing dependency; retain it in source_data.\n const packages = name\n ? (paths.length ? paths : [null]).map((path) => ({\n name,\n ecosystem:\n text(spec[\"ecosystem\"])\n ?.replace(/^ECOSYSTEM_/u, \"\")\n .toLowerCase() ?? null,\n installed_version: text(spec[\"target_dependency_version\"]),\n manifest_path: path,\n fixed_versions: [],\n }))\n : [];\n const context = record(finding[\"context\"] ?? {}, \"Endor context\");\n const updated = text(meta[\"update_time\"]);\n return {\n source_finding_id: id,\n evidence: validateExternalEvidence(\n {\n title: requiredText(meta[\"name\"], \"Endor finding title\"),\n description:\n [\n text(spec[\"summary\"]),\n text(spec[\"explanation\"]),\n text(spec[\"remediation\"]),\n ]\n .filter(Boolean)\n .join(\"\\n\\n\") || text(meta[\"description\"]),\n severity,\n branch:\n context[\"type\"] === \"CONTEXT_TYPE_REF\"\n ? text(context[\"id\"])\n : null,\n code_revision: text(\n record(\n spec[\"source_code_version\"] ?? {},\n \"Endor source code version\",\n )[\"sha\"],\n ),\n source_updated_at:\n updated === null ? null : Math.floor(Date.parse(updated) / 1000),\n advisory_ids: [\n ...new Set([...(advisory ? [advisory] : []), ...aliases]),\n ],\n packages,\n locations,\n source_data: structuredClone(finding),\n },\n target,\n ),\n };\n },\n (value) =>\n requiredText(\n record(value, \"Endor finding\")[\"uuid\"],\n \"Endor finding uuid\",\n ),\n target,\n );\n}\n\n/** Endor's documented SARIF producer uses properties.finding-uuid, not its rule name. */\nexport function normalizeEndorSarif(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Endor SARIF\");\n if (document[\"version\"] !== \"2.1.0\")\n throw new Error(\"Expected Endor SARIF 2.1.0.\");\n const entries = array(document[\"runs\"], \"SARIF runs\").flatMap((value) => {\n const run = record(value, \"SARIF run\");\n const tool = record(run[\"tool\"], \"SARIF tool\");\n const driver = record(tool[\"driver\"], \"SARIF driver\");\n if (driver[\"name\"] !== \"endorctl\")\n throw new Error(\"Expected the endorctl SARIF producer.\");\n if (\n hasSarifExternalPropertyReferences(run[\"externalPropertyFileReferences\"])\n )\n throw new Error(\"Use a self-contained Endor SARIF report.\");\n const rules = array(driver[\"rules\"] ?? [], \"Endor rules\").map((r) =>\n record(r, \"Endor rule\"),\n );\n const rulesById = new Map<\n unknown,\n { rule: Record<string, unknown>; index: number } | null\n >();\n for (const [index, rule] of rules.entries()) {\n const id = rule[\"id\"];\n rulesById.set(id, rulesById.has(id) ? null : { rule, index });\n }\n const { runs: _runs, ...documentContext } = document;\n const { results: _results, tool: _tool, ...runContext } = run;\n const { rules: _rules, ...driverContext } = driver;\n const { driver: _driver, ...toolContext } = tool;\n return array(run[\"results\"] ?? [], \"Endor results\").map((result) => ({\n result,\n rulesById,\n documentContext,\n runContext,\n driverContext,\n toolContext,\n }));\n });\n return normalizeRecords(\n entries,\n ({ result: value, rulesById, ...context }, id) => {\n const result = record(value, \"Endor result\");\n const properties = record(\n result[\"properties\"],\n \"Endor result properties\",\n );\n requiredText(properties[\"project-uuid\"], \"Endor project-uuid\");\n const ruleId = requiredText(result[\"ruleId\"], \"Endor ruleId\");\n const selectedRule = rulesById.get(ruleId);\n if (!selectedRule)\n throw new Error(\n \"Endor result must reference exactly one rule in its run.\",\n );\n const { rule, index: ruleIndex } = selectedRule;\n if (\n result[\"ruleIndex\"] !== undefined &&\n result[\"ruleIndex\"] !== ruleIndex\n )\n throw new Error(\"Endor ruleIndex and ruleId disagree.\");\n if (result[\"rule\"] !== undefined) {\n const reference = record(result[\"rule\"], \"Endor rule reference\");\n if (\n reference[\"toolComponent\"] !== undefined ||\n (reference[\"id\"] !== undefined && reference[\"id\"] !== ruleId) ||\n (reference[\"index\"] !== undefined &&\n reference[\"index\"] !== ruleIndex) ||\n (reference[\"guid\"] !== undefined &&\n reference[\"guid\"] !== rule[\"guid\"])\n )\n throw new Error(\"Inconsistent or external Endor rule reference.\");\n }\n const message = record(result[\"message\"], \"Endor message\");\n const short = record(\n rule[\"shortDescription\"] ?? {},\n \"Endor shortDescription\",\n );\n const full = record(\n rule[\"fullDescription\"] ?? {},\n \"Endor fullDescription\",\n );\n const help = record(rule[\"help\"] ?? {}, \"Endor help\");\n const hasCodeLocations = strings(properties[\"categories\"]).some(\n (category) => category === \"SAST\" || category === \"SECRETS\",\n );\n const locations = array(\n result[\"locations\"] ?? [],\n \"Endor locations\",\n ).flatMap((v) => {\n const physical = record(\n record(v, \"Endor location\")[\"physicalLocation\"] ?? {},\n \"Physical location\",\n );\n const artifact = record(\n physical[\"artifactLocation\"] ?? {},\n \"Artifact location\",\n );\n if (\n artifact[\"index\"] !== undefined ||\n artifact[\"uriBaseId\"] !== undefined\n )\n return [];\n const uri = text(artifact[\"uri\"]);\n if (uri === null || /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(uri)) return [];\n let path: string | null;\n try {\n path = relativePath(decodeURIComponent(uri));\n } catch {\n return [];\n }\n if (path === null) return [];\n const line = hasCodeLocations\n ? record(physical[\"region\"] ?? {}, \"Endor region\")[\"startLine\"]\n : null;\n return [\n {\n path,\n line:\n typeof line === \"number\" && Number.isSafeInteger(line) && line > 0\n ? line\n : null,\n },\n ];\n });\n return {\n source_finding_id: id,\n evidence: validateExternalEvidence(\n {\n title: text(short[\"text\"]) ?? text(rule[\"name\"]) ?? ruleId,\n url: text(properties[\"finding-url\"]),\n description: [\n text(message[\"markdown\"]) ?? text(message[\"text\"]),\n text(full[\"text\"]),\n text(help[\"markdown\"]) ?? text(help[\"text\"]),\n ]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n // Diagnostic level and CVSS are not Endor's finding severity. Keep both as source evidence.\n severity: \"unknown\",\n locations: [\n ...new Map(\n locations.map((location) => [\n JSON.stringify(location),\n location,\n ]),\n ).values(),\n ],\n source_data: structuredClone({\n ...context,\n runContext: sarifRunContextForResult(\n context.runContext,\n result,\n rule,\n context.documentContext,\n context.driverContext,\n context.toolContext,\n ),\n rule,\n result,\n }),\n },\n target,\n ),\n };\n },\n ({ result }) =>\n requiredText(\n record(\n record(result, \"Endor result\")[\"properties\"],\n \"Endor result properties\",\n )[\"finding-uuid\"],\n \"Endor finding-uuid\",\n ),\n target,\n );\n}\n\nexport async function readEndorFindings(\n path: string,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeEndorFindings(await readScannerJson(path), target);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"endor-findings.js","sourceRoot":"","sources":["../src/endor-findings.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EACL,KAAK,EACL,kCAAkC,EAClC,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,wBAAwB,EACxB,OAAO,EACP,IAAI,GACL,MAAM,qBAAqB,CAAC;AAE7B,oFAAoF;AACpF,MAAM,UAAU,mBAAmB,CAAC,UAAmB;IACrD,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,GAAG,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IACrC,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,EAAE,CAAC;IAC3B,OAAO,KAAK,CACV,MAAM,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC,0BAA0B,CAAC,IAAI,EAAE,EAClE,kCAAkC,CACnC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACd,YAAY,CACV,MAAM,CAAC,KAAK,EAAE,6BAA6B,CAAC,CAAC,eAAe,CAAC,EAC7D,sBAAsB,CACvB,CACF,CAAC;AACJ,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,sBAAsB,CACpC,KAAc,EACd,MAAM,GAAyB,OAAO;IAEtC,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACzE,IAAI,IAAI,EAAE,CAAC,SAAS,CAAC,KAAK,OAAO,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,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC,CAClE,CAAC,MAAM,EAAE;aACX;YACD,WAAW,EAAE,eAAe,CAAC;gBAC3B,GAAG,OAAO;gBACV,UAAU,EAAE,wBAAwB,CAClC,OAAO,CAAC,UAAU,EAClB,MAAM,EACN,IAAI,EACJ,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,WAAW,CACpB;gBACD,IAAI;gBACJ,MAAM;aACP,CAAC;SACH,EACD,MAAM,CACP,CAAC;IACJ,CAAC,EACD,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,CACb,YAAY,CACV,MAAM,CACJ,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,YAAY,CAAC,EAC5C,yBAAyB,CAC1B,CAAC,cAAc,CAAC,EACjB,oBAAoB,CACrB,EACH,MAAM,CACP,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,MAAM,GAAyB,OAAO;IAEtC,OAAO,sBAAsB,CAAC,MAAM,eAAe,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import type { ExternalImportTarget } from \"./external-import-contract.js\";\nimport { validateExternalEvidence } from \"./external-import-contract.js\";\nimport type { ExternalFindings } from \"./external-findings.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n array,\n hasSarifExternalPropertyReferences,\n indexSarifRules,\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n sarifRunContextForResult,\n strings,\n text,\n} from \"./scanner-import.js\";\n\n/** @internal Repository claims retained in the adapter's original SARIF context. */\nexport function endorRepositoryUrls(sourceData: unknown): string[] {\n if (!isRecord(sourceData)) return [];\n const run = sourceData[\"runContext\"];\n if (run == null) return [];\n return array(\n record(run, \"Endor run context\")[\"versionControlProvenance\"] ?? [],\n \"Endor version control provenance\",\n ).map((entry) =>\n requiredText(\n record(entry, \"Endor repository provenance\")[\"repositoryUri\"],\n \"Endor repository URI\",\n ),\n );\n}\n\n/** Saved Endor Finding objects, an array, or an unmasked ListFindingsResponse. */\nexport function normalizeEndorFindings(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const root = Array.isArray(input) ? null : record(input, \"Endor report\");\n if (root?.[\"version\"] === \"2.1.0\" && root[\"runs\"] !== undefined)\n return normalizeEndorSarif(root, target);\n const list =\n root?.[\"list\"] === undefined ? null : record(root[\"list\"], \"Endor list\");\n if (list) {\n const response = record(list[\"response\"] ?? {}, \"Endor list response\");\n const token = response[\"next_page_token\"];\n if (\n text(response[\"next_page_id\"]) ||\n (token != null && token !== 0 && token !== \"0\" && token !== \"\")\n ) {\n throw new Error(\n \"The Endor list response has another page. Supply a complete export or an explicitly selected array.\",\n );\n }\n }\n const values = list\n ? array(list[\"objects\"] ?? [], \"Endor list.objects\")\n : Array.isArray(input)\n ? input\n : [input];\n return normalizeRecords(\n values,\n (value) => {\n const finding = record(value, \"Endor finding\");\n const meta = record(finding[\"meta\"], \"Endor meta\");\n const spec = record(finding[\"spec\"], \"Endor spec\");\n requiredText(spec[\"project_uuid\"], \"Endor project_uuid\");\n const name = text(spec[\"target_dependency_name\"]);\n const paths = [\n ...new Set(\n strings(spec[\"dependency_file_paths\"])\n .map(relativePath)\n .filter((p): p is string => p !== null),\n ),\n ];\n const metadata = record(\n spec[\"finding_metadata\"] ?? {},\n \"Endor finding_metadata\",\n );\n const codeLocations = [\"sast_data\", \"ai_sast_data\"].flatMap((field) => {\n const data = record(metadata[field] ?? {}, `Endor ${field}`);\n const location = record(\n data[\"location\"] ?? {},\n `Endor ${field} location`,\n );\n const path = relativePath(location[\"relative_path\"]);\n if (path === null) return [];\n const line = location[\"start_line\"];\n return [\n {\n path,\n line:\n typeof line === \"number\" && Number.isSafeInteger(line) && line > 0\n ? line\n : null,\n },\n ];\n });\n const locations = [\n ...paths\n .filter(\n (path) => !codeLocations.some((location) => location.path === path),\n )\n .map((path) => ({ path })),\n ...new Map(\n codeLocations.map((location) => [JSON.stringify(location), location]),\n ).values(),\n ];\n const vulnerability = record(\n metadata[\"vulnerability\"] ?? {},\n \"Endor vulnerability\",\n );\n const advisory = text(\n record(vulnerability[\"meta\"] ?? {}, \"Vulnerability meta\")[\"name\"],\n );\n const aliases = strings(\n record(vulnerability[\"spec\"] ?? {}, \"Vulnerability spec\")[\"aliases\"],\n );\n const level = text(spec[\"level\"])\n ?.replace(/^FINDING_LEVEL_/u, \"\")\n .toLowerCase();\n const severity =\n level && [\"critical\", \"high\", \"medium\", \"low\"].includes(level)\n ? level\n : \"unknown\";\n // A recommended version can refer to an introducing dependency; retain it in source_data.\n const packages = name\n ? (paths.length ? paths : [null]).map((path) => ({\n name,\n ecosystem:\n text(spec[\"ecosystem\"])\n ?.replace(/^ECOSYSTEM_/u, \"\")\n .toLowerCase() ?? null,\n installed_version: text(spec[\"target_dependency_version\"]),\n manifest_path: path,\n fixed_versions: [],\n }))\n : [];\n const context = record(finding[\"context\"] ?? {}, \"Endor context\");\n const updated = text(meta[\"update_time\"]);\n return validateExternalEvidence(\n {\n title: requiredText(meta[\"name\"], \"Endor finding title\"),\n description:\n [\n text(spec[\"summary\"]),\n text(spec[\"explanation\"]),\n text(spec[\"remediation\"]),\n ]\n .filter(Boolean)\n .join(\"\\n\\n\") || text(meta[\"description\"]),\n severity,\n branch:\n context[\"type\"] === \"CONTEXT_TYPE_REF\" ? text(context[\"id\"]) : null,\n code_revision: text(\n record(\n spec[\"source_code_version\"] ?? {},\n \"Endor source code version\",\n )[\"sha\"],\n ),\n source_updated_at:\n updated === null ? null : Math.floor(Date.parse(updated) / 1000),\n advisory_ids: [\n ...new Set([...(advisory ? [advisory] : []), ...aliases]),\n ],\n packages,\n locations,\n source_data: structuredClone(finding),\n },\n target,\n );\n },\n (value) =>\n requiredText(\n record(value, \"Endor finding\")[\"uuid\"],\n \"Endor finding uuid\",\n ),\n target,\n );\n}\n\n/** Endor's documented SARIF producer uses properties.finding-uuid, not its rule name. */\nexport function normalizeEndorSarif(\n input: unknown,\n target: ExternalImportTarget = \"cloud\",\n): ExternalFindings {\n const document = record(input, \"Endor SARIF\");\n if (document[\"version\"] !== \"2.1.0\")\n throw new Error(\"Expected Endor SARIF 2.1.0.\");\n const entries = array(document[\"runs\"], \"SARIF runs\").flatMap((value) => {\n const run = record(value, \"SARIF run\");\n const tool = record(run[\"tool\"], \"SARIF tool\");\n const driver = record(tool[\"driver\"], \"SARIF driver\");\n if (driver[\"name\"] !== \"endorctl\")\n throw new Error(\"Expected the endorctl SARIF producer.\");\n if (\n hasSarifExternalPropertyReferences(run[\"externalPropertyFileReferences\"])\n )\n throw new Error(\"Use a self-contained Endor SARIF report.\");\n const rules = array(driver[\"rules\"] ?? [], \"Endor rules\").map((r) =>\n record(r, \"Endor rule\"),\n );\n const rulesById = indexSarifRules(rules);\n const { runs: _runs, ...documentContext } = document;\n const { results: _results, tool: _tool, ...runContext } = run;\n const { rules: _rules, ...driverContext } = driver;\n const { driver: _driver, ...toolContext } = tool;\n return array(run[\"results\"] ?? [], \"Endor results\").map((result) => ({\n result,\n rulesById,\n documentContext,\n runContext,\n driverContext,\n toolContext,\n }));\n });\n return normalizeRecords(\n entries,\n ({ result: value, rulesById, ...context }) => {\n const result = record(value, \"Endor result\");\n const properties = record(\n result[\"properties\"],\n \"Endor result properties\",\n );\n requiredText(properties[\"project-uuid\"], \"Endor project-uuid\");\n const ruleId = requiredText(result[\"ruleId\"], \"Endor ruleId\");\n const selectedRule = rulesById.get(ruleId);\n if (!selectedRule)\n throw new Error(\n \"Endor result must reference exactly one rule in its run.\",\n );\n const { rule, index: ruleIndex } = selectedRule;\n if (\n result[\"ruleIndex\"] !== undefined &&\n result[\"ruleIndex\"] !== ruleIndex\n )\n throw new Error(\"Endor ruleIndex and ruleId disagree.\");\n if (result[\"rule\"] !== undefined) {\n const reference = record(result[\"rule\"], \"Endor rule reference\");\n if (\n reference[\"toolComponent\"] !== undefined ||\n (reference[\"id\"] !== undefined && reference[\"id\"] !== ruleId) ||\n (reference[\"index\"] !== undefined &&\n reference[\"index\"] !== ruleIndex) ||\n (reference[\"guid\"] !== undefined &&\n reference[\"guid\"] !== rule[\"guid\"])\n )\n throw new Error(\"Inconsistent or external Endor rule reference.\");\n }\n const message = record(result[\"message\"], \"Endor message\");\n const short = record(\n rule[\"shortDescription\"] ?? {},\n \"Endor shortDescription\",\n );\n const full = record(\n rule[\"fullDescription\"] ?? {},\n \"Endor fullDescription\",\n );\n const help = record(rule[\"help\"] ?? {}, \"Endor help\");\n const hasCodeLocations = strings(properties[\"categories\"]).some(\n (category) => category === \"SAST\" || category === \"SECRETS\",\n );\n const locations = array(\n result[\"locations\"] ?? [],\n \"Endor locations\",\n ).flatMap((v) => {\n const physical = record(\n record(v, \"Endor location\")[\"physicalLocation\"] ?? {},\n \"Physical location\",\n );\n const artifact = record(\n physical[\"artifactLocation\"] ?? {},\n \"Artifact location\",\n );\n if (\n artifact[\"index\"] !== undefined ||\n artifact[\"uriBaseId\"] !== undefined\n )\n return [];\n const uri = text(artifact[\"uri\"]);\n if (uri === null || /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(uri)) return [];\n let path: string | null;\n try {\n path = relativePath(decodeURIComponent(uri));\n } catch {\n return [];\n }\n if (path === null) return [];\n const line = hasCodeLocations\n ? record(physical[\"region\"] ?? {}, \"Endor region\")[\"startLine\"]\n : null;\n return [\n {\n path,\n line:\n typeof line === \"number\" && Number.isSafeInteger(line) && line > 0\n ? line\n : null,\n },\n ];\n });\n return validateExternalEvidence(\n {\n title: text(short[\"text\"]) ?? text(rule[\"name\"]) ?? ruleId,\n url: text(properties[\"finding-url\"]),\n description: [\n text(message[\"markdown\"]) ?? text(message[\"text\"]),\n text(full[\"text\"]),\n text(help[\"markdown\"]) ?? text(help[\"text\"]),\n ]\n .filter(Boolean)\n .join(\"\\n\\n\"),\n // Diagnostic level and CVSS are not Endor's finding severity. Keep both as source evidence.\n severity: \"unknown\",\n locations: [\n ...new Map(\n locations.map((location) => [JSON.stringify(location), location]),\n ).values(),\n ],\n source_data: structuredClone({\n ...context,\n runContext: sarifRunContextForResult(\n context.runContext,\n result,\n rule,\n context.documentContext,\n context.driverContext,\n context.toolContext,\n ),\n rule,\n result,\n }),\n },\n target,\n );\n },\n ({ result }) =>\n requiredText(\n record(\n record(result, \"Endor result\")[\"properties\"],\n \"Endor result properties\",\n )[\"finding-uuid\"],\n \"Endor finding-uuid\",\n ),\n target,\n );\n}\n\nexport async function readEndorFindings(\n path: string,\n target: ExternalImportTarget = \"cloud\",\n): Promise<ExternalFindings> {\n return normalizeEndorFindings(await readScannerJson(path), target);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-findings-import.d.ts","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AASjF,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"external-findings-import.d.ts","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AASjF,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,8BAA8B,CAAC;AAKtC,8EAA8E;AAC9E,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,0BAA0B,EACnC,YAAY,GAAE,+BAAoC,+EAgDnD"}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { cloudRepositoryUrlKey, repositoryUrlKey, } from "./external-import-contract.js";
|
|
2
2
|
import { EXTERNAL_FINDINGS_PROVIDERS, readExternalFindings, } from "./external-findings-read.js";
|
|
3
|
-
import {
|
|
3
|
+
import { prepareLocalImport, } from "./external-findings-local.js";
|
|
4
|
+
import { snapshotImportOptions } from "./external-findings.js";
|
|
4
5
|
import { abortable } from "./targets.js";
|
|
5
6
|
import { requireExternalImports } from "./external-imports-feature.js";
|
|
6
7
|
/** Read an installed vendor format and prepare it for the local workbench. */
|
|
7
8
|
export async function prepareLocalExternalImport(path, options, dependencies = {}) {
|
|
8
9
|
dependencies.signal?.throwIfAborted();
|
|
9
10
|
requireExternalImports(dependencies.environment);
|
|
10
|
-
const
|
|
11
|
+
const settings = snapshotImportOptions(options);
|
|
12
|
+
const parsed = await abortable(() => readExternalFindings(path, settings, "local"), dependencies.signal);
|
|
11
13
|
const normalizedOptions = {
|
|
12
|
-
...
|
|
13
|
-
provider: EXTERNAL_FINDINGS_PROVIDERS[
|
|
14
|
+
...settings,
|
|
15
|
+
provider: EXTERNAL_FINDINGS_PROVIDERS[settings.provider],
|
|
14
16
|
};
|
|
15
17
|
let sourceRepositories = parsed.sourceRepositories ?? [];
|
|
16
18
|
if (normalizedOptions.provider === "semgrep") {
|
|
17
19
|
// The Cloud reader allows custom GitHub casing. Local provenance must also
|
|
18
20
|
// agree with the caller's source URL when the checkout has no remote.
|
|
19
|
-
const source =
|
|
21
|
+
const source = settings.sourceRepositoryUrl;
|
|
20
22
|
const knownGitHub = dependencies.sourceRepositories?.some(({ url, platform }) => platform === "github" &&
|
|
21
23
|
cloudRepositoryUrlKey(url) === cloudRepositoryUrlKey(source));
|
|
22
24
|
const key = knownGitHub ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
@@ -34,7 +36,7 @@ export async function prepareLocalExternalImport(path, options, dependencies = {
|
|
|
34
36
|
];
|
|
35
37
|
}
|
|
36
38
|
const { environment, ...workbench } = dependencies;
|
|
37
|
-
return
|
|
39
|
+
return prepareLocalImport(parsed.findings, normalizedOptions, {
|
|
38
40
|
...workbench,
|
|
39
41
|
environment,
|
|
40
42
|
sourceRepositories: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-findings-import.js","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"external-findings-import.js","sourceRoot":"","sources":["../src/external-findings-import.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,kBAAkB,GAEnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,IAAY,EACZ,OAAmC,EACnC,YAAY,GAAoC,EAAE;IAElD,YAAY,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IACtC,sBAAsB,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,MAAM,SAAS,CAC5B,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EACnD,YAAY,CAAC,MAAM,CACpB,CAAC;IACF,MAAM,iBAAiB,GAAG;QACxB,GAAG,QAAQ;QACX,QAAQ,EAAE,2BAA2B,CAAC,QAAQ,CAAC,QAAQ,CAAC;KACzD,CAAC;IACF,IAAI,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,IAAI,EAAE,CAAC;IACzD,IAAI,iBAAiB,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC7C,2EAA2E;QAC3E,sEAAsE;QACtE,MAAM,MAAM,GAAG,QAAQ,CAAC,mBAAoB,CAAC;QAC7C,MAAM,WAAW,GAAG,YAAY,CAAC,kBAAkB,EAAE,IAAI,CACvD,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CACpB,QAAQ,KAAK,QAAQ;YACrB,qBAAqB,CAAC,GAAG,CAAC,KAAK,qBAAqB,CAAC,MAAM,CAAC,CAC/D,CAAC;QACF,MAAM,GAAG,GAAG,WAAW,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,gBAAgB,CAAC;QACnE,KAAK,MAAM,SAAS,IAAI,kBAAkB,EAAE,CAAC;YAC3C,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC;gBACpC,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;QACN,CAAC;QACD,IAAI,WAAW;YACb,kBAAkB,GAAG;gBACnB,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE;gBACnC,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;oBACxC,GAAG,SAAS;oBACZ,QAAQ,EAAE,QAAiB;iBAC5B,CAAC,CAAC;aACJ,CAAC;IACN,CAAC;IACD,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,EAAE,GAAG,YAAY,CAAC;IACnD,OAAO,kBAAkB,CAAC,MAAM,CAAC,QAAQ,EAAE,iBAAiB,EAAE;QAC5D,GAAG,SAAS;QACZ,WAAW;QACX,kBAAkB,EAAE;YAClB,GAAG,CAAC,YAAY,CAAC,kBAAkB,IAAI,EAAE,CAAC;YAC1C,GAAG,kBAAkB;SACtB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { ExternalPublicationOptions } from \"./external-findings-publish.js\";\nimport {\n cloudRepositoryUrlKey,\n repositoryUrlKey,\n} from \"./external-import-contract.js\";\nimport {\n EXTERNAL_FINDINGS_PROVIDERS,\n readExternalFindings,\n} from \"./external-findings-read.js\";\nimport {\n prepareLocalImport,\n type LocalExternalImportDependencies,\n} from \"./external-findings-local.js\";\nimport { snapshotImportOptions } from \"./external-findings.js\";\nimport { abortable } from \"./targets.js\";\nimport { requireExternalImports } from \"./external-imports-feature.js\";\n\n/** Read an installed vendor format and prepare it for the local workbench. */\nexport async function prepareLocalExternalImport(\n path: string,\n options: ExternalPublicationOptions,\n dependencies: LocalExternalImportDependencies = {},\n) {\n dependencies.signal?.throwIfAborted();\n requireExternalImports(dependencies.environment);\n const settings = snapshotImportOptions(options);\n const parsed = await abortable(\n () => readExternalFindings(path, settings, \"local\"),\n dependencies.signal,\n );\n const normalizedOptions = {\n ...settings,\n provider: EXTERNAL_FINDINGS_PROVIDERS[settings.provider],\n };\n let sourceRepositories = parsed.sourceRepositories ?? [];\n if (normalizedOptions.provider === \"semgrep\") {\n // The Cloud reader allows custom GitHub casing. Local provenance must also\n // agree with the caller's source URL when the checkout has no remote.\n const source = settings.sourceRepositoryUrl!;\n const knownGitHub = dependencies.sourceRepositories?.some(\n ({ url, platform }) =>\n platform === \"github\" &&\n cloudRepositoryUrlKey(url) === cloudRepositoryUrlKey(source),\n );\n const key = knownGitHub ? cloudRepositoryUrlKey : repositoryUrlKey;\n for (const reference of sourceRepositories) {\n if (key(reference.url) !== key(source))\n throw new Error(\n \"SARIF source repository does not match the declared source repository URL.\",\n );\n }\n if (knownGitHub)\n sourceRepositories = [\n { url: source, platform: \"github\" },\n ...sourceRepositories.map((reference) => ({\n ...reference,\n platform: \"github\" as const,\n })),\n ];\n }\n const { environment, ...workbench } = dependencies;\n return prepareLocalImport(parsed.findings, normalizedOptions, {\n ...workbench,\n environment,\n sourceRepositories: [\n ...(dependencies.sourceRepositories ?? []),\n ...sourceRepositories,\n ],\n });\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ExternalFindings, type ExternalSourceRepository } from "./external-findings.js";
|
|
2
2
|
import type { ExternalFindingEvidence, Provider } from "./external-import-models.js";
|
|
3
3
|
import { runWorkbench } from "./runtime.js";
|
|
4
4
|
/** A scanner source record, independent of a Codex assessment or completed scan. */
|
|
@@ -22,6 +22,8 @@ export interface NormalizedLocalImportOptions {
|
|
|
22
22
|
provider: Provider;
|
|
23
23
|
/** Stable scanner organization/project/branch namespace across imports. */
|
|
24
24
|
sourceKey: string;
|
|
25
|
+
/** Full Inspector project ARNs mapped to independently verified repository URLs. */
|
|
26
|
+
inspectorProjectMap?: ReadonlyMap<string, string>;
|
|
25
27
|
}
|
|
26
28
|
export interface LocalExternalImportDependencies {
|
|
27
29
|
environment?: NodeJS.ProcessEnv;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-findings-local.d.ts","sourceRoot":"","sources":["../src/external-findings-local.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"external-findings-local.d.ts","sourceRoot":"","sources":["../src/external-findings-local.ts"],"names":[],"mappings":"AASA,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAAC;AAMhC,OAAO,KAAK,EACV,uBAAuB,EACvB,QAAQ,EACT,MAAM,6BAA6B,CAAC;AAKrC,OAAO,EAML,YAAY,EAGb,MAAM,cAAc,CAAC;AAUtB,oFAAoF;AACpF,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE;QAAE,KAAK,EAAE,cAAc,CAAA;KAAE,CAAC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MA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AO,EAAE,4BAA4B,EACrC,YAAY,GAAE,+BAAoC,GACjD,OAAO,CAAC,2BAA2B,CAAC,CAQtC;AAkKD,4FAA4F;AAC5F,wBAAsB,yBAAyB,CAC7C,SAAS,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,EAC9C,YAAY,GAAE,+BAAoC,GACjD,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAkBlC"}
|
|
@@ -4,56 +4,116 @@ import { isNumberObject } from "node:util/types";
|
|
|
4
4
|
import { environmentEntry } from "./auth.js";
|
|
5
5
|
import { CodexSecurityError } from "./errors.js";
|
|
6
6
|
import { forwardExternalImportSetting, requireExternalImports, } from "./external-imports-feature.js";
|
|
7
|
+
import { snapshotImportOptions, } from "./external-findings.js";
|
|
7
8
|
import { cloudRepositoryUrlKey, repositoryUrlKey, validateExternalReport, } from "./external-import-contract.js";
|
|
8
|
-
import { parseGitRemote } from "./git-remote.js";
|
|
9
|
+
import { isGitHubCloudHost, parseGitRemote } from "./git-remote.js";
|
|
10
|
+
import { inspectorReportRepository } from "./inspector-findings.js";
|
|
9
11
|
import { isRecord } from "./record.js";
|
|
12
|
+
import { dependabotRepository } from "./github-dependabot-findings.js";
|
|
10
13
|
import { bundledPluginRoot, canonicalConfigPath, canonicalizeModelSafePath, expandHome, requireOutputOutsideRepositories, runWorkbench, workbenchEnvironment, } from "./runtime.js";
|
|
11
14
|
import { abortable, gitMarkerRoot, gitOutput, gitProtectionRoots, normalizeRepository, nullIfMissingPath, } from "./targets.js";
|
|
12
15
|
function requireIdentity(value, field) {
|
|
13
16
|
if (typeof value !== "string" || !value.trim() || value.includes("\0"))
|
|
14
17
|
throw new CodexSecurityError(`${field} must be nonempty and contain no NUL characters.`);
|
|
15
18
|
}
|
|
19
|
+
const gitTransportPorts = {
|
|
20
|
+
"http:": "80",
|
|
21
|
+
"https:": "443",
|
|
22
|
+
"ssh:": "22",
|
|
23
|
+
"git+ssh:": "22",
|
|
24
|
+
"ssh+git:": "22",
|
|
25
|
+
"git:": "9418",
|
|
26
|
+
"ftp:": "21",
|
|
27
|
+
"ftps:": "990",
|
|
28
|
+
};
|
|
16
29
|
/** Compare transport forms without changing retained scanner evidence. */
|
|
17
|
-
function
|
|
30
|
+
function remoteRepository(value, provider, bound) {
|
|
18
31
|
if (/^[A-Za-z]:[\\/]/u.test(value))
|
|
19
32
|
return undefined;
|
|
33
|
+
const transport = bound
|
|
34
|
+
? /^(?:ssh|git\+ssh|ssh\+git|git):\/\/([^/]*)(.*)$/isu.exec(value)
|
|
35
|
+
: null;
|
|
36
|
+
const authority = transport?.[1];
|
|
37
|
+
const http = bound && /^https?:\/\//iu.test(value.trimStart());
|
|
38
|
+
// Git decodes the authority before locating its path. An encoded delimiter
|
|
39
|
+
// cannot prove a match to another spelling through WHATWG URL's hostname.
|
|
40
|
+
if (authority &&
|
|
41
|
+
(/%2f|[?#]/iu.test(authority) ||
|
|
42
|
+
authority.slice(authority.lastIndexOf("@") + 1).includes("%")))
|
|
43
|
+
return { key: value };
|
|
20
44
|
let remote;
|
|
21
45
|
try {
|
|
22
46
|
remote = parseGitRemote(value);
|
|
23
47
|
}
|
|
24
48
|
catch {
|
|
25
|
-
return undefined;
|
|
49
|
+
return transport || http ? { key: "\0" + value } : undefined;
|
|
26
50
|
}
|
|
27
|
-
if (!remote ||
|
|
28
|
-
![
|
|
29
|
-
"http:",
|
|
30
|
-
"https:",
|
|
31
|
-
"ssh:",
|
|
32
|
-
"git:",
|
|
33
|
-
"ftp:",
|
|
34
|
-
"ftps:",
|
|
35
|
-
"git+ssh:",
|
|
36
|
-
"ssh+git:",
|
|
37
|
-
].includes(remote.url.protocol))
|
|
51
|
+
if (!remote || !Object.hasOwn(gitTransportPorts, remote.url.protocol))
|
|
38
52
|
return undefined;
|
|
39
|
-
const url = remote
|
|
40
|
-
const ssh =
|
|
53
|
+
const { url, path, scpStyle } = remote;
|
|
54
|
+
const ssh = url.protocol.includes("ssh");
|
|
41
55
|
const protocol = url.protocol === "http:" ? "http:" : "https:";
|
|
42
56
|
const githubSshOverHttps = ssh &&
|
|
43
57
|
url.hostname.toLowerCase() === "ssh.github.com" &&
|
|
44
58
|
url.port === "443";
|
|
45
59
|
const hostname = githubSshOverHttps ? "github.com" : url.hostname;
|
|
46
|
-
const port = githubSshOverHttps ||
|
|
47
|
-
(ssh && url.port === "22") ||
|
|
48
|
-
(url.protocol === "git:" && url.port === "9418") ||
|
|
49
|
-
(url.protocol === "ftp:" && url.port === "21") ||
|
|
50
|
-
(url.protocol === "ftps:" && url.port === "990")
|
|
60
|
+
const port = githubSshOverHttps || url.port === gitTransportPorts[url.protocol]
|
|
51
61
|
? ""
|
|
52
62
|
: url.port;
|
|
53
63
|
// A GitHub source identifies a case-insensitive repository on custom Enterprise
|
|
54
64
|
// hosts too; other providers can refer to VCS hosts with case-sensitive paths.
|
|
55
65
|
const key = provider === "github" ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
56
|
-
|
|
66
|
+
const origin = `${protocol}//${hostname}${port ? `:${port}` : ""}/`;
|
|
67
|
+
if (!bound)
|
|
68
|
+
return { key: key(origin + path) };
|
|
69
|
+
if (!ssh && url.protocol !== "git:") {
|
|
70
|
+
if (url.protocol === "http:" || url.protocol === "https:") {
|
|
71
|
+
// libcurl and WHATWG differ on backslashes and encoded dot segments.
|
|
72
|
+
const raw = /^https?:\/\/[^/\\?#\s]+(\/[^\\?#]*)?(?:[?#].*)?$/iu.exec(value);
|
|
73
|
+
if (!raw || /\/(?:%2e|\.%2e|%2e\.|%2e%2e)(?:\/|$)/iu.test(raw[1] ?? ""))
|
|
74
|
+
return { key: "\0" + value };
|
|
75
|
+
}
|
|
76
|
+
const suffix = /[?#].*$/su.exec(value)?.[0] ?? "";
|
|
77
|
+
// HTTP sends the query and omits fragment text from repository requests.
|
|
78
|
+
if (suffix && !["http:", "https:"].includes(url.protocol))
|
|
79
|
+
return { key: key(origin + path) + "\0" };
|
|
80
|
+
return {
|
|
81
|
+
key: key(origin + path) + suffix.replace(/#.*$/su, "#").replace(/\/$/u, ""),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// Git passes the original path (including dot segments, '?' and '#') to upload-pack.
|
|
85
|
+
const literal = (raw) => {
|
|
86
|
+
const bytes = Buffer.from(raw).toString("latin1");
|
|
87
|
+
return scpStyle
|
|
88
|
+
? bytes
|
|
89
|
+
: bytes.replace(/%(?!00)([\da-f]{2})/giu, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
90
|
+
};
|
|
91
|
+
if (!scpStyle && !transport)
|
|
92
|
+
return { key: value };
|
|
93
|
+
const gitPath = literal(transport?.[2] ?? path);
|
|
94
|
+
const login = scpStyle
|
|
95
|
+
? /^([^@/:\s?#]+)@/u.exec(value)?.[1]
|
|
96
|
+
: /^(.*)@/u.exec(authority ?? "")?.[1];
|
|
97
|
+
const homeRelative = /^\/?~(?:\/|$)/u.test(gitPath) || (scpStyle && !/^[~/]/u.test(gitPath));
|
|
98
|
+
const suffix = /[?#].*$/su.exec(gitPath);
|
|
99
|
+
// Express upload-pack bytes as a URL path for comparison with the HTTP source.
|
|
100
|
+
const name = gitPath
|
|
101
|
+
.slice(0, suffix?.index)
|
|
102
|
+
.replace(/^\//u, "")
|
|
103
|
+
.replace(/[%\x00-\x20\x7f-\xff]/gu, (byte) => "%" + byte.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0"));
|
|
104
|
+
const repository = suffix
|
|
105
|
+
? key(origin + name + "?") +
|
|
106
|
+
"\0" +
|
|
107
|
+
suffix[0].replace(/\/$/u, "").replace(/\.git$/u, "")
|
|
108
|
+
: key(origin + name);
|
|
109
|
+
return {
|
|
110
|
+
key: repository,
|
|
111
|
+
account: ssh && login ? literal(login) : undefined,
|
|
112
|
+
// GitHub serves the same repository path through its SCP and SSH URLs.
|
|
113
|
+
homeRelative: ssh && provider !== "github" && !isGitHubCloudHost(hostname.toLowerCase())
|
|
114
|
+
? homeRelative
|
|
115
|
+
: undefined,
|
|
116
|
+
};
|
|
57
117
|
}
|
|
58
118
|
async function bareMetadataRoots(repository, signal) {
|
|
59
119
|
const roots = [];
|
|
@@ -204,26 +264,32 @@ async function requireMatchingRepository(repository, provider, sources, protecte
|
|
|
204
264
|
const urls = await readGit(["remote", "get-url", "--all", "--", name]);
|
|
205
265
|
remotes.push(...urls.split(/\r?\n/u));
|
|
206
266
|
}
|
|
267
|
+
const identity = (value, platform) => remoteRepository(value, platform, provider === "inspector");
|
|
207
268
|
const githubRepositories = new Set(sources.flatMap((source) => {
|
|
208
269
|
if (source.platform !== "github")
|
|
209
270
|
return [];
|
|
210
|
-
const key =
|
|
271
|
+
const key = identity(source.url, "github")?.key;
|
|
211
272
|
return key === undefined ? [] : [key];
|
|
212
273
|
}));
|
|
213
274
|
for (const source of sources) {
|
|
214
|
-
const githubKey =
|
|
275
|
+
const githubKey = identity(source.url, "github")?.key;
|
|
215
276
|
const sourceProvider = source.platform === "github" ||
|
|
216
277
|
(githubKey !== undefined && githubRepositories.has(githubKey))
|
|
217
278
|
? "github"
|
|
218
279
|
: provider;
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
return key === undefined ? [] : [key];
|
|
222
|
-
}));
|
|
223
|
-
if (remoteKeys.size === 0)
|
|
280
|
+
const targets = remotes.flatMap((remote) => identity(remote, sourceProvider) ?? []);
|
|
281
|
+
if (!targets.length)
|
|
224
282
|
continue;
|
|
225
|
-
const
|
|
226
|
-
if (
|
|
283
|
+
const target = identity(source.url, sourceProvider);
|
|
284
|
+
if (!target ||
|
|
285
|
+
!targets.some(({ key, account, homeRelative }) => key === target.key &&
|
|
286
|
+
(homeRelative === undefined ||
|
|
287
|
+
target.homeRelative === undefined ||
|
|
288
|
+
homeRelative === target.homeRelative) &&
|
|
289
|
+
((homeRelative === false && target.homeRelative === false) ||
|
|
290
|
+
account === undefined ||
|
|
291
|
+
target.account === undefined ||
|
|
292
|
+
account === target.account)))
|
|
227
293
|
throw new CodexSecurityError(`Imported repository ${JSON.stringify(source.url)} does not match a configured remote of ${repository}. Select the matching local repository.`);
|
|
228
294
|
}
|
|
229
295
|
}
|
|
@@ -260,9 +326,14 @@ async function localContext(selectedRepository, dependencies, mode = "import") {
|
|
|
260
326
|
export async function prepareNormalizedLocalImport(input, options, dependencies = {}) {
|
|
261
327
|
dependencies.signal?.throwIfAborted();
|
|
262
328
|
requireExternalImports(dependencies.environment);
|
|
329
|
+
return prepareLocalImport(input, snapshotImportOptions(options), dependencies);
|
|
330
|
+
}
|
|
331
|
+
/** @internal Prepare evidence using settings captured by either local import entrypoint. */
|
|
332
|
+
export async function prepareLocalImport(input, options, dependencies) {
|
|
263
333
|
requireIdentity(options.sourceKey, "Source key");
|
|
264
334
|
const current = structuredClone(input);
|
|
265
335
|
validateExternalReport(current.report);
|
|
336
|
+
let dependabotSource;
|
|
266
337
|
const identities = new Set();
|
|
267
338
|
for (const finding of current.findings) {
|
|
268
339
|
requireIdentity(finding.source_finding_id, "Source finding id");
|
|
@@ -271,19 +342,48 @@ export async function prepareNormalizedLocalImport(input, options, dependencies
|
|
|
271
342
|
identities.add(finding.source_finding_id);
|
|
272
343
|
if (!isRecord(finding.evidence))
|
|
273
344
|
throw new CodexSecurityError("Imported evidence must be an object.");
|
|
345
|
+
if (options.provider !== "github")
|
|
346
|
+
continue;
|
|
347
|
+
const native = dependabotRepository(finding);
|
|
348
|
+
if (!native)
|
|
349
|
+
continue;
|
|
350
|
+
const claimed = finding.evidence.details?.repository?.url;
|
|
351
|
+
if (claimed &&
|
|
352
|
+
cloudRepositoryUrlKey(claimed) !== cloudRepositoryUrlKey(native))
|
|
353
|
+
throw new CodexSecurityError("The normalized repository does not match the original Dependabot alert.");
|
|
354
|
+
if (dependabotSource && dependabotSource !== native)
|
|
355
|
+
throw new CodexSecurityError("Select Dependabot alerts from only one GitHub host and repository.");
|
|
356
|
+
dependabotSource = native;
|
|
274
357
|
}
|
|
275
358
|
const { repository, options: workbenchOptions } = await localContext(options.repository, dependencies);
|
|
276
359
|
const sources = new Map();
|
|
277
|
-
for (const
|
|
278
|
-
const url = evidence.details?.repository?.url;
|
|
360
|
+
for (const finding of current.findings) {
|
|
361
|
+
const url = finding.evidence.details?.repository?.url;
|
|
279
362
|
if (url)
|
|
280
363
|
sources.set(url, { url });
|
|
281
364
|
}
|
|
282
|
-
|
|
283
|
-
|
|
365
|
+
const inspector = inspectorReportRepository(options.provider, current.findings, "local", options.inspectorProjectMap);
|
|
366
|
+
if (inspector) {
|
|
367
|
+
const platform = inspector.platform ?? options.provider;
|
|
368
|
+
const native = remoteRepository(inspector.url, platform, true);
|
|
369
|
+
for (const url of sources.keys()) {
|
|
370
|
+
if (!native || remoteRepository(url, platform, true)?.key !== native.key)
|
|
371
|
+
throw new CodexSecurityError(`Imported repository ${JSON.stringify(url)} does not match the retained Inspector repository ${JSON.stringify(inspector.url)}.`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
for (const source of [
|
|
375
|
+
...(inspector ? [inspector] : []),
|
|
376
|
+
...(dependencies.sourceRepositories ?? []),
|
|
377
|
+
]) {
|
|
378
|
+
// A reader's platform must not loosen an operator-supplied Inspector map.
|
|
284
379
|
if (sources.get(source.url)?.platform !== "github")
|
|
285
|
-
sources.set(source.url, source);
|
|
380
|
+
sources.set(source.url, options.inspectorProjectMap ? { url: source.url } : source);
|
|
286
381
|
}
|
|
382
|
+
if (dependabotSource)
|
|
383
|
+
sources.set(dependabotSource, {
|
|
384
|
+
url: dependabotSource,
|
|
385
|
+
platform: "github",
|
|
386
|
+
});
|
|
287
387
|
await requireMatchingRepository(repository, options.provider, [...sources.values()], workbenchOptions.protectedRoot, workbenchOptions.environment, dependencies.signal);
|
|
288
388
|
dependencies.signal?.throwIfAborted();
|
|
289
389
|
const preview = {
|