@craswitch/mcp-server 0.0.0-stage → 2.0.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 +99 -2
- package/dist/cli.js +8 -0
- package/dist/core/badge.js +156 -0
- package/dist/core/crypto-utils.js +199 -0
- package/dist/core/enisa.js +909 -0
- package/dist/core/evidence.js +350 -0
- package/dist/core/feeds.js +1175 -0
- package/dist/core/guardrails.js +537 -0
- package/dist/core/index.js +16 -0
- package/dist/core/lockfiles.js +1107 -0
- package/dist/core/sbom.js +191 -0
- package/dist/core/types.js +918 -0
- package/dist/core/vex.js +722 -0
- package/dist/core/x402.js +467 -0
- package/dist/crypto.js +214 -0
- package/dist/http-client.js +336 -0
- package/dist/index.js +17 -0
- package/dist/kev-baseline.js +186 -0
- package/dist/server.js +1075 -0
- package/package.json +39 -4
- package/server.json +63 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CycloneDX 1.6 JSON SBOM generator (zero dependencies).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { SCAN_LIMITS, SCHEMA_VERSIONS } from './types.js';
|
|
6
|
+
|
|
7
|
+
import { deduplicateComponents, parseLockfile, parseSpdxSbom } from './lockfiles.js';
|
|
8
|
+
import { utf8ToBytes } from './crypto-utils.js';
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
function mapScopeToCycloneDx(scope ) {
|
|
18
|
+
switch (scope) {
|
|
19
|
+
case 'prod':
|
|
20
|
+
case 'unknown':
|
|
21
|
+
return 'required';
|
|
22
|
+
case 'optional':
|
|
23
|
+
return 'optional';
|
|
24
|
+
case 'dev':
|
|
25
|
+
return 'excluded';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function buildRootRepoPurl(repoFullName , releaseTag ) {
|
|
30
|
+
const parts = repoFullName.split('/').filter((p) => p.length > 0);
|
|
31
|
+
if (parts.length < 2) return undefined;
|
|
32
|
+
const owner = parts[0] ?? '';
|
|
33
|
+
const repo = parts.slice(1).join('/');
|
|
34
|
+
return `pkg:github/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}@${encodeURIComponent(releaseTag)}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generates a valid CycloneDX 1.6 JSON SBOM from normalized PurlComponents.
|
|
39
|
+
*/
|
|
40
|
+
export function generateCycloneDxSbom(
|
|
41
|
+
repoFullName ,
|
|
42
|
+
releaseTag ,
|
|
43
|
+
components ,
|
|
44
|
+
options ,
|
|
45
|
+
) {
|
|
46
|
+
const normalized = deduplicateComponents(components);
|
|
47
|
+
const timestamp = options?.timestamp ?? new Date().toISOString();
|
|
48
|
+
const serialNumber = options?.serialNumber ?? `urn:uuid:${crypto.randomUUID()}`;
|
|
49
|
+
const version = options?.version ?? 1;
|
|
50
|
+
const toolVersion = options?.toolVersion ?? '1.0.0';
|
|
51
|
+
const rootPurl = buildRootRepoPurl(repoFullName, releaseTag);
|
|
52
|
+
|
|
53
|
+
const cdxComponents = normalized.map((comp) => {
|
|
54
|
+
const out = {
|
|
55
|
+
type: 'library',
|
|
56
|
+
name: comp.name,
|
|
57
|
+
version: comp.version,
|
|
58
|
+
purl: comp.purl,
|
|
59
|
+
scope: mapScopeToCycloneDx(comp.scope),
|
|
60
|
+
properties: [
|
|
61
|
+
{ name: 'cra-switch:ecosystem', value: comp.ecosystem },
|
|
62
|
+
{ name: 'cra-switch:scope', value: comp.scope },
|
|
63
|
+
{ name: 'cra-switch:sourceFile', value: comp.sourceFile },
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
if (comp.namespace) {
|
|
67
|
+
out.group = comp.namespace;
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return {
|
|
73
|
+
bomFormat: 'CycloneDX',
|
|
74
|
+
specVersion: SCHEMA_VERSIONS.cyclonedx,
|
|
75
|
+
serialNumber,
|
|
76
|
+
version,
|
|
77
|
+
metadata: {
|
|
78
|
+
timestamp,
|
|
79
|
+
tools: {
|
|
80
|
+
components: [
|
|
81
|
+
{
|
|
82
|
+
type: 'application',
|
|
83
|
+
name: 'cra-switch',
|
|
84
|
+
version: toolVersion,
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
component: {
|
|
89
|
+
type: 'application',
|
|
90
|
+
name: repoFullName,
|
|
91
|
+
version: releaseTag,
|
|
92
|
+
...(rootPurl ? { purl: rootPurl } : {}),
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
components: cdxComponents,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Lightweight structural validator for CycloneDX 1.6 SBOMs.
|
|
101
|
+
*/
|
|
102
|
+
export function validateCycloneDxSbom(sbom ) {
|
|
103
|
+
const errors = [];
|
|
104
|
+
if (!sbom || typeof sbom !== 'object') {
|
|
105
|
+
return { valid: false, errors: ['SBOM must be a JSON object'] };
|
|
106
|
+
}
|
|
107
|
+
const doc = sbom ;
|
|
108
|
+
if (doc.bomFormat !== 'CycloneDX') errors.push('bomFormat must be "CycloneDX"');
|
|
109
|
+
if (doc.specVersion !== '1.6') errors.push('specVersion must be "1.6"');
|
|
110
|
+
if (typeof doc.serialNumber !== 'string' || !doc.serialNumber.startsWith('urn:uuid:')) {
|
|
111
|
+
errors.push('serialNumber must be a valid urn:uuid: string');
|
|
112
|
+
}
|
|
113
|
+
if (typeof doc.version !== 'number' || doc.version < 1) {
|
|
114
|
+
errors.push('version must be a positive integer');
|
|
115
|
+
}
|
|
116
|
+
if (!doc.metadata || typeof doc.metadata !== 'object') {
|
|
117
|
+
errors.push('metadata object is required');
|
|
118
|
+
}
|
|
119
|
+
if (!Array.isArray(doc.components)) {
|
|
120
|
+
errors.push('components must be an array');
|
|
121
|
+
}
|
|
122
|
+
return { valid: errors.length === 0, errors };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Auto-detects and parses a CycloneDX 1.6 or SPDX 2.3 JSON SBOM payload,
|
|
132
|
+
* enforcing `SCAN_LIMITS.maxLockfileBytes`.
|
|
133
|
+
*/
|
|
134
|
+
export function parseSbomPayload(
|
|
135
|
+
rawJson ,
|
|
136
|
+
contentType ,
|
|
137
|
+
sourceFile ,
|
|
138
|
+
) {
|
|
139
|
+
const byteLength = utf8ToBytes(rawJson).byteLength;
|
|
140
|
+
if (byteLength > SCAN_LIMITS.maxLockfileBytes) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`SBOM payload exceeds SCAN_LIMITS.maxLockfileBytes (${byteLength} > ${SCAN_LIMITS.maxLockfileBytes})`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
let parsed ;
|
|
147
|
+
try {
|
|
148
|
+
parsed = JSON.parse(rawJson);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`Invalid SBOM JSON payload: ${err instanceof Error ? err.message : String(err)}`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
156
|
+
throw new Error('SBOM payload must be a JSON object');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const obj = parsed ;
|
|
160
|
+
const ct = (contentType ?? '').toLowerCase();
|
|
161
|
+
|
|
162
|
+
const isCycloneDx =
|
|
163
|
+
obj.bomFormat === 'CycloneDX' ||
|
|
164
|
+
(ct.includes('cyclonedx') && Array.isArray(obj.components));
|
|
165
|
+
const isSpdx =
|
|
166
|
+
(typeof obj.spdxVersion === 'string' && obj.spdxVersion.toUpperCase().startsWith('SPDX-')) ||
|
|
167
|
+
obj.SPDXID === 'SPDXRef-DOCUMENT' ||
|
|
168
|
+
(ct.includes('spdx') && Array.isArray(obj.packages));
|
|
169
|
+
|
|
170
|
+
if (isCycloneDx) {
|
|
171
|
+
return {
|
|
172
|
+
format: 'cyclonedx',
|
|
173
|
+
components: parseLockfile({
|
|
174
|
+
path: sourceFile ?? 'cyclonedx.json',
|
|
175
|
+
kind: 'cyclonedx.json',
|
|
176
|
+
content: rawJson,
|
|
177
|
+
}),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (isSpdx) {
|
|
182
|
+
return {
|
|
183
|
+
format: 'spdx',
|
|
184
|
+
components: parseSpdxSbom(rawJson, sourceFile ?? 'spdx.json'),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
throw new Error(
|
|
189
|
+
'Unrecognized SBOM payload: expected CycloneDX JSON (bomFormat: "CycloneDX") or SPDX JSON (spdxVersion: "SPDX-2.x")',
|
|
190
|
+
);
|
|
191
|
+
}
|