@openai/codex-security 0.8.1 → 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 +8 -2
- 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/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_target.py +0 -108
- package/_bundled_plugin/skills/publish-findings/SKILL.md +4 -0
- 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/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.js +3 -3
- package/dist/api.js.map +1 -1
- package/dist/auth.js +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +27 -8
- package/dist/cli.js.map +1 -1
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +4 -4
- package/dist/contract.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 +117 -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 +51 -27
- 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/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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -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 -1
- package/dist/scanner-import.d.ts.map +1 -1
- package/dist/scanner-import.js +14 -5
- 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 +14 -8
- package/docs/dedupe-records.md +17 -4
- package/package.json +3 -3
- package/schemas/external-findings.schema.json +1 -1
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
import { posix } from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import validSemver from "semver/functions/valid.js";
|
|
4
|
+
import { cloudRepositoryUrlKey, repositoryUrlKey, validateExternalEvidence, } from "./external-import-contract.js";
|
|
5
|
+
import { isGitHubCloudHost } from "./git-remote.js";
|
|
6
|
+
import { CodexSecurityError, errorMessage } from "./errors.js";
|
|
7
|
+
import { isRecord } from "./record.js";
|
|
8
|
+
import { normalizeRecords, readScannerJson, record, relativePath, requiredText, text, } from "./scanner-import.js";
|
|
9
|
+
const listFindings = z.strictObject({ findings: z.array(z.unknown()) });
|
|
10
|
+
const format = "aws-inspector2-list-findings/v1";
|
|
11
|
+
const findingArn = /^(arn:(aws[a-zA-Z-]*):inspector2:([a-z]{2}(?:-gov)?-[a-z]+-\d):(\d{12})):finding\/[a-f0-9]{32}$/u;
|
|
12
|
+
const integrationArn = /^arn:aws[a-zA-Z-]*:inspector2:[a-z]{2}(?:-gov)?-[a-z]+-\d:\d{12}:codesecurity-integration\/[a-f0-9-]{36}$/u;
|
|
13
|
+
const projectSuffix = /^project-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/u;
|
|
14
|
+
const absoluteUrl = /^[a-z][a-z\d+.-]*:\/\//iu;
|
|
15
|
+
function repositoryUrl(value) {
|
|
16
|
+
const raw = requiredText(value, "Inspector --source-repository-url");
|
|
17
|
+
const url = URL.parse(raw);
|
|
18
|
+
const path = /^https?:\/\/[^/?#]+(\/[^?#]+)$/iu.exec(raw)?.[1];
|
|
19
|
+
if (!url ||
|
|
20
|
+
!path ||
|
|
21
|
+
url.username ||
|
|
22
|
+
url.password ||
|
|
23
|
+
/[\s\\?#]|%(?:2f|5c)/iu.test(raw) ||
|
|
24
|
+
path !== url.pathname ||
|
|
25
|
+
!/^\/[^/]+(?:\/[^/]+)+\/?$/u.test(path))
|
|
26
|
+
throw new Error("Use a complete HTTP(S) Inspector source repository URL with a namespace and repository, without credentials, query or fragment.");
|
|
27
|
+
return raw;
|
|
28
|
+
}
|
|
29
|
+
function projectIntegration(projectArn) {
|
|
30
|
+
const separator = projectArn.lastIndexOf("/");
|
|
31
|
+
const parent = projectArn.slice(0, separator);
|
|
32
|
+
if (!integrationArn.test(parent) ||
|
|
33
|
+
!projectSuffix.test(projectArn.slice(separator + 1)))
|
|
34
|
+
throw new Error("Expected a full Inspector repository project ARN.");
|
|
35
|
+
return parent;
|
|
36
|
+
}
|
|
37
|
+
/** @internal Validate an operator-supplied project binding. */
|
|
38
|
+
export function validateInspectorProjectMapping(projectArn, canonicalUrl) {
|
|
39
|
+
projectIntegration(projectArn);
|
|
40
|
+
return repositoryUrl(canonicalUrl);
|
|
41
|
+
}
|
|
42
|
+
function identity(finding) {
|
|
43
|
+
const arn = requiredText(finding["findingArn"], "Inspector finding ARN");
|
|
44
|
+
const match = findingArn.exec(arn);
|
|
45
|
+
if (!match)
|
|
46
|
+
throw new Error("Expected an Inspector2 finding ARN.");
|
|
47
|
+
if (finding["awsAccountId"] !== match[4])
|
|
48
|
+
throw new Error("Inspector finding ARN and AWS account do not match.");
|
|
49
|
+
return {
|
|
50
|
+
arn,
|
|
51
|
+
issuer: match[1],
|
|
52
|
+
partition: match[2],
|
|
53
|
+
region: match[3],
|
|
54
|
+
account: match[4],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function repositoryClaim({ issuer, partition, region, account }, resource) {
|
|
58
|
+
for (const [field, expected] of Object.entries({
|
|
59
|
+
partition,
|
|
60
|
+
region,
|
|
61
|
+
provider: "AWS",
|
|
62
|
+
providerAccountId: account,
|
|
63
|
+
})) {
|
|
64
|
+
if (resource[field] !== undefined && resource[field] !== expected)
|
|
65
|
+
throw new Error("Inspector repository resource and finding scope do not match.");
|
|
66
|
+
}
|
|
67
|
+
const { codeRepository } = record(resource["details"] ?? {}, "Inspector resource details");
|
|
68
|
+
const repo = record(codeRepository ?? {}, "Inspector codeRepository");
|
|
69
|
+
const optional = (field) => repo[field] === undefined
|
|
70
|
+
? undefined
|
|
71
|
+
: requiredText(repo[field], `Inspector codeRepository.${field}`);
|
|
72
|
+
const nativeId = requiredText(resource["id"], "Inspector repository resource ID");
|
|
73
|
+
let integration = optional("integrationArn");
|
|
74
|
+
if (integration !== undefined &&
|
|
75
|
+
(!integration.startsWith(issuer + ":") || !integrationArn.test(integration)))
|
|
76
|
+
throw new Error("Inspector integration ARN does not match the finding scope.");
|
|
77
|
+
if (nativeId.startsWith("arn:")) {
|
|
78
|
+
const parent = projectIntegration(nativeId);
|
|
79
|
+
if (!parent.startsWith(issuer + ":") ||
|
|
80
|
+
(integration !== undefined && parent !== integration))
|
|
81
|
+
throw new Error("Inspector repository resource ARN does not match its project or integration.");
|
|
82
|
+
integration = parent;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
project: JSON.stringify([issuer, nativeId]),
|
|
86
|
+
integration,
|
|
87
|
+
provider: optional("providerType"),
|
|
88
|
+
nativeId,
|
|
89
|
+
name: optional("projectName"),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function checkRepositoryMapping({ nativeId, name }, source, provider, target, projectMap) {
|
|
93
|
+
const hostname = new URL(source).hostname;
|
|
94
|
+
const knownGitHub = isGitHubCloudHost(hostname);
|
|
95
|
+
const gitlab = provider === "GITLAB_SELF_MANAGED";
|
|
96
|
+
const github = provider === "GITHUB" || knownGitHub;
|
|
97
|
+
if (hostname === "gitlab.com" ||
|
|
98
|
+
(gitlab && knownGitHub) ||
|
|
99
|
+
(provider !== undefined && !gitlab && provider !== "GITHUB"))
|
|
100
|
+
throw new Error("Inspector repository provider does not match the selected mapping.");
|
|
101
|
+
if (target === "cloud" && !github)
|
|
102
|
+
throw new Error("Inspector Cloud requires a GitHub repository provider; self-managed GitLab is local only.");
|
|
103
|
+
const urls = [nativeId, name].filter((url) => !!url && absoluteUrl.test(url));
|
|
104
|
+
const key = github && !projectMap ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
105
|
+
const path = new URL((github ? cloudRepositoryUrlKey : repositoryUrlKey)(source)).pathname.slice(1);
|
|
106
|
+
const slug = github ? name?.toLowerCase() : name;
|
|
107
|
+
const matchesSlug = !slug ||
|
|
108
|
+
absoluteUrl.test(slug) ||
|
|
109
|
+
slug === path ||
|
|
110
|
+
slug === posix.basename(path) ||
|
|
111
|
+
(gitlab && projectMap && path.endsWith("/" + slug));
|
|
112
|
+
if (!matchesSlug ||
|
|
113
|
+
urls.some((url) => key(repositoryUrl(url)) !== key(source)))
|
|
114
|
+
throw new Error("Inspector native repository does not match --source-repository-url.");
|
|
115
|
+
if (projectMap) {
|
|
116
|
+
// repositoryClaim validated this ARN and its issuer before the lookup.
|
|
117
|
+
const trustedUrl = nativeId.startsWith("arn:")
|
|
118
|
+
? projectMap.get(nativeId)
|
|
119
|
+
: undefined;
|
|
120
|
+
if (trustedUrl === undefined)
|
|
121
|
+
throw new Error("Inspector project ARN is missing from the trusted mapping.");
|
|
122
|
+
if (repositoryUrlKey(repositoryUrl(trustedUrl)) !== repositoryUrlKey(source))
|
|
123
|
+
throw new Error("Inspector project ARN mapping does not match the source repository URL.");
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
return urls.length > 0;
|
|
127
|
+
}
|
|
128
|
+
function repositoryClaims(finding) {
|
|
129
|
+
if (!isRecord(finding) || !Array.isArray(finding["resources"]))
|
|
130
|
+
return [];
|
|
131
|
+
const claims = [];
|
|
132
|
+
let origin;
|
|
133
|
+
for (const resource of finding["resources"]) {
|
|
134
|
+
if (!isRecord(resource) || resource["type"] !== "CODE_REPOSITORY")
|
|
135
|
+
continue;
|
|
136
|
+
origin ??= identity(finding);
|
|
137
|
+
claims.push(repositoryClaim(origin, resource));
|
|
138
|
+
}
|
|
139
|
+
return claims;
|
|
140
|
+
}
|
|
141
|
+
/** Claims from the whole export must identify one project, including excluded rows. */
|
|
142
|
+
function checkReportScope(rows, target, projectMap, exclude = (_, error) => {
|
|
143
|
+
throw error;
|
|
144
|
+
}) {
|
|
145
|
+
const claims = rows.flatMap((row) => row.claims);
|
|
146
|
+
function shared(field) {
|
|
147
|
+
const values = new Set(claims.map((claim) => claim[field]));
|
|
148
|
+
values.delete(undefined);
|
|
149
|
+
if (values.size > 1)
|
|
150
|
+
throw new Error("Inspector export identifies more than one repository project or integration.");
|
|
151
|
+
return values.values().next().value;
|
|
152
|
+
}
|
|
153
|
+
shared("project");
|
|
154
|
+
shared("integration");
|
|
155
|
+
const provider = shared("provider");
|
|
156
|
+
// A bare project ID can recur across integrations in the same account and Region.
|
|
157
|
+
const sharedProvider = claims.find((claim) => claim.integration && claim.provider)?.provider;
|
|
158
|
+
const providerFor = (claim) => claim.provider ?? (claim.integration ? sharedProvider : undefined);
|
|
159
|
+
const missingHost = () => new Error("Inspector needs a matching native repository URL or a trusted project ARN mapping to identify the Git host.");
|
|
160
|
+
const needHost = [];
|
|
161
|
+
let sharedHost = false;
|
|
162
|
+
for (const row of rows) {
|
|
163
|
+
try {
|
|
164
|
+
// Only a fully verified row can supply evidence to another row.
|
|
165
|
+
const scopedMatches = row.claims.flatMap((claim) => {
|
|
166
|
+
const proven = checkRepositoryMapping(claim, row.source, providerFor(claim), target, projectMap);
|
|
167
|
+
if (claim.integration)
|
|
168
|
+
return [proven];
|
|
169
|
+
if (!proven)
|
|
170
|
+
throw missingHost();
|
|
171
|
+
return [];
|
|
172
|
+
});
|
|
173
|
+
if (scopedMatches.includes(true))
|
|
174
|
+
sharedHost = true;
|
|
175
|
+
else if (scopedMatches.length)
|
|
176
|
+
needHost.push(row);
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
exclude(row, error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (!sharedHost)
|
|
183
|
+
for (const row of needHost)
|
|
184
|
+
exclude(row, missingHost());
|
|
185
|
+
return claims.every((claim) => providerFor(claim) === provider)
|
|
186
|
+
? provider
|
|
187
|
+
: undefined;
|
|
188
|
+
}
|
|
189
|
+
const nonempty = z.string().regex(/\S/u, "Expected nonempty text.");
|
|
190
|
+
const optionalValue = z.unknown().optional();
|
|
191
|
+
const absent = z.never().optional();
|
|
192
|
+
const vulnerablePackage = z.object({
|
|
193
|
+
name: nonempty,
|
|
194
|
+
version: nonempty,
|
|
195
|
+
packageManager: optionalValue,
|
|
196
|
+
epoch: optionalValue,
|
|
197
|
+
release: optionalValue,
|
|
198
|
+
fixedInVersion: optionalValue,
|
|
199
|
+
filePath: optionalValue,
|
|
200
|
+
sourceLayerHash: absent,
|
|
201
|
+
sourceLambdaLayerArn: absent,
|
|
202
|
+
});
|
|
203
|
+
const repositoryFinding = z.object({
|
|
204
|
+
type: z.enum(["PACKAGE_VULNERABILITY", "CODE_VULNERABILITY"]),
|
|
205
|
+
resources: z
|
|
206
|
+
.array(z.object({
|
|
207
|
+
type: z.literal("CODE_REPOSITORY"),
|
|
208
|
+
details: z.strictObject({ codeRepository: optionalValue }).nullish(),
|
|
209
|
+
}))
|
|
210
|
+
.min(1),
|
|
211
|
+
networkReachabilityDetails: absent,
|
|
212
|
+
packageVulnerabilityDetails: z
|
|
213
|
+
.object({
|
|
214
|
+
vulnerabilityId: nonempty,
|
|
215
|
+
source: nonempty,
|
|
216
|
+
sourceUrl: optionalValue,
|
|
217
|
+
relatedVulnerabilities: z.array(nonempty).nullish(),
|
|
218
|
+
vulnerablePackages: z.array(vulnerablePackage).nullish(),
|
|
219
|
+
})
|
|
220
|
+
.optional(),
|
|
221
|
+
codeVulnerabilityDetails: z
|
|
222
|
+
.object({
|
|
223
|
+
detectorName: nonempty,
|
|
224
|
+
detectorId: nonempty,
|
|
225
|
+
cwes: z.array(z.unknown()),
|
|
226
|
+
filePath: z.object({
|
|
227
|
+
fileName: optionalValue,
|
|
228
|
+
filePath: optionalValue,
|
|
229
|
+
startLine: optionalValue,
|
|
230
|
+
}),
|
|
231
|
+
sourceLambdaLayerArn: absent,
|
|
232
|
+
})
|
|
233
|
+
.optional(),
|
|
234
|
+
});
|
|
235
|
+
function selectedFinding(value) {
|
|
236
|
+
const native = record(value, "Inspector finding");
|
|
237
|
+
const parsed = repositoryFinding.safeParse(native);
|
|
238
|
+
if (!parsed.success)
|
|
239
|
+
throw new Error(`Expected an Inspector vulnerability on CODE_REPOSITORY resources. ${z.prettifyError(parsed.error)}`);
|
|
240
|
+
const { type, packageVulnerabilityDetails: pkg, codeVulnerabilityDetails: code, } = parsed.data;
|
|
241
|
+
if ((pkg && type !== "PACKAGE_VULNERABILITY") ||
|
|
242
|
+
(code && type !== "CODE_VULNERABILITY"))
|
|
243
|
+
throw new Error("Inspector finding contains details for a different finding type.");
|
|
244
|
+
return { native, pkg, code };
|
|
245
|
+
}
|
|
246
|
+
function isInspectorFinding(value, occurrenceId) {
|
|
247
|
+
return (isRecord(value) &&
|
|
248
|
+
typeof value["findingArn"] === "string" &&
|
|
249
|
+
findingArn.test(value["findingArn"]) &&
|
|
250
|
+
(occurrenceId === undefined || value["findingArn"] === occurrenceId) &&
|
|
251
|
+
Array.isArray(value["resources"]));
|
|
252
|
+
}
|
|
253
|
+
function hasInspectorEvidence(sourceData, occurrenceId) {
|
|
254
|
+
return (isRecord(sourceData) &&
|
|
255
|
+
(sourceData["format"] === format ||
|
|
256
|
+
isInspectorFinding(sourceData["finding"], occurrenceId) ||
|
|
257
|
+
isInspectorFinding(sourceData, occurrenceId)));
|
|
258
|
+
}
|
|
259
|
+
export function inspectorReportRepository(provider, findings, target, projectMap) {
|
|
260
|
+
if (provider !== "inspector") {
|
|
261
|
+
if (findings.some(({ evidence, source_finding_id }) => hasInspectorEvidence(evidence.source_data, source_finding_id)))
|
|
262
|
+
throw new CodexSecurityError("Retained Inspector evidence requires the inspector provider.");
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
const retained = [];
|
|
266
|
+
for (const { source_finding_id: id, evidence } of findings) {
|
|
267
|
+
const data = evidence.source_data;
|
|
268
|
+
if (!isRecord(data) || data["format"] !== format) {
|
|
269
|
+
if (projectMap || hasInspectorEvidence(data) || findingArn.test(id))
|
|
270
|
+
throw new Error("Expected retained Inspector ListFindings evidence for the finding ARN.");
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
const source = repositoryUrl(data["sourceRepositoryUrl"]);
|
|
274
|
+
const { native: finding } = selectedFinding(data["finding"]);
|
|
275
|
+
if (finding["findingArn"] !== id)
|
|
276
|
+
throw new Error("Inspector source_finding_id does not match the retained finding ARN.");
|
|
277
|
+
retained.push({
|
|
278
|
+
source,
|
|
279
|
+
claims: repositoryClaims(finding),
|
|
280
|
+
id,
|
|
281
|
+
declared: evidence.details?.repository?.url,
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
const first = retained[0];
|
|
285
|
+
if (!first)
|
|
286
|
+
return undefined;
|
|
287
|
+
// A supplied map owns the path casing on custom hosts.
|
|
288
|
+
const github = checkReportScope(retained, target, projectMap) === "GITHUB" && !projectMap;
|
|
289
|
+
const key = github || target === "cloud" ? cloudRepositoryUrlKey : repositoryUrlKey;
|
|
290
|
+
const repository = key(first.source);
|
|
291
|
+
for (const { source, declared } of retained) {
|
|
292
|
+
if (key(source) !== repository)
|
|
293
|
+
throw new Error("Inspector export identifies more than one source repository.");
|
|
294
|
+
if (declared && key(declared) !== repository)
|
|
295
|
+
throw new Error("Retained scanner repository does not match the normalized evidence repository.");
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
findingId: first.id,
|
|
299
|
+
url: first.source,
|
|
300
|
+
...(github && { platform: "github" }),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function repoFile(value) {
|
|
304
|
+
const relative = relativePath(value);
|
|
305
|
+
if (!relative)
|
|
306
|
+
return null;
|
|
307
|
+
const path = posix.normalize(relative);
|
|
308
|
+
return path === "." ||
|
|
309
|
+
path.endsWith("/") ||
|
|
310
|
+
/^(?:[a-z][a-z\d+.-]*:|~[^/]*(?:\/|$)|[^/]+@[^/]+:)/iu.test(path)
|
|
311
|
+
? null
|
|
312
|
+
: path;
|
|
313
|
+
}
|
|
314
|
+
function timestamp(value) {
|
|
315
|
+
const seconds = typeof value === "number"
|
|
316
|
+
? value
|
|
317
|
+
: typeof value === "string" &&
|
|
318
|
+
/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.\d+)?(?:Z|[+-]\d\d:\d\d)$/u.test(value)
|
|
319
|
+
? Date.parse(value) / 1000
|
|
320
|
+
: NaN;
|
|
321
|
+
if (!Number.isFinite(seconds))
|
|
322
|
+
throw new Error("Invalid Inspector timestamp.");
|
|
323
|
+
return Math.floor(seconds);
|
|
324
|
+
}
|
|
325
|
+
const ecosystems = new Map(Object.entries({
|
|
326
|
+
BUNDLER: "rubygems",
|
|
327
|
+
GEMSPEC: "rubygems",
|
|
328
|
+
CARGO: "cargo",
|
|
329
|
+
COMPOSER: "composer",
|
|
330
|
+
NPM: "npm",
|
|
331
|
+
YARN: "npm",
|
|
332
|
+
NODEPKG: "npm",
|
|
333
|
+
NUGET: "nuget",
|
|
334
|
+
DOTNET_CORE: "nuget",
|
|
335
|
+
GOBINARY: "go",
|
|
336
|
+
GOMOD: "go",
|
|
337
|
+
JAR: "java",
|
|
338
|
+
POM: "maven",
|
|
339
|
+
PIP: "pypi",
|
|
340
|
+
PIPENV: "pypi",
|
|
341
|
+
POETRY: "pypi",
|
|
342
|
+
PYTHONPKG: "pypi",
|
|
343
|
+
}));
|
|
344
|
+
const manifests = new Set([
|
|
345
|
+
"package.json",
|
|
346
|
+
"package-lock.json",
|
|
347
|
+
"npm-shrinkwrap.json",
|
|
348
|
+
"yarn.lock",
|
|
349
|
+
"pnpm-lock.yaml",
|
|
350
|
+
"Cargo.toml",
|
|
351
|
+
"Cargo.lock",
|
|
352
|
+
"composer.json",
|
|
353
|
+
"composer.lock",
|
|
354
|
+
"Gemfile",
|
|
355
|
+
"Gemfile.lock",
|
|
356
|
+
"go.mod",
|
|
357
|
+
"go.sum",
|
|
358
|
+
"pom.xml",
|
|
359
|
+
"build.gradle",
|
|
360
|
+
"build.gradle.kts",
|
|
361
|
+
"gradle.lockfile",
|
|
362
|
+
"Pipfile",
|
|
363
|
+
"Pipfile.lock",
|
|
364
|
+
"poetry.lock",
|
|
365
|
+
"pyproject.toml",
|
|
366
|
+
"uv.lock",
|
|
367
|
+
"packages.config",
|
|
368
|
+
"packages.lock.json",
|
|
369
|
+
]);
|
|
370
|
+
function manifestPath(path) {
|
|
371
|
+
if (!path)
|
|
372
|
+
return null;
|
|
373
|
+
const name = posix.basename(path);
|
|
374
|
+
return manifests.has(name) ||
|
|
375
|
+
/^requirements(?:[-_.].*)?\.txt$/u.test(name) ||
|
|
376
|
+
/\.(?:csproj|fsproj|vbproj|gemspec)$/u.test(name)
|
|
377
|
+
? path
|
|
378
|
+
: null;
|
|
379
|
+
}
|
|
380
|
+
function concreteVersion(value, ecosystem, osPackage) {
|
|
381
|
+
const version = text(value);
|
|
382
|
+
if (!version)
|
|
383
|
+
return null;
|
|
384
|
+
// Debian versions use internal tildes for prereleases and backports.
|
|
385
|
+
if (osPackage && version.includes("~"))
|
|
386
|
+
return /^(?:\d+:)?\d[a-z\d.+~]*(?:-[a-z\d.+~]+)*$/iu.test(version)
|
|
387
|
+
? version
|
|
388
|
+
: null;
|
|
389
|
+
if (validSemver(version))
|
|
390
|
+
return version;
|
|
391
|
+
if (ecosystem === "npm" || ecosystem === "cargo")
|
|
392
|
+
return null;
|
|
393
|
+
if (ecosystem === "java" || ecosystem === "maven") {
|
|
394
|
+
if (version === "LATEST" ||
|
|
395
|
+
version === "RELEASE" ||
|
|
396
|
+
version.startsWith("latest."))
|
|
397
|
+
return null;
|
|
398
|
+
return /^[a-z\d][\w.+-]*$/iu.test(version) && !version.endsWith("+")
|
|
399
|
+
? version
|
|
400
|
+
: null;
|
|
401
|
+
}
|
|
402
|
+
if (!ecosystem && version.endsWith("+"))
|
|
403
|
+
return null;
|
|
404
|
+
const publicVersion = ecosystem === "pypi" ? version.split("+", 1)[0] : version;
|
|
405
|
+
return /\d/u.test(version) &&
|
|
406
|
+
/^(?:\d+:)?[a-z\d][\w.+!-]*$/iu.test(version) &&
|
|
407
|
+
!/(?:^|\.)x(?:\.|$)/iu.test(publicVersion)
|
|
408
|
+
? version
|
|
409
|
+
: null;
|
|
410
|
+
}
|
|
411
|
+
function evidence({ native: finding, pkg, code }, id, source, target) {
|
|
412
|
+
const { description, severity, remediation, firstObservedAt, lastObservedAt, updatedAt, status, } = finding;
|
|
413
|
+
const { recommendation } = record(remediation, "Inspector remediation");
|
|
414
|
+
record(recommendation ?? {}, "Inspector recommendation");
|
|
415
|
+
requiredText(status, "Inspector status");
|
|
416
|
+
timestamp(firstObservedAt);
|
|
417
|
+
timestamp(lastObservedAt);
|
|
418
|
+
const level = requiredText(severity, "Inspector severity").toLowerCase();
|
|
419
|
+
const paths = new Set();
|
|
420
|
+
const packages = (pkg?.vulnerablePackages ?? []).map((item) => {
|
|
421
|
+
const path = repoFile(item.filePath);
|
|
422
|
+
if (path)
|
|
423
|
+
paths.add(path);
|
|
424
|
+
const ecosystem = ecosystems.get(text(item.packageManager) ?? "") ?? null;
|
|
425
|
+
const version = (value) => concreteVersion(value, ecosystem, item.packageManager === "OS");
|
|
426
|
+
const fixed = version(item.fixedInVersion);
|
|
427
|
+
const splitVersion = item.packageManager === "OS" &&
|
|
428
|
+
(item.epoch != null || item.release != null);
|
|
429
|
+
return {
|
|
430
|
+
name: item.name,
|
|
431
|
+
ecosystem,
|
|
432
|
+
installed_version: splitVersion ? null : version(item.version),
|
|
433
|
+
manifest_path: manifestPath(path),
|
|
434
|
+
fixed_versions: fixed ? [fixed] : [],
|
|
435
|
+
};
|
|
436
|
+
});
|
|
437
|
+
const locations = [...paths].map((path) => ({ path, line: null }));
|
|
438
|
+
if (code) {
|
|
439
|
+
const { fileName, filePath, startLine } = code.filePath;
|
|
440
|
+
const path = repoFile(filePath);
|
|
441
|
+
if (path && posix.basename(path) === fileName)
|
|
442
|
+
locations.push({
|
|
443
|
+
path,
|
|
444
|
+
line: typeof startLine === "number" &&
|
|
445
|
+
Number.isSafeInteger(startLine) &&
|
|
446
|
+
startLine > 0
|
|
447
|
+
? startLine
|
|
448
|
+
: null,
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
return validateExternalEvidence({
|
|
452
|
+
title: text(finding["title"]) ??
|
|
453
|
+
pkg?.vulnerabilityId ??
|
|
454
|
+
code?.detectorName ??
|
|
455
|
+
id,
|
|
456
|
+
description: requiredText(description, "Inspector description"),
|
|
457
|
+
severity: ["critical", "high", "medium", "low", "informational"].includes(level)
|
|
458
|
+
? level
|
|
459
|
+
: "unknown",
|
|
460
|
+
url: text(pkg?.sourceUrl),
|
|
461
|
+
advisory_ids: pkg
|
|
462
|
+
? [
|
|
463
|
+
...new Set([
|
|
464
|
+
pkg.vulnerabilityId,
|
|
465
|
+
...(pkg.relatedVulnerabilities ?? []),
|
|
466
|
+
]),
|
|
467
|
+
]
|
|
468
|
+
: [],
|
|
469
|
+
packages,
|
|
470
|
+
locations,
|
|
471
|
+
source_updated_at: updatedAt === undefined ? null : timestamp(updatedAt),
|
|
472
|
+
source_data: {
|
|
473
|
+
format,
|
|
474
|
+
sourceRepositoryUrl: source,
|
|
475
|
+
finding: structuredClone(finding),
|
|
476
|
+
},
|
|
477
|
+
}, target);
|
|
478
|
+
}
|
|
479
|
+
export function normalizeInspectorFindings(input, sourceRepositoryUrl, target = "cloud", projectMap) {
|
|
480
|
+
const source = repositoryUrl(sourceRepositoryUrl);
|
|
481
|
+
if (isRecord(input) &&
|
|
482
|
+
(Object.hasOwn(input, "NextToken") || Object.hasOwn(input, "nextToken")))
|
|
483
|
+
throw new Error("Inspector export has a continuation key; supply the complete paginated CLI JSON output.");
|
|
484
|
+
const report = listFindings.safeParse(input);
|
|
485
|
+
if (!report.success)
|
|
486
|
+
throw new Error("Expected only a complete native Inspector ListFindings response with a findings array.");
|
|
487
|
+
const rows = report.data.findings.map((finding, i) => ({
|
|
488
|
+
finding,
|
|
489
|
+
source,
|
|
490
|
+
position: i + 1,
|
|
491
|
+
claims: repositoryClaims(finding),
|
|
492
|
+
}));
|
|
493
|
+
checkReportScope(rows, target, projectMap);
|
|
494
|
+
const result = normalizeRecords(rows, ({ finding }, id) => evidence(selectedFinding(finding), id, source, target), ({ finding }) => identity(record(finding, "Inspector finding")).arn, target);
|
|
495
|
+
if (result.excluded.length && result.findings.length) {
|
|
496
|
+
// Only surviving rows can supply shared provider and host evidence on replay.
|
|
497
|
+
const skipped = new Set(result.excluded.map((row) => row.position));
|
|
498
|
+
const retained = rows.filter((row) => !skipped.has(row.position));
|
|
499
|
+
checkReportScope(retained, target, projectMap, (row, error) => {
|
|
500
|
+
skipped.add(row.position);
|
|
501
|
+
result.excluded.push({
|
|
502
|
+
position: row.position,
|
|
503
|
+
source_finding_id: identity(record(row.finding, "Inspector finding"))
|
|
504
|
+
.arn,
|
|
505
|
+
reason: errorMessage(error),
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
result.findings = result.findings.filter((_, i) => !skipped.has(retained[i].position));
|
|
509
|
+
result.excluded.sort((a, b) => a.position - b.position);
|
|
510
|
+
}
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
export async function readInspectorFindings(path, sourceRepositoryUrl, target = "cloud", projectMap) {
|
|
514
|
+
const mapping = projectMap && new Map(projectMap);
|
|
515
|
+
return normalizeInspectorFindings(await readScannerJson(path), sourceRepositoryUrl, target, mapping);
|
|
516
|
+
}
|
|
517
|
+
//# sourceMappingURL=inspector-findings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspector-findings.js","sourceRoot":"","sources":["../src/inspector-findings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK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AAC,CAAC;IAClD,OAAO,0BAA0B,CAC/B,MAAM,eAAe,CAAC,IAAI,CAAC,EAC3B,mBAAmB,EACnB,MAAM,EACN,OAAO,CACR,CAAC;AACJ,CAAC","sourcesContent":["import { posix } from \"node:path\";\nimport { z } from \"zod\";\nimport validSemver from \"semver/functions/valid.js\";\nimport type {\n ExternalFinding,\n ExternalFindings,\n ExternalSourceRepository,\n} from \"./external-findings.js\";\nimport {\n cloudRepositoryUrlKey,\n repositoryUrlKey,\n validateExternalEvidence,\n type ExternalImportTarget,\n} from \"./external-import-contract.js\";\nimport { isGitHubCloudHost } from \"./git-remote.js\";\nimport { CodexSecurityError, errorMessage } from \"./errors.js\";\nimport type { Provider } from \"./external-import-models.js\";\nimport { isRecord } from \"./record.js\";\nimport {\n normalizeRecords,\n readScannerJson,\n record,\n relativePath,\n requiredText,\n text,\n} from \"./scanner-import.js\";\n\ntype Native = Record<string, unknown>;\n\nconst listFindings = z.strictObject({ findings: z.array(z.unknown()) });\nconst format = \"aws-inspector2-list-findings/v1\";\nconst findingArn =\n /^(arn:(aws[a-zA-Z-]*):inspector2:([a-z]{2}(?:-gov)?-[a-z]+-\\d):(\\d{12})):finding\\/[a-f0-9]{32}$/u;\nconst integrationArn =\n /^arn:aws[a-zA-Z-]*:inspector2:[a-z]{2}(?:-gov)?-[a-z]+-\\d:\\d{12}:codesecurity-integration\\/[a-f0-9-]{36}$/u;\nconst projectSuffix =\n /^project-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/u;\nconst absoluteUrl = /^[a-z][a-z\\d+.-]*:\\/\\//iu;\n\nfunction repositoryUrl(value: unknown): string {\n const raw = requiredText(value, \"Inspector --source-repository-url\");\n const url = URL.parse(raw);\n const path = /^https?:\\/\\/[^/?#]+(\\/[^?#]+)$/iu.exec(raw)?.[1];\n if (\n !url ||\n !path ||\n url.username ||\n url.password ||\n /[\\s\\\\?#]|%(?:2f|5c)/iu.test(raw) ||\n path !== url.pathname ||\n !/^\\/[^/]+(?:\\/[^/]+)+\\/?$/u.test(path)\n )\n throw new Error(\n \"Use a complete HTTP(S) Inspector source repository URL with a namespace and repository, without credentials, query or fragment.\",\n );\n return raw;\n}\n\nfunction projectIntegration(projectArn: string): string {\n const separator = projectArn.lastIndexOf(\"/\");\n const parent = projectArn.slice(0, separator);\n if (\n !integrationArn.test(parent) ||\n !projectSuffix.test(projectArn.slice(separator + 1))\n )\n throw new Error(\"Expected a full Inspector repository project ARN.\");\n return parent;\n}\n\n/** @internal Validate an operator-supplied project binding. */\nexport function validateInspectorProjectMapping(\n projectArn: string,\n canonicalUrl: unknown,\n): string {\n projectIntegration(projectArn);\n return repositoryUrl(canonicalUrl);\n}\n\nfunction identity(finding: Native) {\n const arn = requiredText(finding[\"findingArn\"], \"Inspector finding ARN\");\n const match = findingArn.exec(arn);\n if (!match) throw new Error(\"Expected an Inspector2 finding ARN.\");\n if (finding[\"awsAccountId\"] !== match[4])\n throw new Error(\"Inspector finding ARN and AWS account do not match.\");\n return {\n arn,\n issuer: match[1]!,\n partition: match[2]!,\n region: match[3]!,\n account: match[4]!,\n };\n}\n\nfunction repositoryClaim(\n { issuer, partition, region, account }: ReturnType<typeof identity>,\n resource: Native,\n) {\n for (const [field, expected] of Object.entries({\n partition,\n region,\n provider: \"AWS\",\n providerAccountId: account,\n })) {\n if (resource[field] !== undefined && resource[field] !== expected)\n throw new Error(\n \"Inspector repository resource and finding scope do not match.\",\n );\n }\n const { codeRepository } = record(\n resource[\"details\"] ?? {},\n \"Inspector resource details\",\n );\n const repo = record(codeRepository ?? {}, \"Inspector codeRepository\");\n const optional = (field: string) =>\n repo[field] === undefined\n ? undefined\n : requiredText(repo[field], `Inspector codeRepository.${field}`);\n const nativeId = requiredText(\n resource[\"id\"],\n \"Inspector repository resource ID\",\n );\n let integration = optional(\"integrationArn\");\n if (\n integration !== undefined &&\n (!integration.startsWith(issuer + \":\") || !integrationArn.test(integration))\n )\n throw new Error(\n \"Inspector integration ARN does not match the finding scope.\",\n );\n if (nativeId.startsWith(\"arn:\")) {\n const parent = projectIntegration(nativeId);\n if (\n !parent.startsWith(issuer + \":\") ||\n (integration !== undefined && parent !== integration)\n )\n throw new Error(\n \"Inspector repository resource ARN does not match its project or integration.\",\n );\n integration = parent;\n }\n return {\n project: JSON.stringify([issuer, nativeId]),\n integration,\n provider: optional(\"providerType\"),\n nativeId,\n name: optional(\"projectName\"),\n };\n}\n\nfunction checkRepositoryMapping(\n { nativeId, name }: ReturnType<typeof repositoryClaim>,\n source: string,\n provider: string | undefined,\n target: ExternalImportTarget,\n projectMap?: ReadonlyMap<string, string>,\n) {\n const hostname = new URL(source).hostname;\n const knownGitHub = isGitHubCloudHost(hostname);\n const gitlab = provider === \"GITLAB_SELF_MANAGED\";\n const github = provider === \"GITHUB\" || knownGitHub;\n if (\n hostname === \"gitlab.com\" ||\n (gitlab && knownGitHub) ||\n (provider !== undefined && !gitlab && provider !== \"GITHUB\")\n )\n throw new Error(\n \"Inspector repository provider does not match the selected mapping.\",\n );\n if (target === \"cloud\" && !github)\n throw new Error(\n \"Inspector Cloud requires a GitHub repository provider; self-managed GitLab is local only.\",\n );\n const urls = [nativeId, name].filter(\n (url): url is string => !!url && absoluteUrl.test(url),\n );\n const key = github && !projectMap ? cloudRepositoryUrlKey : repositoryUrlKey;\n const path = new URL(\n (github ? cloudRepositoryUrlKey : repositoryUrlKey)(source),\n ).pathname.slice(1);\n const slug = github ? name?.toLowerCase() : name;\n const matchesSlug =\n !slug ||\n absoluteUrl.test(slug) ||\n slug === path ||\n slug === posix.basename(path) ||\n (gitlab && projectMap && path.endsWith(\"/\" + slug));\n if (\n !matchesSlug ||\n urls.some((url) => key(repositoryUrl(url)) !== key(source))\n )\n throw new Error(\n \"Inspector native repository does not match --source-repository-url.\",\n );\n if (projectMap) {\n // repositoryClaim validated this ARN and its issuer before the lookup.\n const trustedUrl = nativeId.startsWith(\"arn:\")\n ? projectMap.get(nativeId)\n : undefined;\n if (trustedUrl === undefined)\n throw new Error(\n \"Inspector project ARN is missing from the trusted mapping.\",\n );\n if (\n repositoryUrlKey(repositoryUrl(trustedUrl)) !== repositoryUrlKey(source)\n )\n throw new Error(\n \"Inspector project ARN mapping does not match the source repository URL.\",\n );\n return true;\n }\n return urls.length > 0;\n}\n\nfunction repositoryClaims(finding: unknown) {\n if (!isRecord(finding) || !Array.isArray(finding[\"resources\"])) return [];\n const claims = [];\n let origin: ReturnType<typeof identity> | undefined;\n for (const resource of finding[\"resources\"]) {\n if (!isRecord(resource) || resource[\"type\"] !== \"CODE_REPOSITORY\") continue;\n origin ??= identity(finding);\n claims.push(repositoryClaim(origin, resource));\n }\n return claims;\n}\n\n/** Claims from the whole export must identify one project, including excluded rows. */\nfunction checkReportScope<\n T extends { claims: ReturnType<typeof repositoryClaims>; source: string },\n>(\n rows: readonly T[],\n target: ExternalImportTarget,\n projectMap?: ReadonlyMap<string, string>,\n exclude: (row: T, error: unknown) => void = (_, error) => {\n throw error;\n },\n): string | undefined {\n const claims = rows.flatMap((row) => row.claims);\n function shared(field: \"project\" | \"integration\" | \"provider\") {\n const values = new Set(claims.map((claim) => claim[field]));\n values.delete(undefined);\n if (values.size > 1)\n throw new Error(\n \"Inspector export identifies more than one repository project or integration.\",\n );\n return values.values().next().value;\n }\n shared(\"project\");\n shared(\"integration\");\n const provider = shared(\"provider\");\n type Claim = ReturnType<typeof repositoryClaim>;\n // A bare project ID can recur across integrations in the same account and Region.\n const sharedProvider = claims.find(\n (claim) => claim.integration && claim.provider,\n )?.provider;\n const providerFor = (claim: Claim) =>\n claim.provider ?? (claim.integration ? sharedProvider : undefined);\n const missingHost = () =>\n new Error(\n \"Inspector needs a matching native repository URL or a trusted project ARN mapping to identify the Git host.\",\n );\n const needHost = [];\n let sharedHost = false;\n for (const row of rows) {\n try {\n // Only a fully verified row can supply evidence to another row.\n const scopedMatches = row.claims.flatMap((claim) => {\n const proven = checkRepositoryMapping(\n claim,\n row.source,\n providerFor(claim),\n target,\n projectMap,\n );\n if (claim.integration) return [proven];\n if (!proven) throw missingHost();\n return [];\n });\n if (scopedMatches.includes(true)) sharedHost = true;\n else if (scopedMatches.length) needHost.push(row);\n } catch (error) {\n exclude(row, error);\n }\n }\n if (!sharedHost) for (const row of needHost) exclude(row, missingHost());\n return claims.every((claim) => providerFor(claim) === provider)\n ? provider\n : undefined;\n}\n\nconst nonempty = z.string().regex(/\\S/u, \"Expected nonempty text.\");\nconst optionalValue = z.unknown().optional();\nconst absent = z.never().optional();\nconst vulnerablePackage = z.object({\n name: nonempty,\n version: nonempty,\n packageManager: optionalValue,\n epoch: optionalValue,\n release: optionalValue,\n fixedInVersion: optionalValue,\n filePath: optionalValue,\n sourceLayerHash: absent,\n sourceLambdaLayerArn: absent,\n});\nconst repositoryFinding = z.object({\n type: z.enum([\"PACKAGE_VULNERABILITY\", \"CODE_VULNERABILITY\"]),\n resources: z\n .array(\n z.object({\n type: z.literal(\"CODE_REPOSITORY\"),\n details: z.strictObject({ codeRepository: optionalValue }).nullish(),\n }),\n )\n .min(1),\n networkReachabilityDetails: absent,\n packageVulnerabilityDetails: z\n .object({\n vulnerabilityId: nonempty,\n source: nonempty,\n sourceUrl: optionalValue,\n relatedVulnerabilities: z.array(nonempty).nullish(),\n vulnerablePackages: z.array(vulnerablePackage).nullish(),\n })\n .optional(),\n codeVulnerabilityDetails: z\n .object({\n detectorName: nonempty,\n detectorId: nonempty,\n cwes: z.array(z.unknown()),\n filePath: z.object({\n fileName: optionalValue,\n filePath: optionalValue,\n startLine: optionalValue,\n }),\n sourceLambdaLayerArn: absent,\n })\n .optional(),\n});\nfunction selectedFinding(value: unknown) {\n const native = record(value, \"Inspector finding\");\n const parsed = repositoryFinding.safeParse(native);\n if (!parsed.success)\n throw new Error(\n `Expected an Inspector vulnerability on CODE_REPOSITORY resources. ${z.prettifyError(parsed.error)}`,\n );\n const {\n type,\n packageVulnerabilityDetails: pkg,\n codeVulnerabilityDetails: code,\n } = parsed.data;\n if (\n (pkg && type !== \"PACKAGE_VULNERABILITY\") ||\n (code && type !== \"CODE_VULNERABILITY\")\n )\n throw new Error(\n \"Inspector finding contains details for a different finding type.\",\n );\n return { native, pkg, code };\n}\n\nfunction isInspectorFinding(value: unknown, occurrenceId?: string): boolean {\n return (\n isRecord(value) &&\n typeof value[\"findingArn\"] === \"string\" &&\n findingArn.test(value[\"findingArn\"]) &&\n (occurrenceId === undefined || value[\"findingArn\"] === occurrenceId) &&\n Array.isArray(value[\"resources\"])\n );\n}\n\nfunction hasInspectorEvidence(\n sourceData: unknown,\n occurrenceId?: string,\n): boolean {\n return (\n isRecord(sourceData) &&\n (sourceData[\"format\"] === format ||\n isInspectorFinding(sourceData[\"finding\"], occurrenceId) ||\n isInspectorFinding(sourceData, occurrenceId))\n );\n}\n\nexport function inspectorReportRepository(\n provider: Provider,\n findings: readonly ExternalFinding[],\n target: ExternalImportTarget,\n projectMap?: ReadonlyMap<string, string>,\n): (ExternalSourceRepository & { findingId: string }) | undefined {\n if (provider !== \"inspector\") {\n if (\n findings.some(({ evidence, source_finding_id }) =>\n hasInspectorEvidence(evidence.source_data, source_finding_id),\n )\n )\n throw new CodexSecurityError(\n \"Retained Inspector evidence requires the inspector provider.\",\n );\n return undefined;\n }\n const retained = [];\n for (const { source_finding_id: id, evidence } of findings) {\n const data = evidence.source_data;\n if (!isRecord(data) || data[\"format\"] !== format) {\n if (projectMap || hasInspectorEvidence(data) || findingArn.test(id))\n throw new Error(\n \"Expected retained Inspector ListFindings evidence for the finding ARN.\",\n );\n continue;\n }\n const source = repositoryUrl(data[\"sourceRepositoryUrl\"]);\n const { native: finding } = selectedFinding(data[\"finding\"]);\n if (finding[\"findingArn\"] !== id)\n throw new Error(\n \"Inspector source_finding_id does not match the retained finding ARN.\",\n );\n retained.push({\n source,\n claims: repositoryClaims(finding),\n id,\n declared: evidence.details?.repository?.url,\n });\n }\n const first = retained[0];\n if (!first) return undefined;\n // A supplied map owns the path casing on custom hosts.\n const github =\n checkReportScope(retained, target, projectMap) === \"GITHUB\" && !projectMap;\n const key =\n github || target === \"cloud\" ? cloudRepositoryUrlKey : repositoryUrlKey;\n const repository = key(first.source);\n for (const { source, declared } of retained) {\n if (key(source) !== repository)\n throw new Error(\n \"Inspector export identifies more than one source repository.\",\n );\n if (declared && key(declared) !== repository)\n throw new Error(\n \"Retained scanner repository does not match the normalized evidence repository.\",\n );\n }\n return {\n findingId: first.id,\n url: first.source,\n ...(github && { platform: \"github\" }),\n };\n}\n\nfunction repoFile(value: unknown): string | null {\n const relative = relativePath(value);\n if (!relative) return null;\n const path = posix.normalize(relative);\n return path === \".\" ||\n path.endsWith(\"/\") ||\n /^(?:[a-z][a-z\\d+.-]*:|~[^/]*(?:\\/|$)|[^/]+@[^/]+:)/iu.test(path)\n ? null\n : path;\n}\n\nfunction timestamp(value: unknown): number {\n const seconds =\n typeof value === \"number\"\n ? value\n : typeof value === \"string\" &&\n /^\\d{4}-\\d\\d-\\d\\dT\\d\\d:\\d\\d:\\d\\d(?:\\.\\d+)?(?:Z|[+-]\\d\\d:\\d\\d)$/u.test(\n value,\n )\n ? Date.parse(value) / 1000\n : NaN;\n if (!Number.isFinite(seconds))\n throw new Error(\"Invalid Inspector timestamp.\");\n return Math.floor(seconds);\n}\n\nconst ecosystems = new Map(\n Object.entries({\n BUNDLER: \"rubygems\",\n GEMSPEC: \"rubygems\",\n CARGO: \"cargo\",\n COMPOSER: \"composer\",\n NPM: \"npm\",\n YARN: \"npm\",\n NODEPKG: \"npm\",\n NUGET: \"nuget\",\n DOTNET_CORE: \"nuget\",\n GOBINARY: \"go\",\n GOMOD: \"go\",\n JAR: \"java\",\n POM: \"maven\",\n PIP: \"pypi\",\n PIPENV: \"pypi\",\n POETRY: \"pypi\",\n PYTHONPKG: \"pypi\",\n }),\n);\n\nconst manifests = new Set([\n \"package.json\",\n \"package-lock.json\",\n \"npm-shrinkwrap.json\",\n \"yarn.lock\",\n \"pnpm-lock.yaml\",\n \"Cargo.toml\",\n \"Cargo.lock\",\n \"composer.json\",\n \"composer.lock\",\n \"Gemfile\",\n \"Gemfile.lock\",\n \"go.mod\",\n \"go.sum\",\n \"pom.xml\",\n \"build.gradle\",\n \"build.gradle.kts\",\n \"gradle.lockfile\",\n \"Pipfile\",\n \"Pipfile.lock\",\n \"poetry.lock\",\n \"pyproject.toml\",\n \"uv.lock\",\n \"packages.config\",\n \"packages.lock.json\",\n]);\n\nfunction manifestPath(path: string | null): string | null {\n if (!path) return null;\n const name = posix.basename(path);\n return manifests.has(name) ||\n /^requirements(?:[-_.].*)?\\.txt$/u.test(name) ||\n /\\.(?:csproj|fsproj|vbproj|gemspec)$/u.test(name)\n ? path\n : null;\n}\n\nfunction concreteVersion(\n value: unknown,\n ecosystem: string | null,\n osPackage: boolean,\n): string | null {\n const version = text(value);\n if (!version) return null;\n // Debian versions use internal tildes for prereleases and backports.\n if (osPackage && version.includes(\"~\"))\n return /^(?:\\d+:)?\\d[a-z\\d.+~]*(?:-[a-z\\d.+~]+)*$/iu.test(version)\n ? version\n : null;\n if (validSemver(version)) return version;\n if (ecosystem === \"npm\" || ecosystem === \"cargo\") return null;\n if (ecosystem === \"java\" || ecosystem === \"maven\") {\n if (\n version === \"LATEST\" ||\n version === \"RELEASE\" ||\n version.startsWith(\"latest.\")\n )\n return null;\n return /^[a-z\\d][\\w.+-]*$/iu.test(version) && !version.endsWith(\"+\")\n ? version\n : null;\n }\n if (!ecosystem && version.endsWith(\"+\")) return null;\n const publicVersion =\n ecosystem === \"pypi\" ? version.split(\"+\", 1)[0]! : version;\n return /\\d/u.test(version) &&\n /^(?:\\d+:)?[a-z\\d][\\w.+!-]*$/iu.test(version) &&\n !/(?:^|\\.)x(?:\\.|$)/iu.test(publicVersion)\n ? version\n : null;\n}\n\nfunction evidence(\n { native: finding, pkg, code }: ReturnType<typeof selectedFinding>,\n id: string,\n source: string,\n target: ExternalImportTarget,\n) {\n const {\n description,\n severity,\n remediation,\n firstObservedAt,\n lastObservedAt,\n updatedAt,\n status,\n } = finding;\n const { recommendation } = record(remediation, \"Inspector remediation\");\n record(recommendation ?? {}, \"Inspector recommendation\");\n requiredText(status, \"Inspector status\");\n timestamp(firstObservedAt);\n timestamp(lastObservedAt);\n const level = requiredText(severity, \"Inspector severity\").toLowerCase();\n const paths = new Set<string>();\n const packages = (pkg?.vulnerablePackages ?? []).map((item) => {\n const path = repoFile(item.filePath);\n if (path) paths.add(path);\n const ecosystem = ecosystems.get(text(item.packageManager) ?? \"\") ?? null;\n const version = (value: unknown) =>\n concreteVersion(value, ecosystem, item.packageManager === \"OS\");\n const fixed = version(item.fixedInVersion);\n const splitVersion =\n item.packageManager === \"OS\" &&\n (item.epoch != null || item.release != null);\n return {\n name: item.name,\n ecosystem,\n installed_version: splitVersion ? null : version(item.version),\n manifest_path: manifestPath(path),\n fixed_versions: fixed ? [fixed] : [],\n };\n });\n const locations: { path: string; line: number | null }[] = [...paths].map(\n (path) => ({ path, line: null }),\n );\n if (code) {\n const { fileName, filePath, startLine } = code.filePath;\n const path = repoFile(filePath);\n if (path && posix.basename(path) === fileName)\n locations.push({\n path,\n line:\n typeof startLine === \"number\" &&\n Number.isSafeInteger(startLine) &&\n startLine > 0\n ? startLine\n : null,\n });\n }\n return validateExternalEvidence(\n {\n title:\n text(finding[\"title\"]) ??\n pkg?.vulnerabilityId ??\n code?.detectorName ??\n id,\n description: requiredText(description, \"Inspector description\"),\n severity: [\"critical\", \"high\", \"medium\", \"low\", \"informational\"].includes(\n level,\n )\n ? level\n : \"unknown\",\n url: text(pkg?.sourceUrl),\n advisory_ids: pkg\n ? [\n ...new Set([\n pkg.vulnerabilityId,\n ...(pkg.relatedVulnerabilities ?? []),\n ]),\n ]\n : [],\n packages,\n locations,\n source_updated_at: updatedAt === undefined ? null : timestamp(updatedAt),\n source_data: {\n format,\n sourceRepositoryUrl: source,\n finding: structuredClone(finding),\n },\n },\n target,\n );\n}\n\nexport function normalizeInspectorFindings(\n input: unknown,\n sourceRepositoryUrl: string,\n target: ExternalImportTarget = \"cloud\",\n projectMap?: ReadonlyMap<string, string>,\n): ExternalFindings {\n const source = repositoryUrl(sourceRepositoryUrl);\n if (\n isRecord(input) &&\n (Object.hasOwn(input, \"NextToken\") || Object.hasOwn(input, \"nextToken\"))\n )\n throw new Error(\n \"Inspector export has a continuation key; supply the complete paginated CLI JSON output.\",\n );\n const report = listFindings.safeParse(input);\n if (!report.success)\n throw new Error(\n \"Expected only a complete native Inspector ListFindings response with a findings array.\",\n );\n const rows = report.data.findings.map((finding, i) => ({\n finding,\n source,\n position: i + 1,\n claims: repositoryClaims(finding),\n }));\n checkReportScope(rows, target, projectMap);\n const result = normalizeRecords(\n rows,\n ({ finding }, id) => evidence(selectedFinding(finding), id, source, target),\n ({ finding }) => identity(record(finding, \"Inspector finding\")).arn,\n target,\n );\n if (result.excluded.length && result.findings.length) {\n // Only surviving rows can supply shared provider and host evidence on replay.\n const skipped = new Set(result.excluded.map((row) => row.position));\n const retained = rows.filter((row) => !skipped.has(row.position));\n checkReportScope(retained, target, projectMap, (row, error) => {\n skipped.add(row.position);\n result.excluded.push({\n position: row.position,\n source_finding_id: identity(record(row.finding, \"Inspector finding\"))\n .arn,\n reason: errorMessage(error),\n });\n });\n result.findings = result.findings.filter(\n (_, i) => !skipped.has(retained[i]!.position),\n );\n result.excluded.sort((a, b) => a.position - b.position);\n }\n return result;\n}\n\nexport async function readInspectorFindings(\n path: string,\n sourceRepositoryUrl: string,\n target: ExternalImportTarget = \"cloud\",\n projectMap?: ReadonlyMap<string, string>,\n): Promise<ExternalFindings> {\n const mapping = projectMap && new Map(projectMap);\n return normalizeInspectorFindings(\n await readScannerJson(path),\n sourceRepositoryUrl,\n target,\n mapping,\n );\n}\n"]}
|
package/dist/patch-tui.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface PatchTuiProps {
|
|
|
18
18
|
onComplete(selection: PatchSelection | null): void;
|
|
19
19
|
color?: boolean;
|
|
20
20
|
}
|
|
21
|
-
export declare function PatchTui({ repository, findings, onComplete, color, }: PatchTuiProps): React.JSX.Element;
|
|
21
|
+
export declare function PatchTui({ repository, findings: inputFindings, onComplete, color, }: PatchTuiProps): React.JSX.Element;
|
|
22
22
|
export declare function runPatchTui(repository: string, findings: readonly Finding[], { stdin, stdout, color, }?: {
|
|
23
23
|
stdin?: NodeJS.ReadStream;
|
|
24
24
|
stdout?: NodeJS.WriteStream;
|
package/dist/patch-tui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-tui.d.ts","sourceRoot":"","sources":["../src/patch-tui.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAuB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"patch-tui.d.ts","sourceRoot":"","sources":["../src/patch-tui.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAuB,MAAM,aAAa,CAAC;AAGhE,QAAA,MAAM,eAAe;aACnB,QAAQ,EAAE,WAAW;aACrB,IAAI,EAAE,KAAK;aACX,MAAM,EAAE,QAAQ;aAChB,GAAG,EAAE,YAAY;CACT,CAAC;AAEX,KAAK,aAAa,GAAG,MAAM,OAAO,eAAe,CAAC;AAgClD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,aAAa,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,UAAU,aAAa;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,OAAO,EAAE,CAAC;IAC7B,UAAU,CAAC,SAAS,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI,CAAC;IACnD,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAgTD,wBAAgB,QAAQ,CAAC,EACvB,UAAU,EACV,QAAQ,EAAE,aAAa,EACvB,UAAU,EACV,KAA6C,GAC9C,EAAE,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAqUnC;AAED,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,EACE,KAAqB,EACrB,MAAuB,EACvB,KAAK,GACN,GAAE;IACD,KAAK,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACZ,GACL,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAyBhC"}
|
package/dist/patch-tui.js
CHANGED
|
@@ -4,6 +4,7 @@ import { basename, isAbsolute, relative, resolve, sep } from "node:path";
|
|
|
4
4
|
import { stripVTControlCharacters } from "node:util";
|
|
5
5
|
import { Box, Text, render, useApp, useInput, useStdout } from "ink";
|
|
6
6
|
import { useMemo, useRef, useState } from "react";
|
|
7
|
+
import { SCAN_SEVERITIES } from "./scan-settings.js";
|
|
7
8
|
const SEVERITY_COLORS = {
|
|
8
9
|
critical: "redBright",
|
|
9
10
|
high: "red",
|
|
@@ -227,9 +228,11 @@ function FindingDetailLine({ line, section, title, severity, color, }) {
|
|
|
227
228
|
}
|
|
228
229
|
return _jsx(Text, { wrap: "truncate-end", children: line || " " });
|
|
229
230
|
}
|
|
230
|
-
export function PatchTui({ repository, findings, onComplete, color = process.env["NO_COLOR"] === undefined, }) {
|
|
231
|
+
export function PatchTui({ repository, findings: inputFindings, onComplete, color = process.env["NO_COLOR"] === undefined, }) {
|
|
231
232
|
const { exit } = useApp();
|
|
232
233
|
const { stdout } = useStdout();
|
|
234
|
+
const findings = useMemo(() => [...inputFindings].sort((left, right) => SCAN_SEVERITIES.indexOf(left.severity.level) -
|
|
235
|
+
SCAN_SEVERITIES.indexOf(right.severity.level)), [inputFindings]);
|
|
233
236
|
const [pane, setPane] = useState("findings");
|
|
234
237
|
const [focused, setFocused] = useState(0);
|
|
235
238
|
const focusedFinding = useRef(focused);
|