@openai/codex-security 0.5.1 → 0.7.0
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 +151 -36
- package/_bundled_plugin/.mcp.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 +1 -1
- 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/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/access-advisory.md +11 -0
- package/_bundled_plugin/references/core-scan.md +30 -77
- package/_bundled_plugin/references/final-report.md +45 -189
- package/_bundled_plugin/references/scan-contract.md +2 -0
- package/_bundled_plugin/references/scan-prologue.md +1 -1
- package/_bundled_plugin/references/scan-runtime.md +1 -5
- package/_bundled_plugin/references/threat-model.md +33 -41
- package/_bundled_plugin/schemas/coverage.schema.json +12 -1
- package/_bundled_plugin/schemas/scan-manifest.schema.json +1 -0
- package/_bundled_plugin/schemas/tools/deep-reducer.schema.json +38 -1
- package/_bundled_plugin/scripts/deep_scan_config.py +39 -39
- package/_bundled_plugin/scripts/deep_scan_workbench.py +145 -85
- package/_bundled_plugin/scripts/finalize_scan_contract.py +189 -57
- package/_bundled_plugin/scripts/report_projection.py +44 -15
- package/_bundled_plugin/scripts/threat_model_projection.py +4 -2
- package/_bundled_plugin/scripts/windows_scan_local_files.py +43 -14
- package/_bundled_plugin/scripts/workbench/retained_coverage.py +3218 -0
- package/_bundled_plugin/scripts/workbench/retained_records.py +627 -0
- package/_bundled_plugin/scripts/workbench/saved_coverage.py +644 -1
- package/_bundled_plugin/scripts/workbench/saved_outputs.py +72 -0
- package/_bundled_plugin/scripts/workbench/saved_sources.py +712 -0
- package/_bundled_plugin/scripts/workbench_cli.py +3 -0
- package/_bundled_plugin/scripts/workbench_coverage_receipts.py +479 -0
- package/_bundled_plugin/scripts/workbench_db.py +51 -22
- package/_bundled_plugin/scripts/workbench_feedback.py +0 -1
- package/_bundled_plugin/scripts/workbench_finding_workflows.py +53 -9
- package/_bundled_plugin/scripts/workbench_native_indexes.py +56 -44
- package/_bundled_plugin/scripts/workbench_saved_results.py +641 -2387
- package/_bundled_plugin/scripts/workbench_scan_history.py +72 -7
- package/_bundled_plugin/scripts/workbench_schema.py +1 -1
- package/_bundled_plugin/scripts/workbench_source_scopes.py +4 -1
- package/_bundled_plugin/scripts/workbench_target.py +142 -17
- package/_bundled_plugin/scripts/workbench_validation.py +9 -2
- package/_bundled_plugin/shared/workbench-history-repairs.json +21 -0
- package/_bundled_plugin/shared/workbench-migrations.json +44 -0
- package/_bundled_plugin/skills/assess-patch-risk/SKILL.md +3 -14
- package/_bundled_plugin/skills/assess-patch-risk/references/windows-validation.md +14 -0
- package/_bundled_plugin/skills/attack-path-analysis/SKILL.md +38 -103
- package/_bundled_plugin/skills/attack-path-analysis/references/attack-path-facts.md +11 -73
- package/_bundled_plugin/skills/attack-path-analysis/references/severity-policy.md +57 -116
- package/_bundled_plugin/skills/deep-security-scan/SKILL.md +28 -51
- package/_bundled_plugin/skills/define-security-policy/SKILL.md +9 -9
- package/_bundled_plugin/skills/finding-discovery/SKILL.md +26 -140
- package/_bundled_plugin/skills/fix-finding/SKILL.md +19 -30
- package/_bundled_plugin/skills/propose-security-hardening/SKILL.md +28 -218
- package/_bundled_plugin/skills/propose-security-hardening/references/proposal-format.md +29 -424
- package/_bundled_plugin/skills/publish-findings/SKILL.md +134 -0
- package/_bundled_plugin/skills/publish-findings/agents/openai.yaml +6 -0
- package/_bundled_plugin/skills/publish-findings/references/wiz-import.md +64 -0
- package/_bundled_plugin/skills/security-diff-scan/SKILL.md +12 -12
- package/_bundled_plugin/skills/security-scan/SKILL.md +28 -16
- package/_bundled_plugin/skills/security-scan/references/desktop-scan.md +11 -17
- package/_bundled_plugin/skills/security-scan/references/scan-artifacts-and-ledger.md +52 -69
- package/_bundled_plugin/skills/threat-model/SKILL.md +16 -9
- package/_bundled_plugin/skills/triage-finding/SKILL.md +5 -15
- package/_bundled_plugin/skills/triage-finding/references/ticket-intake.md +6 -6
- package/_bundled_plugin/skills/validation/SKILL.md +42 -104
- package/_bundled_plugin/skills/validation/references/validation-guidance.md +21 -106
- package/_bundled_plugin/skills/verify-fix/SKILL.md +8 -4
- package/_bundled_plugin/skills/vulnerability-writeup/SKILL.md +21 -159
- package/_bundled_plugin/skills/vulnerability-writeup/references/report-format.md +18 -60
- package/dist/api.d.ts +8 -3
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +414 -72
- package/dist/api.js.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +4 -1
- package/dist/auth.js.map +1 -1
- package/dist/classify-severity-records.d.ts +5 -2
- package/dist/classify-severity-records.d.ts.map +1 -1
- package/dist/classify-severity-records.js +40 -34
- package/dist/classify-severity-records.js.map +1 -1
- package/dist/classify-severity.d.ts +5 -1
- package/dist/classify-severity.d.ts.map +1 -1
- package/dist/classify-severity.js +20 -30
- package/dist/classify-severity.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 +9 -2
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +802 -149
- package/dist/cli.js.map +1 -1
- package/dist/cloud-endpoint.d.ts +6 -0
- package/dist/cloud-endpoint.d.ts.map +1 -0
- package/dist/cloud-endpoint.js +51 -0
- package/dist/cloud-endpoint.js.map +1 -0
- package/dist/cloud-publish.d.ts.map +1 -1
- package/dist/cloud-publish.js +7 -5
- package/dist/cloud-publish.js.map +1 -1
- package/dist/component-scan.d.ts +8 -2
- package/dist/component-scan.d.ts.map +1 -1
- package/dist/component-scan.js +2 -0
- package/dist/component-scan.js.map +1 -1
- package/dist/contract.d.ts +2 -0
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +67 -33
- package/dist/contract.js.map +1 -1
- package/dist/cost.d.ts +18 -0
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +107 -12
- package/dist/cost.js.map +1 -1
- package/dist/coverage-presentation.d.ts +6 -0
- package/dist/coverage-presentation.d.ts.map +1 -0
- package/dist/coverage-presentation.js +34 -0
- package/dist/coverage-presentation.js.map +1 -0
- package/dist/custom-validation-prompt.js +3 -3
- package/dist/custom-validation-prompt.js.map +1 -1
- package/dist/custom-validation.d.ts.map +1 -1
- package/dist/custom-validation.js +30 -4
- package/dist/custom-validation.js.map +1 -1
- package/dist/deduplication/checkpointed-review.d.ts.map +1 -1
- package/dist/deduplication/checkpointed-review.js +3 -1
- package/dist/deduplication/checkpointed-review.js.map +1 -1
- package/dist/deduplication/scan.d.ts.map +1 -1
- package/dist/deduplication/scan.js +7 -5
- package/dist/deduplication/scan.js.map +1 -1
- package/dist/default-severity-rubric.d.ts +3 -0
- package/dist/default-severity-rubric.d.ts.map +1 -0
- package/dist/default-severity-rubric.js +67 -0
- package/dist/default-severity-rubric.js.map +1 -0
- package/dist/endor-findings.d.ts +8 -0
- package/dist/endor-findings.d.ts.map +1 -0
- package/dist/endor-findings.js +238 -0
- package/dist/endor-findings.js.map +1 -0
- package/dist/external-findings-import.d.ts +5 -0
- package/dist/external-findings-import.d.ts.map +1 -0
- package/dist/external-findings-import.js +46 -0
- package/dist/external-findings-import.js.map +1 -0
- package/dist/external-findings-local.d.ts +63 -0
- package/dist/external-findings-local.d.ts.map +1 -0
- package/dist/external-findings-local.js +344 -0
- package/dist/external-findings-local.js.map +1 -0
- package/dist/external-findings-publish.d.ts +73 -0
- package/dist/external-findings-publish.d.ts.map +1 -0
- package/dist/external-findings-publish.js +721 -0
- package/dist/external-findings-publish.js.map +1 -0
- package/dist/external-findings-read.d.ts +16 -0
- package/dist/external-findings-read.d.ts.map +1 -0
- package/dist/external-findings-read.js +97 -0
- package/dist/external-findings-read.js.map +1 -0
- package/dist/external-findings.d.ts +21 -0
- package/dist/external-findings.d.ts.map +1 -0
- package/dist/external-findings.js +2 -0
- package/dist/external-findings.js.map +1 -0
- package/dist/external-import-contract.d.ts +15 -0
- package/dist/external-import-contract.d.ts.map +1 -0
- package/dist/external-import-contract.js +262 -0
- package/dist/external-import-contract.js.map +1 -0
- package/dist/external-import-models.d.ts +362 -0
- package/dist/external-import-models.d.ts.map +1 -0
- package/dist/external-import-models.js +3 -0
- package/dist/external-import-models.js.map +1 -0
- package/dist/external-imports-feature.d.ts +6 -0
- package/dist/external-imports-feature.d.ts.map +1 -0
- package/dist/external-imports-feature.js +51 -0
- package/dist/external-imports-feature.js.map +1 -0
- package/dist/finding-workflow.d.ts +23 -6
- package/dist/finding-workflow.d.ts.map +1 -1
- package/dist/finding-workflow.js +23 -10
- package/dist/finding-workflow.js.map +1 -1
- package/dist/github-advisories.d.ts +386 -0
- package/dist/github-advisories.d.ts.map +1 -0
- package/dist/github-advisories.js +133 -0
- package/dist/github-advisories.js.map +1 -0
- package/dist/github-findings.d.ts +11 -0
- package/dist/github-findings.d.ts.map +1 -0
- package/dist/github-findings.js +258 -0
- package/dist/github-findings.js.map +1 -0
- package/dist/hosted-remediation-protocol.d.ts +2 -1
- package/dist/hosted-remediation-protocol.d.ts.map +1 -1
- package/dist/hosted-remediation-protocol.js +17 -11
- package/dist/hosted-remediation-protocol.js.map +1 -1
- package/dist/hosted-remediation.d.ts +4 -0
- package/dist/hosted-remediation.d.ts.map +1 -1
- package/dist/hosted-remediation.js +22 -3
- package/dist/hosted-remediation.js.map +1 -1
- package/dist/hosted-scan.d.ts +16 -0
- package/dist/hosted-scan.d.ts.map +1 -1
- package/dist/hosted-scan.js +9 -2
- package/dist/hosted-scan.js.map +1 -1
- package/dist/import-scan.js +1 -1
- package/dist/import-scan.js.map +1 -1
- package/dist/index.d.ts +16 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge-base.d.ts +1 -0
- package/dist/knowledge-base.d.ts.map +1 -1
- package/dist/knowledge-base.js +17 -8
- package/dist/knowledge-base.js.map +1 -1
- package/dist/models.d.ts +1 -0
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js.map +1 -1
- package/dist/owner-evidence.d.ts +2 -0
- package/dist/owner-evidence.d.ts.map +1 -1
- package/dist/owner-evidence.js +2 -1
- package/dist/owner-evidence.js.map +1 -1
- package/dist/project-config-schema.d.ts +2 -0
- package/dist/project-config-schema.d.ts.map +1 -1
- package/dist/project-config-schema.js +1 -0
- package/dist/project-config-schema.js.map +1 -1
- package/dist/project-config.d.ts +1 -0
- package/dist/project-config.d.ts.map +1 -1
- package/dist/project-config.js +2 -0
- package/dist/project-config.js.map +1 -1
- package/dist/publish.d.ts +2 -0
- package/dist/publish.d.ts.map +1 -1
- package/dist/publish.js +1 -1
- package/dist/publish.js.map +1 -1
- package/dist/remediation.d.ts +7 -25
- package/dist/remediation.d.ts.map +1 -1
- package/dist/remediation.js +18 -28
- package/dist/remediation.js.map +1 -1
- package/dist/result.d.ts +4 -0
- package/dist/result.d.ts.map +1 -1
- package/dist/result.js +10 -0
- package/dist/result.js.map +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +10 -8
- package/dist/runtime.js.map +1 -1
- package/dist/scan-dashboard.d.ts +5 -3
- package/dist/scan-dashboard.d.ts.map +1 -1
- package/dist/scan-dashboard.js +79 -26
- package/dist/scan-dashboard.js.map +1 -1
- package/dist/scan-history-renderer.d.ts.map +1 -1
- package/dist/scan-history-renderer.js +8 -2
- package/dist/scan-history-renderer.js.map +1 -1
- package/dist/scan-owner-suggestions.d.ts +8 -0
- package/dist/scan-owner-suggestions.d.ts.map +1 -0
- package/dist/scan-owner-suggestions.js +33 -0
- package/dist/scan-owner-suggestions.js.map +1 -0
- package/dist/scan-settings.d.ts +1 -0
- package/dist/scan-settings.d.ts.map +1 -1
- package/dist/scan-settings.js +4 -0
- package/dist/scan-settings.js.map +1 -1
- package/dist/scan-usage-display.d.ts +8 -0
- package/dist/scan-usage-display.d.ts.map +1 -0
- package/dist/scan-usage-display.js +46 -0
- package/dist/scan-usage-display.js.map +1 -0
- package/dist/scanner-import.d.ts +20 -0
- package/dist/scanner-import.d.ts.map +1 -0
- package/dist/scanner-import.js +208 -0
- package/dist/scanner-import.js.map +1 -0
- package/dist/security-policy-diff.d.ts +2 -0
- package/dist/security-policy-diff.d.ts.map +1 -0
- package/dist/security-policy-diff.js +197 -0
- package/dist/security-policy-diff.js.map +1 -0
- package/dist/security-policy.d.ts +7 -3
- package/dist/security-policy.d.ts.map +1 -1
- package/dist/security-policy.js +11 -76
- package/dist/security-policy.js.map +1 -1
- package/dist/semgrep-findings.d.ts +10 -0
- package/dist/semgrep-findings.d.ts.map +1 -0
- package/dist/semgrep-findings.js +293 -0
- package/dist/semgrep-findings.js.map +1 -0
- package/dist/severity-review.d.ts +3 -0
- package/dist/severity-review.d.ts.map +1 -1
- package/dist/severity-review.js +19 -0
- package/dist/severity-review.js.map +1 -1
- package/dist/severity-store.js +7 -2
- package/dist/severity-store.js.map +1 -1
- package/dist/skill-authentication.d.ts +18 -0
- package/dist/skill-authentication.d.ts.map +1 -0
- package/dist/skill-authentication.js +82 -0
- package/dist/skill-authentication.js.map +1 -0
- package/dist/snyk-findings.d.ts +10 -0
- package/dist/snyk-findings.d.ts.map +1 -0
- package/dist/snyk-findings.js +350 -0
- package/dist/snyk-findings.js.map +1 -0
- package/dist/suggest-owners.d.ts +4 -1
- package/dist/suggest-owners.d.ts.map +1 -1
- package/dist/suggest-owners.js +53 -21
- package/dist/suggest-owners.js.map +1 -1
- package/dist/targets.d.ts +2 -2
- package/dist/targets.d.ts.map +1 -1
- package/dist/targets.js +16 -3
- package/dist/targets.js.map +1 -1
- package/dist/wiz-csv.d.ts +9 -0
- package/dist/wiz-csv.d.ts.map +1 -0
- package/dist/wiz-csv.js +116 -0
- package/dist/wiz-csv.js.map +1 -0
- package/dist/wiz-findings.d.ts +5 -0
- package/dist/wiz-findings.d.ts.map +1 -0
- package/dist/wiz-findings.js +464 -0
- package/dist/wiz-findings.js.map +1 -0
- package/docs/classify-severity-records.md +30 -13
- package/docs/cli.md +835 -47
- package/docs/findings-service.md +119 -118
- package/docs/hosted-remediation.md +43 -24
- package/docs/hosted-scans.md +38 -0
- package/package.json +11 -9
- package/schemas/external-findings.schema.json +1421 -0
- package/schemas/project-config.schema.json +4 -0
- package/_bundled_plugin/scripts/generate_in_scope_files.py +0 -277
- package/_bundled_plugin/scripts/generate_rank_input.py +0 -350
- package/_bundled_plugin/scripts/rank_preview.py +0 -129
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { validateExternalEvidence } from "./external-import-contract.js";
|
|
2
|
+
import { isRecord } from "./record.js";
|
|
3
|
+
import { array, hasSarifExternalPropertyReferences, normalizeRecords, readScannerJson, record, relativePath, requiredText, sarifRunContextForResult, strings, text, } from "./scanner-import.js";
|
|
4
|
+
/** @internal Repository claims retained in the adapter's original SARIF context. */
|
|
5
|
+
export function endorRepositoryUrls(sourceData) {
|
|
6
|
+
if (!isRecord(sourceData))
|
|
7
|
+
return [];
|
|
8
|
+
const run = sourceData["runContext"];
|
|
9
|
+
if (run == null)
|
|
10
|
+
return [];
|
|
11
|
+
return array(record(run, "Endor run context")["versionControlProvenance"] ?? [], "Endor version control provenance").map((entry) => requiredText(record(entry, "Endor repository provenance")["repositoryUri"], "Endor repository URI"));
|
|
12
|
+
}
|
|
13
|
+
/** Saved Endor Finding objects, an array, or an unmasked ListFindingsResponse. */
|
|
14
|
+
export function normalizeEndorFindings(input, target = "cloud") {
|
|
15
|
+
const root = Array.isArray(input) ? null : record(input, "Endor report");
|
|
16
|
+
if (root?.["version"] === "2.1.0" && root["runs"] !== undefined)
|
|
17
|
+
return normalizeEndorSarif(root, target);
|
|
18
|
+
const list = root?.["list"] === undefined ? null : record(root["list"], "Endor list");
|
|
19
|
+
if (list) {
|
|
20
|
+
const response = record(list["response"] ?? {}, "Endor list response");
|
|
21
|
+
const token = response["next_page_token"];
|
|
22
|
+
if (text(response["next_page_id"]) ||
|
|
23
|
+
(token != null && token !== 0 && token !== "0" && token !== "")) {
|
|
24
|
+
throw new Error("The Endor list response has another page. Supply a complete export or an explicitly selected array.");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const values = list
|
|
28
|
+
? array(list["objects"] ?? [], "Endor list.objects")
|
|
29
|
+
: Array.isArray(input)
|
|
30
|
+
? input
|
|
31
|
+
: [input];
|
|
32
|
+
return normalizeRecords(values, (value, id) => {
|
|
33
|
+
const finding = record(value, "Endor finding");
|
|
34
|
+
const meta = record(finding["meta"], "Endor meta");
|
|
35
|
+
const spec = record(finding["spec"], "Endor spec");
|
|
36
|
+
requiredText(spec["project_uuid"], "Endor project_uuid");
|
|
37
|
+
const name = text(spec["target_dependency_name"]);
|
|
38
|
+
const paths = [
|
|
39
|
+
...new Set(strings(spec["dependency_file_paths"])
|
|
40
|
+
.map(relativePath)
|
|
41
|
+
.filter((p) => p !== null)),
|
|
42
|
+
];
|
|
43
|
+
const metadata = record(spec["finding_metadata"] ?? {}, "Endor finding_metadata");
|
|
44
|
+
const codeLocations = ["sast_data", "ai_sast_data"].flatMap((field) => {
|
|
45
|
+
const data = record(metadata[field] ?? {}, `Endor ${field}`);
|
|
46
|
+
const location = record(data["location"] ?? {}, `Endor ${field} location`);
|
|
47
|
+
const path = relativePath(location["relative_path"]);
|
|
48
|
+
if (path === null)
|
|
49
|
+
return [];
|
|
50
|
+
const line = location["start_line"];
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
path,
|
|
54
|
+
line: typeof line === "number" && Number.isSafeInteger(line) && line > 0
|
|
55
|
+
? line
|
|
56
|
+
: null,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
});
|
|
60
|
+
const locations = [
|
|
61
|
+
...paths
|
|
62
|
+
.filter((path) => !codeLocations.some((location) => location.path === path))
|
|
63
|
+
.map((path) => ({ path })),
|
|
64
|
+
...new Map(codeLocations.map((location) => [JSON.stringify(location), location])).values(),
|
|
65
|
+
];
|
|
66
|
+
const vulnerability = record(metadata["vulnerability"] ?? {}, "Endor vulnerability");
|
|
67
|
+
const advisory = text(record(vulnerability["meta"] ?? {}, "Vulnerability meta")["name"]);
|
|
68
|
+
const aliases = strings(record(vulnerability["spec"] ?? {}, "Vulnerability spec")["aliases"]);
|
|
69
|
+
const level = text(spec["level"])
|
|
70
|
+
?.replace(/^FINDING_LEVEL_/u, "")
|
|
71
|
+
.toLowerCase();
|
|
72
|
+
const severity = level && ["critical", "high", "medium", "low"].includes(level)
|
|
73
|
+
? level
|
|
74
|
+
: "unknown";
|
|
75
|
+
// A recommended version can refer to an introducing dependency; retain it in source_data.
|
|
76
|
+
const packages = name
|
|
77
|
+
? (paths.length ? paths : [null]).map((path) => ({
|
|
78
|
+
name,
|
|
79
|
+
ecosystem: text(spec["ecosystem"])
|
|
80
|
+
?.replace(/^ECOSYSTEM_/u, "")
|
|
81
|
+
.toLowerCase() ?? null,
|
|
82
|
+
installed_version: text(spec["target_dependency_version"]),
|
|
83
|
+
manifest_path: path,
|
|
84
|
+
fixed_versions: [],
|
|
85
|
+
}))
|
|
86
|
+
: [];
|
|
87
|
+
const context = record(finding["context"] ?? {}, "Endor context");
|
|
88
|
+
const updated = text(meta["update_time"]);
|
|
89
|
+
return {
|
|
90
|
+
source_finding_id: id,
|
|
91
|
+
evidence: validateExternalEvidence({
|
|
92
|
+
title: requiredText(meta["name"], "Endor finding title"),
|
|
93
|
+
description: [
|
|
94
|
+
text(spec["summary"]),
|
|
95
|
+
text(spec["explanation"]),
|
|
96
|
+
text(spec["remediation"]),
|
|
97
|
+
]
|
|
98
|
+
.filter(Boolean)
|
|
99
|
+
.join("\n\n") || text(meta["description"]),
|
|
100
|
+
severity,
|
|
101
|
+
branch: context["type"] === "CONTEXT_TYPE_REF"
|
|
102
|
+
? text(context["id"])
|
|
103
|
+
: null,
|
|
104
|
+
code_revision: text(record(spec["source_code_version"] ?? {}, "Endor source code version")["sha"]),
|
|
105
|
+
source_updated_at: updated === null ? null : Math.floor(Date.parse(updated) / 1000),
|
|
106
|
+
advisory_ids: [
|
|
107
|
+
...new Set([...(advisory ? [advisory] : []), ...aliases]),
|
|
108
|
+
],
|
|
109
|
+
packages,
|
|
110
|
+
locations,
|
|
111
|
+
source_data: structuredClone(finding),
|
|
112
|
+
}, target),
|
|
113
|
+
};
|
|
114
|
+
}, (value) => requiredText(record(value, "Endor finding")["uuid"], "Endor finding uuid"), target);
|
|
115
|
+
}
|
|
116
|
+
/** Endor's documented SARIF producer uses properties.finding-uuid, not its rule name. */
|
|
117
|
+
export function normalizeEndorSarif(input, target = "cloud") {
|
|
118
|
+
const document = record(input, "Endor SARIF");
|
|
119
|
+
if (document["version"] !== "2.1.0")
|
|
120
|
+
throw new Error("Expected Endor SARIF 2.1.0.");
|
|
121
|
+
const entries = array(document["runs"], "SARIF runs").flatMap((value) => {
|
|
122
|
+
const run = record(value, "SARIF run");
|
|
123
|
+
const tool = record(run["tool"], "SARIF tool");
|
|
124
|
+
const driver = record(tool["driver"], "SARIF driver");
|
|
125
|
+
if (driver["name"] !== "endorctl")
|
|
126
|
+
throw new Error("Expected the endorctl SARIF producer.");
|
|
127
|
+
if (hasSarifExternalPropertyReferences(run["externalPropertyFileReferences"]))
|
|
128
|
+
throw new Error("Use a self-contained Endor SARIF report.");
|
|
129
|
+
const rules = array(driver["rules"] ?? [], "Endor rules").map((r) => record(r, "Endor rule"));
|
|
130
|
+
const rulesById = new Map();
|
|
131
|
+
for (const [index, rule] of rules.entries()) {
|
|
132
|
+
const id = rule["id"];
|
|
133
|
+
rulesById.set(id, rulesById.has(id) ? null : { rule, index });
|
|
134
|
+
}
|
|
135
|
+
const { runs: _runs, ...documentContext } = document;
|
|
136
|
+
const { results: _results, tool: _tool, ...runContext } = run;
|
|
137
|
+
const { rules: _rules, ...driverContext } = driver;
|
|
138
|
+
const { driver: _driver, ...toolContext } = tool;
|
|
139
|
+
return array(run["results"] ?? [], "Endor results").map((result) => ({
|
|
140
|
+
result,
|
|
141
|
+
rulesById,
|
|
142
|
+
documentContext,
|
|
143
|
+
runContext,
|
|
144
|
+
driverContext,
|
|
145
|
+
toolContext,
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
return normalizeRecords(entries, ({ result: value, rulesById, ...context }, id) => {
|
|
149
|
+
const result = record(value, "Endor result");
|
|
150
|
+
const properties = record(result["properties"], "Endor result properties");
|
|
151
|
+
requiredText(properties["project-uuid"], "Endor project-uuid");
|
|
152
|
+
const ruleId = requiredText(result["ruleId"], "Endor ruleId");
|
|
153
|
+
const selectedRule = rulesById.get(ruleId);
|
|
154
|
+
if (!selectedRule)
|
|
155
|
+
throw new Error("Endor result must reference exactly one rule in its run.");
|
|
156
|
+
const { rule, index: ruleIndex } = selectedRule;
|
|
157
|
+
if (result["ruleIndex"] !== undefined &&
|
|
158
|
+
result["ruleIndex"] !== ruleIndex)
|
|
159
|
+
throw new Error("Endor ruleIndex and ruleId disagree.");
|
|
160
|
+
if (result["rule"] !== undefined) {
|
|
161
|
+
const reference = record(result["rule"], "Endor rule reference");
|
|
162
|
+
if (reference["toolComponent"] !== undefined ||
|
|
163
|
+
(reference["id"] !== undefined && reference["id"] !== ruleId) ||
|
|
164
|
+
(reference["index"] !== undefined &&
|
|
165
|
+
reference["index"] !== ruleIndex) ||
|
|
166
|
+
(reference["guid"] !== undefined &&
|
|
167
|
+
reference["guid"] !== rule["guid"]))
|
|
168
|
+
throw new Error("Inconsistent or external Endor rule reference.");
|
|
169
|
+
}
|
|
170
|
+
const message = record(result["message"], "Endor message");
|
|
171
|
+
const short = record(rule["shortDescription"] ?? {}, "Endor shortDescription");
|
|
172
|
+
const full = record(rule["fullDescription"] ?? {}, "Endor fullDescription");
|
|
173
|
+
const help = record(rule["help"] ?? {}, "Endor help");
|
|
174
|
+
const hasCodeLocations = strings(properties["categories"]).some((category) => category === "SAST" || category === "SECRETS");
|
|
175
|
+
const locations = array(result["locations"] ?? [], "Endor locations").flatMap((v) => {
|
|
176
|
+
const physical = record(record(v, "Endor location")["physicalLocation"] ?? {}, "Physical location");
|
|
177
|
+
const artifact = record(physical["artifactLocation"] ?? {}, "Artifact location");
|
|
178
|
+
if (artifact["index"] !== undefined ||
|
|
179
|
+
artifact["uriBaseId"] !== undefined)
|
|
180
|
+
return [];
|
|
181
|
+
const uri = text(artifact["uri"]);
|
|
182
|
+
if (uri === null || /^[A-Za-z][A-Za-z0-9+.-]*:/u.test(uri))
|
|
183
|
+
return [];
|
|
184
|
+
let path;
|
|
185
|
+
try {
|
|
186
|
+
path = relativePath(decodeURIComponent(uri));
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
if (path === null)
|
|
192
|
+
return [];
|
|
193
|
+
const line = hasCodeLocations
|
|
194
|
+
? record(physical["region"] ?? {}, "Endor region")["startLine"]
|
|
195
|
+
: null;
|
|
196
|
+
return [
|
|
197
|
+
{
|
|
198
|
+
path,
|
|
199
|
+
line: typeof line === "number" && Number.isSafeInteger(line) && line > 0
|
|
200
|
+
? line
|
|
201
|
+
: null,
|
|
202
|
+
},
|
|
203
|
+
];
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
source_finding_id: id,
|
|
207
|
+
evidence: validateExternalEvidence({
|
|
208
|
+
title: text(short["text"]) ?? text(rule["name"]) ?? ruleId,
|
|
209
|
+
url: text(properties["finding-url"]),
|
|
210
|
+
description: [
|
|
211
|
+
text(message["markdown"]) ?? text(message["text"]),
|
|
212
|
+
text(full["text"]),
|
|
213
|
+
text(help["markdown"]) ?? text(help["text"]),
|
|
214
|
+
]
|
|
215
|
+
.filter(Boolean)
|
|
216
|
+
.join("\n\n"),
|
|
217
|
+
// Diagnostic level and CVSS are not Endor's finding severity. Keep both as source evidence.
|
|
218
|
+
severity: "unknown",
|
|
219
|
+
locations: [
|
|
220
|
+
...new Map(locations.map((location) => [
|
|
221
|
+
JSON.stringify(location),
|
|
222
|
+
location,
|
|
223
|
+
])).values(),
|
|
224
|
+
],
|
|
225
|
+
source_data: structuredClone({
|
|
226
|
+
...context,
|
|
227
|
+
runContext: sarifRunContextForResult(context.runContext, result, rule, context.documentContext, context.driverContext, context.toolContext),
|
|
228
|
+
rule,
|
|
229
|
+
result,
|
|
230
|
+
}),
|
|
231
|
+
}, target),
|
|
232
|
+
};
|
|
233
|
+
}, ({ result }) => requiredText(record(record(result, "Endor result")["properties"], "Endor result properties")["finding-uuid"], "Endor finding-uuid"), target);
|
|
234
|
+
}
|
|
235
|
+
export async function readEndorFindings(path, target = "cloud") {
|
|
236
|
+
return normalizeEndorFindings(await readScannerJson(path), target);
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=endor-findings.js.map
|
|
@@ -0,0 +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,m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AAQ;qBACT,CAAC,CACH,CAAC,MAAM,EAAE;iBACX;gBACD,WAAW,EAAE,eAAe,CAAC;oBAC3B,GAAG,OAAO;oBACV,UAAU,EAAE,wBAAwB,CAClC,OAAO,CAAC,UAAU,EAClB,MAAM,EACN,IAAI,EACJ,OAAO,CAAC,eAAe,EACvB,OAAO,CAAC,aAAa,EACrB,OAAO,CAAC,WAAW,CACpB;oBACD,IAAI;oBACJ,MAAM;iBACP,CAAC;aACH,EACD,MAAM,CACP;SACF,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 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"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ExternalPublicationOptions } from "./external-findings-publish.js";
|
|
2
|
+
import { type LocalExternalImportDependencies } from "./external-findings-local.js";
|
|
3
|
+
/** Read an installed vendor format and prepare it for the local workbench. */
|
|
4
|
+
export declare function prepareLocalExternalImport(path: string, options: ExternalPublicationOptions, dependencies?: LocalExternalImportDependencies): Promise<import("./external-findings-local.js").PreparedLocalExternalImport>;
|
|
5
|
+
//# sourceMappingURL=external-findings-import.d.ts.map
|
|
@@ -0,0 +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;AAItC,8EAA8E;AAC9E,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,0BAA0B,EACnC,YAAY,GAAE,+BAAoC,+EA+CnD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { cloudRepositoryUrlKey, repositoryUrlKey, } from "./external-import-contract.js";
|
|
2
|
+
import { EXTERNAL_FINDINGS_PROVIDERS, readExternalFindings, } from "./external-findings-read.js";
|
|
3
|
+
import { prepareNormalizedLocalImport, } from "./external-findings-local.js";
|
|
4
|
+
import { abortable } from "./targets.js";
|
|
5
|
+
import { requireExternalImports } from "./external-imports-feature.js";
|
|
6
|
+
/** Read an installed vendor format and prepare it for the local workbench. */
|
|
7
|
+
export async function prepareLocalExternalImport(path, options, dependencies = {}) {
|
|
8
|
+
dependencies.signal?.throwIfAborted();
|
|
9
|
+
requireExternalImports(dependencies.environment);
|
|
10
|
+
const parsed = await abortable(() => readExternalFindings(path, options, "local"), dependencies.signal);
|
|
11
|
+
const normalizedOptions = {
|
|
12
|
+
...options,
|
|
13
|
+
provider: EXTERNAL_FINDINGS_PROVIDERS[options.provider],
|
|
14
|
+
};
|
|
15
|
+
let sourceRepositories = parsed.sourceRepositories ?? [];
|
|
16
|
+
if (normalizedOptions.provider === "semgrep") {
|
|
17
|
+
// The Cloud reader allows custom GitHub casing. Local provenance must also
|
|
18
|
+
// agree with the caller's source URL when the checkout has no remote.
|
|
19
|
+
const source = options.sourceRepositoryUrl;
|
|
20
|
+
const knownGitHub = dependencies.sourceRepositories?.some(({ url, platform }) => platform === "github" &&
|
|
21
|
+
cloudRepositoryUrlKey(url) === cloudRepositoryUrlKey(source));
|
|
22
|
+
const key = knownGitHub ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
23
|
+
for (const reference of sourceRepositories) {
|
|
24
|
+
if (key(reference.url) !== key(source))
|
|
25
|
+
throw new Error("SARIF source repository does not match the declared source repository URL.");
|
|
26
|
+
}
|
|
27
|
+
if (knownGitHub)
|
|
28
|
+
sourceRepositories = [
|
|
29
|
+
{ url: source, platform: "github" },
|
|
30
|
+
...sourceRepositories.map((reference) => ({
|
|
31
|
+
...reference,
|
|
32
|
+
platform: "github",
|
|
33
|
+
})),
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
const { environment, ...workbench } = dependencies;
|
|
37
|
+
return prepareNormalizedLocalImport(parsed.findings, normalizedOptions, {
|
|
38
|
+
...workbench,
|
|
39
|
+
environment,
|
|
40
|
+
sourceRepositories: [
|
|
41
|
+
...(dependencies.sourceRepositories ?? []),
|
|
42
|
+
...sourceRepositories,
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=external-findings-import.js.map
|
|
@@ -0,0 +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,4BAA4B,GAE7B,MAAM,8BAA8B,CAAC;AACtC,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,MAAM,GAAG,MAAM,SAAS,CAC5B,GAAG,EAAE,CAAC,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,EAClD,YAAY,CAAC,MAAM,CACpB,CAAC;IACF,MAAM,iBAAiB,GAAG;QACxB,GAAG,OAAO;QACV,QAAQ,EAAE,2BAA2B,CAAC,OAAO,CAAC,QAAQ,CAAC;KACxD,CAAC;IACF,IAAI,kBAAkB,GAAG,MAAM,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esContent":["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 prepareNormalizedLocalImport,\n type LocalExternalImportDependencies,\n} from \"./external-findings-local.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 parsed = await abortable(\n () => readExternalFindings(path, options, \"local\"),\n dependencies.signal,\n );\n const normalizedOptions = {\n ...options,\n provider: EXTERNAL_FINDINGS_PROVIDERS[options.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 = options.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 prepareNormalizedLocalImport(parsed.findings, normalizedOptions, {\n ...workbench,\n environment,\n sourceRepositories: [\n ...(dependencies.sourceRepositories ?? []),\n ...sourceRepositories,\n ],\n });\n}\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ExternalFindings, ExternalSourceRepository } from "./external-findings.js";
|
|
2
|
+
import type { ExternalFindingEvidence, Provider } from "./external-import-models.js";
|
|
3
|
+
import { runWorkbench } from "./runtime.js";
|
|
4
|
+
/** A scanner source record, independent of a Codex assessment or completed scan. */
|
|
5
|
+
export interface StoredExternalFinding {
|
|
6
|
+
id: string;
|
|
7
|
+
repository: string;
|
|
8
|
+
provider: Provider;
|
|
9
|
+
sourceKey: string;
|
|
10
|
+
sourceFindingId: string;
|
|
11
|
+
evidence: ExternalFindingEvidence;
|
|
12
|
+
assessment: {
|
|
13
|
+
state: "not_assessed";
|
|
14
|
+
};
|
|
15
|
+
version: number;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
updatedAt: string;
|
|
18
|
+
}
|
|
19
|
+
export interface NormalizedLocalImportOptions {
|
|
20
|
+
/** Local checkout or source directory to associate with these records. */
|
|
21
|
+
repository: string;
|
|
22
|
+
provider: Provider;
|
|
23
|
+
/** Stable scanner organization/project/branch namespace across imports. */
|
|
24
|
+
sourceKey: string;
|
|
25
|
+
}
|
|
26
|
+
export interface LocalExternalImportDependencies {
|
|
27
|
+
environment?: NodeJS.ProcessEnv;
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
runWorkbench?: typeof runWorkbench;
|
|
30
|
+
/** Repository references supplied by a reader outside its projected evidence. */
|
|
31
|
+
sourceRepositories?: readonly ExternalSourceRepository[];
|
|
32
|
+
}
|
|
33
|
+
export interface LocalExternalImportPreview extends ExternalFindings {
|
|
34
|
+
repository: string;
|
|
35
|
+
source: {
|
|
36
|
+
provider: Provider;
|
|
37
|
+
source_key: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export interface LocalExternalImportResult {
|
|
41
|
+
repository: string;
|
|
42
|
+
read: number;
|
|
43
|
+
ready: number;
|
|
44
|
+
excluded: ExternalFindings["excluded"];
|
|
45
|
+
findings: StoredExternalFinding[];
|
|
46
|
+
counts: {
|
|
47
|
+
created: number;
|
|
48
|
+
updated: number;
|
|
49
|
+
unchanged: number;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export interface PreparedLocalExternalImport {
|
|
53
|
+
preview: LocalExternalImportPreview;
|
|
54
|
+
import(): Promise<LocalExternalImportResult>;
|
|
55
|
+
}
|
|
56
|
+
/** Prepare scanner evidence without writing state or performing a security assessment. */
|
|
57
|
+
export declare function prepareNormalizedLocalImport(input: ExternalFindings, options: NormalizedLocalImportOptions, dependencies?: LocalExternalImportDependencies): Promise<PreparedLocalExternalImport>;
|
|
58
|
+
/** Read imported source records, including evidence that has not been assessed by Codex. */
|
|
59
|
+
export declare function listLocalExternalFindings(selection: {
|
|
60
|
+
repository: string;
|
|
61
|
+
id?: string;
|
|
62
|
+
}, dependencies?: LocalExternalImportDependencies): Promise<StoredExternalFinding[]>;
|
|
63
|
+
//# sourceMappingURL=external-findings-local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"external-findings-local.d.ts","sourceRoot":"","sources":["../src/external-findings-local.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,KAAK,EACV,uBAAuB,EACvB,QAAQ,EACT,MAAM,6BAA6B,CAAC;AAGrC,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,E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