jso-protector 0.2.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/CHANGELOG.md +960 -0
- package/LICENSE +90 -0
- package/MIGRATION.md +207 -0
- package/README.md +1477 -0
- package/RELEASE.md +82 -0
- package/SECURITY.md +71 -0
- package/ai-cli.js +392 -0
- package/ai.js +176 -0
- package/bin/jso-protector.js +12066 -0
- package/browserify.d.ts +10 -0
- package/browserify.js +88 -0
- package/bun.d.ts +10 -0
- package/bun.js +41 -0
- package/ci/Jenkinsfile +82 -0
- package/ci/argo-workflows.yaml +121 -0
- package/ci/azure-pipelines.yml +56 -0
- package/ci/bitbucket-pipelines.yml +43 -0
- package/ci/buildkite.yml +50 -0
- package/ci/circleci.yml +60 -0
- package/ci/drone.yml +67 -0
- package/ci/github-actions.yml +51 -0
- package/ci/gitlab-ci.yml +39 -0
- package/ci/gocd.yaml +79 -0
- package/ci/teamcity.kts +79 -0
- package/ci/tekton.yaml +106 -0
- package/ci/verify-package.js +748 -0
- package/ci/verify-publish-metadata.js +147 -0
- package/ci/verify-templates.js +195 -0
- package/ci/woodpecker.yml +53 -0
- package/compliance/cli.js +204 -0
- package/compliance/evidence-forwarder.js +209 -0
- package/compliance/pci-dss-v4/controls.json +75 -0
- package/compliance/pci-dss-v4/index.js +2613 -0
- package/config/named-sets.js +185 -0
- package/esbuild.d.ts +16 -0
- package/esbuild.js +190 -0
- package/examples/README.md +78 -0
- package/examples/browserify/build.js +20 -0
- package/examples/bun/package.json +13 -0
- package/examples/bun/scripts/protect-release.js +28 -0
- package/examples/cli-basic/jso.config.cjs +23 -0
- package/examples/cli-basic/jso.config.json +15 -0
- package/examples/cli-basic/package.json +14 -0
- package/examples/cli-basic/scripts/build.js +10 -0
- package/examples/curl/README.md +55 -0
- package/examples/curl/protect.sh +106 -0
- package/examples/esbuild/build.js +19 -0
- package/examples/grunt/Gruntfile.js +29 -0
- package/examples/gulp/gulpfile.js +19 -0
- package/examples/helm/Chart.yaml +27 -0
- package/examples/helm/README.md +69 -0
- package/examples/helm/templates/_helpers.tpl +23 -0
- package/examples/helm/templates/_podtemplate.tpl +64 -0
- package/examples/helm/templates/job.yaml +39 -0
- package/examples/helm/templates/secret.yaml +17 -0
- package/examples/helm/values.yaml +54 -0
- package/examples/kubernetes/job.yaml +123 -0
- package/examples/metro.config.js +11 -0
- package/examples/nextjs/next.config.js +11 -0
- package/examples/node-api/protect-release.js +28 -0
- package/examples/node-api/release-summary.js +59 -0
- package/examples/parcel/package.json +13 -0
- package/examples/parcel/scripts/protect-release.js +28 -0
- package/examples/payment-page-script-inventory.json +62 -0
- package/examples/payment-page-security-headers.json +46 -0
- package/examples/pre-commit/.pre-commit-config.yaml +33 -0
- package/examples/pre-commit/README.md +45 -0
- package/examples/react-native/README.md +208 -0
- package/examples/react-native/metro.config.js +11 -0
- package/examples/rollup/rollup.config.js +20 -0
- package/examples/rspack/rspack.config.js +28 -0
- package/examples/turbopack/package.json +13 -0
- package/examples/turbopack/scripts/protect-release.js +28 -0
- package/examples/vite/vite.config.js +18 -0
- package/examples/webpack/webpack.config.js +21 -0
- package/examples/webpack-loader/webpack.config.js +22 -0
- package/governance/index.d.ts +18 -0
- package/governance/index.js +309 -0
- package/grunt.d.ts +4 -0
- package/grunt.js +111 -0
- package/gulp.d.ts +10 -0
- package/gulp.js +106 -0
- package/index.d.ts +879 -0
- package/index.js +607 -0
- package/jso.config.example.json +29 -0
- package/jso.config.schema.json +548 -0
- package/metro.d.ts +43 -0
- package/metro.js +117 -0
- package/next.d.ts +24 -0
- package/next.js +64 -0
- package/package.json +241 -0
- package/parcel.d.ts +10 -0
- package/parcel.js +40 -0
- package/react-native.d.ts +2 -0
- package/react-native.js +3 -0
- package/release-signer.js +245 -0
- package/rollup.d.ts +13 -0
- package/rollup.js +71 -0
- package/rspack-loader.d.ts +13 -0
- package/rspack-loader.js +11 -0
- package/rspack.d.ts +11 -0
- package/rspack.js +9 -0
- package/runtime/ai-script-governance.js +379 -0
- package/runtime/countermeasures.js +0 -0
- package/runtime/data-exfiltration-guard.d.ts +7 -0
- package/runtime/data-exfiltration-guard.js +161 -0
- package/runtime/environment-integrity.js +389 -0
- package/runtime/managed-integrity.d.ts +4 -0
- package/runtime/managed-integrity.js +108 -0
- package/runtime/third-party-inventory.js +437 -0
- package/turbopack.d.ts +10 -0
- package/turbopack.js +41 -0
- package/vite.d.ts +16 -0
- package/vite.js +78 -0
- package/watermark.js +126 -0
- package/webpack-loader.d.ts +15 -0
- package/webpack-loader.js +97 -0
- package/webpack.d.ts +13 -0
- package/webpack.js +143 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Compliance evidence forwarder — pushes a generated compliance report
|
|
4
|
+
// (e.g. the PCI DSS v4 reporter's JSON output) to a GRC platform as an
|
|
5
|
+
// evidence artifact, so the per-build report that already exists also
|
|
6
|
+
// lands in Drata / Vanta / an in-house GRC system without a manual
|
|
7
|
+
// upload step.
|
|
8
|
+
//
|
|
9
|
+
// Design stance (read before extending)
|
|
10
|
+
// --------------------------------------
|
|
11
|
+
// GRC platforms are multi-tenant: the evidence-upload endpoint and the
|
|
12
|
+
// API token are per-customer values the operator supplies. This module
|
|
13
|
+
// therefore does NOT hardcode a vendor API version or base URL it can't
|
|
14
|
+
// keep current. Instead a `profile` shapes the outbound ENVELOPE and
|
|
15
|
+
// HEADERS, and the operator passes the tenant `endpoint` + `token`.
|
|
16
|
+
// That keeps the forwarder honest (no pretending to track an external
|
|
17
|
+
// API we don't control) and stable (a vendor field rename is a config
|
|
18
|
+
// override, not a code change).
|
|
19
|
+
//
|
|
20
|
+
// Three profiles:
|
|
21
|
+
// "generic" — POST the normalized artifact as-is, optionally HMAC-
|
|
22
|
+
// signed exactly like the jso-beacon-slack webhook adapter
|
|
23
|
+
// (X-JSO-Signature: sha256=<hex> over `<ts>.<body>`).
|
|
24
|
+
// "drata" — wrap the artifact in a { name, controls[], evidence{} }
|
|
25
|
+
// shape, Authorization: Bearer <token>.
|
|
26
|
+
// "vanta" — wrap in a { resourceId, testIds[], document{} } shape,
|
|
27
|
+
// Authorization: Bearer <token>.
|
|
28
|
+
// Field names per profile are overridable via `fieldMap` so an operator
|
|
29
|
+
// can match their tenant's exact contract.
|
|
30
|
+
//
|
|
31
|
+
// Contract (mirrors the SIEM adapters): the returned function never
|
|
32
|
+
// throws — transport/validation failures resolve to
|
|
33
|
+
// { ok:false, status:0, error } so a flaky GRC endpoint can't abort a
|
|
34
|
+
// build's reporting step.
|
|
35
|
+
|
|
36
|
+
const https = require("node:https");
|
|
37
|
+
const http = require("node:http");
|
|
38
|
+
const { URL } = require("node:url");
|
|
39
|
+
const crypto = require("node:crypto");
|
|
40
|
+
|
|
41
|
+
const SIGNATURE_HEADER = "X-JSO-Signature";
|
|
42
|
+
const TIMESTAMP_HEADER = "X-JSO-Timestamp";
|
|
43
|
+
const USER_AGENT = "jso-protector/evidence-forwarder";
|
|
44
|
+
const PROFILES = ["generic", "drata", "vanta"];
|
|
45
|
+
|
|
46
|
+
// Normalize a compliance report (the PCI reporter's `json` object, or
|
|
47
|
+
// any report carrying {standard, version, controls[], summary}) into a
|
|
48
|
+
// vendor-neutral evidence artifact. Deterministic + side-effect free so
|
|
49
|
+
// it is trivially testable and the sha256 below is reproducible.
|
|
50
|
+
function buildArtifact(report, opts) {
|
|
51
|
+
opts = opts || {};
|
|
52
|
+
if (!report || typeof report !== "object") {
|
|
53
|
+
throw new Error("evidence-forwarder: report object is required");
|
|
54
|
+
}
|
|
55
|
+
const controls = Array.isArray(report.controls) ? report.controls.map(function (c) {
|
|
56
|
+
return {
|
|
57
|
+
id: c.id,
|
|
58
|
+
title: c.title || null,
|
|
59
|
+
status: c.status || null,
|
|
60
|
+
subRequirements: Array.isArray(c.subRequirements)
|
|
61
|
+
? c.subRequirements.map(function (s) { return { id: s.id, status: s.status, detail: s.detail || null }; })
|
|
62
|
+
: [],
|
|
63
|
+
};
|
|
64
|
+
}) : [];
|
|
65
|
+
|
|
66
|
+
const artifact = {
|
|
67
|
+
source: "jso-protector",
|
|
68
|
+
standard: report.standard || null,
|
|
69
|
+
version: report.version || null,
|
|
70
|
+
organizationName: report.organizationName || opts.organizationName || null,
|
|
71
|
+
buildId: report.buildId || null,
|
|
72
|
+
buildLabel: report.buildLabel || null,
|
|
73
|
+
generatedAt: report.generatedAt || opts.now || null,
|
|
74
|
+
summary: report.summary || null,
|
|
75
|
+
controls: controls,
|
|
76
|
+
};
|
|
77
|
+
// Stable content hash over the canonical artifact (sorted keys), so
|
|
78
|
+
// the GRC side can dedupe re-uploads of the same evidence.
|
|
79
|
+
const canonical = canonicalize(artifact);
|
|
80
|
+
artifact.artifactSha256 = crypto.createHash("sha256").update(canonical, "utf8").digest("hex");
|
|
81
|
+
return artifact;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Minimal canonical JSON (sorted keys, no whitespace) — same idea as
|
|
85
|
+
// release-signer's canonicalize, kept local to avoid a cross-module dep.
|
|
86
|
+
function canonicalize(value) {
|
|
87
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
88
|
+
if (Array.isArray(value)) return "[" + value.map(canonicalize).join(",") + "]";
|
|
89
|
+
const keys = Object.keys(value).sort();
|
|
90
|
+
return "{" + keys.map(function (k) { return JSON.stringify(k) + ":" + canonicalize(value[k]); }).join(",") + "}";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Shape the outbound body + headers for a profile. Returns { body, headers }.
|
|
94
|
+
function shapeRequest(profile, artifact, config) {
|
|
95
|
+
const fieldMap = config.fieldMap || {};
|
|
96
|
+
let body, headers = { "Content-Type": "application/json", "User-Agent": USER_AGENT };
|
|
97
|
+
|
|
98
|
+
if (profile === "drata") {
|
|
99
|
+
body = {
|
|
100
|
+
[fieldMap.name || "name"]: (artifact.standard || "Compliance") + " evidence — build " + (artifact.buildLabel || artifact.buildId || "unlabeled"),
|
|
101
|
+
[fieldMap.controls || "controls"]: artifact.controls.map(function (c) { return c.id; }),
|
|
102
|
+
[fieldMap.evidence || "evidence"]: artifact,
|
|
103
|
+
};
|
|
104
|
+
if (config.token) headers["Authorization"] = "Bearer " + config.token;
|
|
105
|
+
} else if (profile === "vanta") {
|
|
106
|
+
body = {
|
|
107
|
+
[fieldMap.resourceId || "resourceId"]: artifact.buildId || artifact.artifactSha256,
|
|
108
|
+
[fieldMap.testIds || "testIds"]: artifact.controls.map(function (c) { return c.id; }),
|
|
109
|
+
[fieldMap.document || "document"]: artifact,
|
|
110
|
+
};
|
|
111
|
+
if (config.token) headers["Authorization"] = "Bearer " + config.token;
|
|
112
|
+
} else {
|
|
113
|
+
// generic — artifact as-is, optional bearer, optional HMAC.
|
|
114
|
+
body = artifact;
|
|
115
|
+
if (config.token) headers["Authorization"] = "Bearer " + config.token;
|
|
116
|
+
}
|
|
117
|
+
return { body: body, headers: headers };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function signGeneric(secret, timestamp, rawBody) {
|
|
121
|
+
const signingString = String(timestamp) + "." + String(rawBody);
|
|
122
|
+
return "sha256=" + crypto.createHmac("sha256", secret).update(signingString).digest("hex");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Default transport: POST rawBody to endpoint with headers. Resolves
|
|
126
|
+
// { ok, status, body } / { ok:false, status:0, error }. Never rejects.
|
|
127
|
+
function defaultTransport(endpoint, rawBody, headers) {
|
|
128
|
+
return new Promise(function (resolve) {
|
|
129
|
+
let url;
|
|
130
|
+
try { url = new URL(endpoint); }
|
|
131
|
+
catch (e) { resolve({ ok: false, status: 0, error: "invalid endpoint URL: " + (e.message || String(e)) }); return; }
|
|
132
|
+
const lib = url.protocol === "http:" ? http : https;
|
|
133
|
+
const req = lib.request(url, {
|
|
134
|
+
method: "POST",
|
|
135
|
+
headers: Object.assign({ "Content-Length": Buffer.byteLength(rawBody) }, headers),
|
|
136
|
+
}, function (res) {
|
|
137
|
+
let chunks = "";
|
|
138
|
+
res.on("data", function (d) { chunks += d; });
|
|
139
|
+
res.on("end", function () {
|
|
140
|
+
const status = res.statusCode || 0;
|
|
141
|
+
resolve({ ok: status >= 200 && status < 300, status: status, body: chunks });
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
req.on("error", function (e) { resolve({ ok: false, status: 0, error: e.message || String(e) }); });
|
|
145
|
+
req.write(rawBody);
|
|
146
|
+
req.end();
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function createEvidenceForwarder(config) {
|
|
151
|
+
config = config || {};
|
|
152
|
+
const profile = PROFILES.indexOf(config.profile) >= 0 ? config.profile : "generic";
|
|
153
|
+
const transport = typeof config.transport === "function" ? config.transport : defaultTransport;
|
|
154
|
+
const nowFn = config.now || function () { return new Date().toISOString(); };
|
|
155
|
+
|
|
156
|
+
return async function forward(report) {
|
|
157
|
+
if (!config.endpoint) {
|
|
158
|
+
return { ok: false, status: 0, error: "evidence-forwarder: endpoint is required" };
|
|
159
|
+
}
|
|
160
|
+
let artifact, shaped, rawBody;
|
|
161
|
+
try {
|
|
162
|
+
artifact = buildArtifact(report, { organizationName: config.organizationName, now: nowFn() });
|
|
163
|
+
shaped = shapeRequest(profile, artifact, config);
|
|
164
|
+
rawBody = JSON.stringify(shaped.body);
|
|
165
|
+
} catch (e) {
|
|
166
|
+
return { ok: false, status: 0, error: e.message || String(e) };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const headers = Object.assign({}, shaped.headers);
|
|
170
|
+
if (profile === "generic" && config.secret) {
|
|
171
|
+
const ts = String(safeNowMs(nowFn));
|
|
172
|
+
headers[TIMESTAMP_HEADER] = ts;
|
|
173
|
+
headers[SIGNATURE_HEADER] = signGeneric(config.secret, ts, rawBody);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let res;
|
|
177
|
+
try { res = await transport(config.endpoint, rawBody, headers); }
|
|
178
|
+
catch (e) { return { ok: false, status: 0, error: e.message || String(e) }; }
|
|
179
|
+
if (!res || typeof res !== "object") return { ok: false, status: 0, error: "transport returned no result" };
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
ok: !!res.ok,
|
|
183
|
+
status: typeof res.status === "number" ? res.status : 0,
|
|
184
|
+
error: res.error || null,
|
|
185
|
+
profile: profile,
|
|
186
|
+
artifactSha256: artifact.artifactSha256,
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Date.now() is unavailable in some sandboxes; fall back to parsing the
|
|
192
|
+
// ISO string from nowFn so the HMAC timestamp is still monotone-ish.
|
|
193
|
+
function safeNowMs(nowFn) {
|
|
194
|
+
try { return Date.now(); }
|
|
195
|
+
catch (e) {
|
|
196
|
+
const t = Date.parse(nowFn());
|
|
197
|
+
return Number.isFinite(t) ? t : 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
module.exports = {
|
|
202
|
+
PROFILES: PROFILES.slice(),
|
|
203
|
+
createEvidenceForwarder: createEvidenceForwarder,
|
|
204
|
+
buildArtifact: buildArtifact,
|
|
205
|
+
// exposed for tests:
|
|
206
|
+
_canonicalize: canonicalize,
|
|
207
|
+
_shapeRequest: shapeRequest,
|
|
208
|
+
_signGeneric: signGeneric,
|
|
209
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_meta": {
|
|
3
|
+
"standard": "PCI DSS",
|
|
4
|
+
"version": "4.0.1",
|
|
5
|
+
"publisher": "PCI Security Standards Council",
|
|
6
|
+
"publishedDate": "2024-06",
|
|
7
|
+
"compliance_deadline": "2025-03-31",
|
|
8
|
+
"scope_note": "Only the controls JSO directly contributes evidence to. Customers are responsible for the broader QSA-led assessment.",
|
|
9
|
+
"spec_url": "https://www.pcisecuritystandards.org/document_library/?category=pcidss"
|
|
10
|
+
},
|
|
11
|
+
"controls": [
|
|
12
|
+
{
|
|
13
|
+
"id": "6.4.3",
|
|
14
|
+
"title": "Payment page scripts that are loaded and executed in the consumer's browser are managed.",
|
|
15
|
+
"subRequirements": [
|
|
16
|
+
{
|
|
17
|
+
"id": "6.4.3.a",
|
|
18
|
+
"title": "A method is implemented to confirm that each script is authorized.",
|
|
19
|
+
"jso_evidence_primitives": ["watermark", "payment_page_script_inventory"],
|
|
20
|
+
"description": "JSO HMAC-SHA256 watermarks (--watermark <tag> --watermark-key <key>) inject a signed header into every protected file. Verification re-derives the HMAC in constant time. A file with a valid signature under your secret key is, by definition, an authorized script."
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"id": "6.4.3.b",
|
|
24
|
+
"title": "A method is implemented to assure the integrity of each script.",
|
|
25
|
+
"jso_evidence_primitives": ["ed25519_release_attestation", "per_file_sha256"],
|
|
26
|
+
"description": "JSO Ed25519-signed release attestation (--sign-release <priv.pem>) commits to per-file sha256 in a canonical-JSON-signed envelope. Stage-2 verification re-hashes the on-disk files. Any post-signing byte change breaks the signature."
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "6.4.3.c",
|
|
30
|
+
"title": "An inventory of all scripts is maintained with written business or technical justification.",
|
|
31
|
+
"jso_evidence_primitives": ["manifest_files_array", "payment_page_script_inventory"],
|
|
32
|
+
"description": "The manifest.json's files[] array is the technical inventory for protected first-party files. Add --script-inventory with a payment-page script CSV or JSON export when reviewers need authorization and written business justification for every script loaded on the page."
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"id": "11.6.1",
|
|
38
|
+
"title": "A change- and tamper-detection mechanism is deployed for payment pages.",
|
|
39
|
+
"subRequirements": [
|
|
40
|
+
{
|
|
41
|
+
"id": "11.6.1.a",
|
|
42
|
+
"title": "Detects unauthorized modification (including IoCs, changes, additions, and deletions) of HTTP headers and contents of payment pages as received by the consumer browser.",
|
|
43
|
+
"jso_evidence_primitives": ["runtime_defense_integrity_heartbeat", "self_defending", "watermark_in_browser", "dashboard_runtime_incident_export"],
|
|
44
|
+
"description": "JSO Runtime Defense modules ship an integrity heartbeat, devtools/debug protection, headless detection, and tamper-aware self-defending IIFE. The watermark also remains in the protected script, so an in-browser verifier can confirm the served bytes match the signed build."
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "11.6.1.b",
|
|
48
|
+
"title": "Performs the function at least once every seven days OR per the targeted risk analysis cadence.",
|
|
49
|
+
"jso_evidence_primitives": ["beacon_callback_frequency", "dashboard_runtime_incident_export"],
|
|
50
|
+
"description": "Runtime Defense beacon callback fires on every tamper detection event AND on periodic heartbeat. Configure the cadence in your protection options (BeaconUrl + heartbeat interval) to satisfy the seven-day-or-faster requirement."
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"id": "11.6.1.c",
|
|
54
|
+
"title": "Alerts personnel to unauthorized modification.",
|
|
55
|
+
"jso_evidence_primitives": ["beacon_callback", "siem_forwarder", "dashboard_runtime_incident_export"],
|
|
56
|
+
"description": "Beacon callback emits structured JSON events to your BeaconUrl. JSO ships first-party SIEM adapters in jso-beacon-slack (Splunk HEC, Elasticsearch, generic HMAC-signed webhook) that forward those events to the on-call rota."
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"out_of_scope_customer_owns": [
|
|
62
|
+
{
|
|
63
|
+
"id": "6.4.3.b.tls",
|
|
64
|
+
"note": "TLS protection of the JSO HTTP API call is JSO's responsibility (HSTS, TLS 1.3); but TLS protection of the consumer's first-fetch of the protected script from your CDN is the customer's responsibility (Subresource Integrity, CSP)."
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "11.6.1.c.runbook",
|
|
68
|
+
"note": "JSO delivers the alert; the customer must define the on-call runbook (who pages, what they do)."
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"id": "12.10.x",
|
|
72
|
+
"note": "Incident response plan is customer-owned. JSO contributes the detection signal only."
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|