@countinghouse/ch-local 0.0.0-stage → 1.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/LICENSE +202 -0
- package/README.md +361 -2
- package/bin/ch-local.js +472 -0
- package/clients/claude-code/.claude-plugin/plugin.json +6 -0
- package/clients/claude-code/.mcp.json +11 -0
- package/clients/claude-code/bin/launch.js +235 -0
- package/clients/claude-code/bin/win-acl.js +420 -0
- package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
- package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
- package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
- package/lib/allowlist.js +65 -0
- package/lib/aside.js +16 -0
- package/lib/atomic.js +45 -0
- package/lib/auto-apply.js +245 -0
- package/lib/auto-upgrade.js +98 -0
- package/lib/availability.js +307 -0
- package/lib/ceiling.js +280 -0
- package/lib/clean-text.js +20 -0
- package/lib/cli-change.js +38 -0
- package/lib/client-conditions-fixtures.js +143 -0
- package/lib/client-conditions.js +656 -0
- package/lib/clients.js +179 -0
- package/lib/command-line.js +202 -0
- package/lib/conditions-command.js +116 -0
- package/lib/control.js +134 -0
- package/lib/credential-store.js +414 -0
- package/lib/credentials-command.js +344 -0
- package/lib/daemon-requests.js +137 -0
- package/lib/daemon.js +888 -0
- package/lib/describe-module.js +137 -0
- package/lib/description-check.js +175 -0
- package/lib/failed-json.js +43 -0
- package/lib/gc.js +274 -0
- package/lib/github-token.js +57 -0
- package/lib/handoff-io.js +73 -0
- package/lib/held-back.js +116 -0
- package/lib/hidden-input.js +64 -0
- package/lib/history.js +49 -0
- package/lib/home.js +372 -0
- package/lib/in-place.js +1036 -0
- package/lib/install-plan.js +142 -0
- package/lib/install.js +846 -0
- package/lib/installed-description.js +153 -0
- package/lib/integrity.js +7 -0
- package/lib/lock.js +456 -0
- package/lib/lockfile-rules.js +98 -0
- package/lib/machine.js +20 -0
- package/lib/module-credentials.js +403 -0
- package/lib/module-record.js +298 -0
- package/lib/module-roles.js +44 -0
- package/lib/module-seams.js +26 -0
- package/lib/module-store.js +202 -0
- package/lib/module-values.js +334 -0
- package/lib/names.js +31 -0
- package/lib/next-steps.js +8 -0
- package/lib/node-check.js +56 -0
- package/lib/npm-fetch.js +123 -0
- package/lib/npm-release.js +99 -0
- package/lib/npm-upgrade.js +146 -0
- package/lib/npm.js +41 -0
- package/lib/outside-edits.js +162 -0
- package/lib/own-applied.js +175 -0
- package/lib/own-command.js +380 -0
- package/lib/own-file.js +120 -0
- package/lib/own-record.js +96 -0
- package/lib/own-tree.js +336 -0
- package/lib/pack-table.js +290 -0
- package/lib/packs-command.js +570 -0
- package/lib/packs.js +219 -0
- package/lib/pins.js +64 -0
- package/lib/pipe-probe.js +82 -0
- package/lib/plain-read.js +63 -0
- package/lib/private-file.js +90 -0
- package/lib/private-write.js +33 -0
- package/lib/provenance.js +234 -0
- package/lib/record.js +82 -0
- package/lib/registry.js +22 -0
- package/lib/release-pins.js +350 -0
- package/lib/release-pins.json +4225 -0
- package/lib/release-tags.js +12 -0
- package/lib/release.js +36 -0
- package/lib/restart-command.js +161 -0
- package/lib/rollback.js +227 -0
- package/lib/run-liveness.js +15 -0
- package/lib/runtime-log.js +287 -0
- package/lib/sandbox-support.js +17 -0
- package/lib/semver-order.js +40 -0
- package/lib/session-socket.js +69 -0
- package/lib/session-table.js +238 -0
- package/lib/session.js +281 -0
- package/lib/settings-command.js +82 -0
- package/lib/settings.js +564 -0
- package/lib/shim-binary.js +152 -0
- package/lib/shim-config.js +159 -0
- package/lib/shim-install.js +365 -0
- package/lib/sigstore/README.md +44 -0
- package/lib/sigstore/npm-keys.json +18 -0
- package/lib/sigstore/trusted-root.json +126 -0
- package/lib/snippets.js +76 -0
- package/lib/start.js +721 -0
- package/lib/store-files.js +48 -0
- package/lib/store-paths.js +33 -0
- package/lib/swap-preload.js +38 -0
- package/lib/tar.js +220 -0
- package/lib/uninstall.js +314 -0
- package/lib/unpack.js +41 -0
- package/lib/upgrade-stamp.js +63 -0
- package/lib/upgrade.js +281 -0
- package/lib/watch.js +40 -0
- package/lib/win-acl.js +420 -0
- package/node_modules/@sigstore/bundle/LICENSE +202 -0
- package/node_modules/@sigstore/bundle/README.md +19 -0
- package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
- package/node_modules/@sigstore/bundle/dist/build.js +100 -0
- package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
- package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
- package/node_modules/@sigstore/bundle/dist/error.js +25 -0
- package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
- package/node_modules/@sigstore/bundle/dist/index.js +43 -0
- package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
- package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
- package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
- package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
- package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
- package/node_modules/@sigstore/bundle/package.json +35 -0
- package/node_modules/@sigstore/core/LICENSE +202 -0
- package/node_modules/@sigstore/core/README.md +10 -0
- package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
- package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
- package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
- package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
- package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/crypto.js +69 -0
- package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/dsse.js +29 -0
- package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/encoding.js +27 -0
- package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
- package/node_modules/@sigstore/core/dist/index.js +66 -0
- package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/json.js +60 -0
- package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/oid.js +20 -0
- package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/pem.js +43 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
- package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
- package/node_modules/@sigstore/core/dist/stream.js +117 -0
- package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
- package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
- package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
- package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
- package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
- package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
- package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
- package/node_modules/@sigstore/core/package.json +31 -0
- package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
- package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
- package/node_modules/@sigstore/verify/README.md +9 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
- package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
- package/node_modules/@sigstore/verify/dist/error.js +34 -0
- package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/index.js +28 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
- package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
- package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
- package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
- package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/policy.js +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
- package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
- package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
- package/node_modules/@sigstore/verify/package.json +36 -0
- package/package.json +37 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The runtime's store files in the home, as `ch-local status` sees them
|
|
3
|
+
// (start runs countinghouse with --store local --storePath <home>/store),
|
|
4
|
+
// read only. Not metering.json: ch-local's start never meters, and without
|
|
5
|
+
// --meter the runtime never reads the ledger, so it refuses nothing for it.
|
|
6
|
+
// A file that is there and does not parse as a JSON object is corrupt, by
|
|
7
|
+
// the rule countinghouse's store reads it with (lib/store/json-file.js
|
|
8
|
+
// readMap). From countinghouse 8.0.0 (RUNTIME), only a runtime that had the
|
|
9
|
+
// file open before it became corrupt replaces it; an older one handles it
|
|
10
|
+
// its own way, so these lines are said only for a home recorded on 8.0.0 or
|
|
11
|
+
// later. Status can't tell whether such a runtime is running, so it says
|
|
12
|
+
// what it sees and the user's own safe step, one line a file. A missing or
|
|
13
|
+
// good file, or one that can't be read for another reason (the runtime's
|
|
14
|
+
// log says that one), says nothing here.
|
|
15
|
+
const fs = require('node:fs');
|
|
16
|
+
const path = require('node:path');
|
|
17
|
+
|
|
18
|
+
// the runtime whose store these lines describe (lib/release-pins.json's
|
|
19
|
+
// floor for countinghouse holds every release to it)
|
|
20
|
+
const RUNTIME = '8.0.0';
|
|
21
|
+
const UNTIL = 'until a runtime that had it open before it became corrupt replaces it';
|
|
22
|
+
// each store file, in this order, and its line (file: its full path)
|
|
23
|
+
const FILES = [
|
|
24
|
+
['used-nonces.json', (f) => `store: used-nonces.json is corrupt: when a tool asks you a question during a call, your answer is refused, ${UNTIL}; if none does, move it away (${f})`],
|
|
25
|
+
['kv.json', (f) => `store: kv.json is corrupt: the modules' stored data can't be read or changed, and an uninstall that would remove it is refused, ${UNTIL}; if none does, move it away (${f}), and what the modules stored starts empty`]
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
// file -> whether it is there, readable, and not a JSON object
|
|
29
|
+
function corrupt(file) {
|
|
30
|
+
let raw;
|
|
31
|
+
try { raw = fs.readFileSync(file, 'utf8'); } catch (err) { return false; }
|
|
32
|
+
try {
|
|
33
|
+
const data = JSON.parse(raw);
|
|
34
|
+
return !(data != null && typeof data === 'object' && !Array.isArray(data));
|
|
35
|
+
} catch (err) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// the store folder, the home's recorded countinghouse -> the lines status
|
|
41
|
+
// says, one a corrupt file (none for a runtime older than RUNTIME, or one
|
|
42
|
+
// not known)
|
|
43
|
+
function storeLines(dir, runtimeVersion) {
|
|
44
|
+
if (typeof runtimeVersion !== 'string' || require('./release-pins').belowFloor(runtimeVersion, RUNTIME)) return [];
|
|
45
|
+
return FILES.filter(([name]) => corrupt(path.join(dir, name))).map(([name, line]) => line(path.join(dir, name)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = {storeLines, FILES, RUNTIME};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Where a module version is in the store (lib/module-store.js, #413 section
|
|
3
|
+
// 9.1), and nothing else: what start and the applier read to load from the
|
|
4
|
+
// store, without the store's placing code (unpack, the tar reader).
|
|
5
|
+
const path = require('node:path');
|
|
6
|
+
const {PACKAGE, storeVersion} = require('./names');
|
|
7
|
+
|
|
8
|
+
function checkName(name, version) {
|
|
9
|
+
if (typeof name !== 'string' || !PACKAGE.test(name)) throw new Error(`${JSON.stringify(name)} is not a package name`);
|
|
10
|
+
if (!storeVersion(version)) throw new Error(`${name}: ${JSON.stringify(version)} is not a version`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// where: layout(). -> <store>/<name>/<version> (a scoped name is two directories)
|
|
14
|
+
function versionDir(where, name, version) {
|
|
15
|
+
checkName(name, version);
|
|
16
|
+
return path.join(where.moduleStore, ...name.split('/'), version);
|
|
17
|
+
}
|
|
18
|
+
const markerFile = (where, name, version) => `${versionDir(where, name, version)}.json`;
|
|
19
|
+
|
|
20
|
+
// Whether the version looks placed: its directory and its marker there. A
|
|
21
|
+
// start's own check before it names the version to the runtime (which
|
|
22
|
+
// checks the directory against --modulesRoot itself); placing and
|
|
23
|
+
// collection read the marker in full (lib/module-store.js isComplete).
|
|
24
|
+
function looksPlaced(where, name, version) {
|
|
25
|
+
const fs = require('node:fs');
|
|
26
|
+
try {
|
|
27
|
+
return fs.lstatSync(versionDir(where, name, version)).isDirectory() && fs.lstatSync(markerFile(where, name, version)).isFile();
|
|
28
|
+
} catch (err) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = {versionDir, markerFile, checkName, looksPlaced};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Code that runs from <home>/app while that tree is replaced -- an install
|
|
3
|
+
// or upgrade (lib/install.js swaps app.new in), a rollback (lib/rollback.js
|
|
4
|
+
// swaps the previous release back, or finishes an interrupted one), the
|
|
5
|
+
// daemon, which outlives both -- must never load a file of the other
|
|
6
|
+
// release. Node resolves a require('./x') by this file's path, which after
|
|
7
|
+
// the swap names the other release's lib: a function this release calls may
|
|
8
|
+
// not be there (C-upgrade-path's test caught rollback calling the older
|
|
9
|
+
// release's upgrade.js).
|
|
10
|
+
//
|
|
11
|
+
// So before the swap, and at the daemon's start, preloadForSwap() loads every
|
|
12
|
+
// module of this release's lib, every JSON file lib requires, and its own
|
|
13
|
+
// dependencies (package.json's, which resolve through <home>/app/node_modules
|
|
14
|
+
// too: sigstore's, lazily required by provenance): any later
|
|
15
|
+
// require('./x') -- however lazy, however deep in a callee -- is this
|
|
16
|
+
// release's copy, from the cache. No list to keep: the whole lib, by
|
|
17
|
+
// construction (86 modules, about 200 ms). Everywhere else modules stay
|
|
18
|
+
// lazily required (start loads only what it needs).
|
|
19
|
+
// test/swap-requires.test.js pins that it loads them all, and that it comes
|
|
20
|
+
// before every swap.
|
|
21
|
+
const fs = require('node:fs');
|
|
22
|
+
const path = require('node:path');
|
|
23
|
+
|
|
24
|
+
// (the JSON files lib requires, from lib/ or the package root)
|
|
25
|
+
const JSON_FILES = ['../package.json', './release-pins.json', './sigstore/trusted-root.json', './sigstore/npm-keys.json'];
|
|
26
|
+
|
|
27
|
+
// (this release's own runtime dependencies, by name, from here)
|
|
28
|
+
const DEPENDENCIES = Object.keys(require('../package.json').dependencies || {});
|
|
29
|
+
|
|
30
|
+
function preloadForSwap() {
|
|
31
|
+
for (const name of fs.readdirSync(__dirname)) {
|
|
32
|
+
if (name.endsWith('.js')) require(path.join(__dirname, name));
|
|
33
|
+
}
|
|
34
|
+
for (const file of JSON_FILES) require(file);
|
|
35
|
+
for (const dep of DEPENDENCIES) require(dep);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {preloadForSwap, JSON_FILES, DEPENDENCIES};
|
package/lib/tar.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// A pack's or part's npm tarball unpacked without npm: they have no
|
|
3
|
+
// dependencies (#43), so npm adds nothing but its own trust surface. This is
|
|
4
|
+
// security code (reviewer, 2026-11-12), so it accepts the least it can:
|
|
5
|
+
// - regular files and directories under package/, nothing else: no links,
|
|
6
|
+
// devices or FIFOs, no GNU extensions; a pax header (type x) only with the
|
|
7
|
+
// path, time and size keys, parsed strictly, the size equal to the header's;
|
|
8
|
+
// - names that cannot mean anything else on another system: no backslash,
|
|
9
|
+
// colon, NUL, empty, . or .. segment, Windows-reserved name or trailing
|
|
10
|
+
// dot or space, and no path twice (also by case or Unicode form, or as a
|
|
11
|
+
// file and a directory);
|
|
12
|
+
// - the total and per-file sizes and the entry count capped, including
|
|
13
|
+
// while decompressing (a gzip bomb).
|
|
14
|
+
// Every header is read and checked before anything is written, and a
|
|
15
|
+
// tarball refused part-way leaves nothing behind.
|
|
16
|
+
const fs = require('node:fs');
|
|
17
|
+
const path = require('node:path');
|
|
18
|
+
const zlib = require('node:zlib');
|
|
19
|
+
|
|
20
|
+
const LIMITS = {maxBytes: 64 * 1024 * 1024, maxFileBytes: 16 * 1024 * 1024, maxEntries: 10000};
|
|
21
|
+
// size is accepted only when it equals the header's own (node-tar writes it).
|
|
22
|
+
const PAX_KEYS = new Set(['path', 'mtime', 'atime', 'ctime', 'size']);
|
|
23
|
+
const PAX_MAX = 4096;
|
|
24
|
+
// Windows' reserved device names, with the superscript digits and the console names.
|
|
25
|
+
const RESERVED = /^(con|prn|aux|nul|com[0-9\u00b9\u00b2\u00b3]|lpt[0-9\u00b9\u00b2\u00b3]|conin\$|conout\$)(\..*)?$/i;
|
|
26
|
+
// The key two names share when a case-insensitive file system would make them one:
|
|
27
|
+
// NFC, then a full case fold (upper then lower: long s and dotless i fold too).
|
|
28
|
+
const fold = (s) => s.normalize('NFC').toUpperCase().toLowerCase().normalize('NFC');
|
|
29
|
+
|
|
30
|
+
function refuse(why) {
|
|
31
|
+
const err = new Error(`refused the tarball: ${why}`);
|
|
32
|
+
err.code = 'TAR_REFUSED';
|
|
33
|
+
return err;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cstr = (buf, start, len) => {
|
|
37
|
+
const s = buf.subarray(start, start + len);
|
|
38
|
+
const end = s.indexOf(0);
|
|
39
|
+
return s.subarray(0, end === -1 ? len : end).toString('utf8');
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function octal(buf, start, len, what) {
|
|
43
|
+
if (buf[start] & 0x80) throw refuse(`a ${what} in base-256`);
|
|
44
|
+
const s = cstr(buf, start, len).replace(/[ \0]+$/, '').replace(/^ +/, '');
|
|
45
|
+
if (!/^[0-7]*$/.test(s)) throw refuse(`a ${what} that is not octal`);
|
|
46
|
+
return s === '' ? 0 : parseInt(s, 8);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function checksumOk(h) {
|
|
50
|
+
let sum = 0;
|
|
51
|
+
for (let i = 0; i < 512; i++) sum += (i >= 148 && i < 156) ? 0x20 : h[i];
|
|
52
|
+
return sum === octal(h, 148, 8, 'checksum');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// "<len> <key>=<value>\n" records, each length exact.
|
|
56
|
+
function parsePax(data) {
|
|
57
|
+
const out = {};
|
|
58
|
+
let pos = 0;
|
|
59
|
+
while (pos < data.length) {
|
|
60
|
+
const space = data.indexOf(0x20, pos);
|
|
61
|
+
const lenText = space === -1 ? '' : data.subarray(pos, space).toString('ascii');
|
|
62
|
+
const len = /^[1-9][0-9]*$/.test(lenText) ? Number(lenText) : NaN;
|
|
63
|
+
if (!(len > 0) || pos + len > data.length || data[pos + len - 1] !== 0x0a) throw refuse('a malformed pax header');
|
|
64
|
+
const record = data.subarray(space + 1, pos + len - 1).toString('utf8');
|
|
65
|
+
const eq = record.indexOf('=');
|
|
66
|
+
if (eq <= 0) throw refuse('a malformed pax header');
|
|
67
|
+
const key = record.slice(0, eq);
|
|
68
|
+
if (!PAX_KEYS.has(key)) throw refuse(`a pax header with the key ${JSON.stringify(key)}`);
|
|
69
|
+
if (Object.prototype.hasOwnProperty.call(out, key)) throw refuse(`a pax header that repeats the key ${JSON.stringify(key)}`);
|
|
70
|
+
out[key] = record.slice(eq + 1);
|
|
71
|
+
pos += len;
|
|
72
|
+
}
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The member's path under package/ -> its segments; refuses anything else.
|
|
77
|
+
function segmentsOf(name, isDir, bundled = false) {
|
|
78
|
+
const shown = JSON.stringify(name);
|
|
79
|
+
if (/[\\:\0]/.test(name)) throw refuse(`the member ${shown} has a backslash, colon or NUL`);
|
|
80
|
+
// eslint-disable-next-line no-control-regex
|
|
81
|
+
if (/[<>"|?*\u0001-\u001f]/.test(name)) throw refuse(`the member ${shown} has a character Windows does not allow in a name`);
|
|
82
|
+
if (name.startsWith('/')) throw refuse(`the member ${shown} is an absolute path`);
|
|
83
|
+
if (!name.startsWith('package/')) throw refuse(`the member ${shown} is not under package/`);
|
|
84
|
+
let rest = name.slice('package/'.length);
|
|
85
|
+
if (isDir && rest.endsWith('/')) rest = rest.slice(0, -1);
|
|
86
|
+
if (rest === '') return isDir ? [] : (() => { throw refuse(`the member ${shown} has no name`); })();
|
|
87
|
+
const segments = rest.split('/');
|
|
88
|
+
for (const s of segments) {
|
|
89
|
+
if (s === '' || s === '.' || s === '..') throw refuse(`the member ${shown} has an empty, . or .. segment`);
|
|
90
|
+
if (RESERVED.test(s) || /[. ]$/.test(s)) throw refuse(`the member ${shown} has a name Windows would change`);
|
|
91
|
+
if (!bundled && fold(s) === 'node_modules') throw refuse(`the member ${shown} is under a node_modules directory: a pack's packages bundle no dependencies`);
|
|
92
|
+
}
|
|
93
|
+
return segments;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// buffer: the .tgz bytes. dest: a directory that must not exist yet.
|
|
97
|
+
// Every header read and checked, nothing written -> [{segments, isDir, data}]
|
|
98
|
+
// bundled: a runtime package's tarball, which may carry node_modules (its
|
|
99
|
+
// bundleDependencies); a pack's never does
|
|
100
|
+
function readEntries(buffer, limits = {}, {bundled = false} = {}) {
|
|
101
|
+
const {maxBytes, maxFileBytes, maxEntries} = {...LIMITS, ...limits};
|
|
102
|
+
let tar;
|
|
103
|
+
try {
|
|
104
|
+
// Beyond the data, each entry has at most a header and its padding, and a
|
|
105
|
+
// pax header with its data (at most PAX_MAX) before it; two end blocks.
|
|
106
|
+
tar = zlib.gunzipSync(buffer, {maxOutputLength: maxBytes + (maxEntries + 2) * (1024 + 512 + PAX_MAX)});
|
|
107
|
+
} catch (err) {
|
|
108
|
+
throw refuse(err.code === 'ERR_BUFFER_TOO_LARGE' || err instanceof RangeError ? 'it is over the size cap uncompressed' : 'it is not a gzip tarball');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const entries = [];
|
|
112
|
+
const files = new Set();
|
|
113
|
+
const dirs = new Set();
|
|
114
|
+
// Each directory's spelling, by its case- and form-folded key: two
|
|
115
|
+
// spellings of one key would be two directories here and one on macOS or
|
|
116
|
+
// Windows.
|
|
117
|
+
const spelling = new Map();
|
|
118
|
+
const spell = (key, exact, name) => {
|
|
119
|
+
if (spelling.has(key) && spelling.get(key) !== exact) throw refuse(`the member ${JSON.stringify(name)} spells a directory that is already there in another case or Unicode form`);
|
|
120
|
+
spelling.set(key, exact);
|
|
121
|
+
};
|
|
122
|
+
let total = 0;
|
|
123
|
+
let pending = null;
|
|
124
|
+
let offset = 0;
|
|
125
|
+
for (;;) {
|
|
126
|
+
if (offset + 512 > tar.length) throw refuse('it ends inside a header');
|
|
127
|
+
const h = tar.subarray(offset, offset + 512);
|
|
128
|
+
if (h.every((b) => b === 0)) break;
|
|
129
|
+
if (!checksumOk(h)) throw refuse(`a header checksum is wrong at byte ${offset}`);
|
|
130
|
+
// POSIX ustar only: magic "ustar\0", version "00" (GNU's "ustar \0" is refused).
|
|
131
|
+
if (h.toString('latin1', 257, 265) !== 'ustar\u000000') throw refuse(`a header at byte ${offset} is not POSIX ustar`);
|
|
132
|
+
const size = octal(h, 124, 12, 'size');
|
|
133
|
+
const type = h[156] === 0 ? '0' : String.fromCharCode(h[156]);
|
|
134
|
+
const dataStart = offset + 512;
|
|
135
|
+
if (dataStart + size > tar.length) throw refuse('it ends inside a member');
|
|
136
|
+
const data = tar.subarray(dataStart, dataStart + size);
|
|
137
|
+
offset = dataStart + Math.ceil(size / 512) * 512;
|
|
138
|
+
|
|
139
|
+
if (type === 'x') {
|
|
140
|
+
if (pending != null) throw refuse('two pax headers in a row');
|
|
141
|
+
if (size > PAX_MAX) throw refuse(`a pax header over ${PAX_MAX / 1024} KiB`);
|
|
142
|
+
pending = parsePax(data);
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
const prefix = cstr(h, 345, 155);
|
|
146
|
+
const headerName = prefix !== '' ? `${prefix}/${cstr(h, 0, 100)}` : cstr(h, 0, 100);
|
|
147
|
+
const name = pending != null && pending.path != null ? pending.path : headerName;
|
|
148
|
+
if (pending != null && pending.size != null && pending.size !== String(size)) throw refuse(`a pax size of ${JSON.stringify(pending.size)} for the member ${JSON.stringify(name)}, whose header says ${size}`);
|
|
149
|
+
pending = null;
|
|
150
|
+
if (type !== '0' && type !== '5') {
|
|
151
|
+
throw refuse(`the member ${JSON.stringify(name)} is of type ${JSON.stringify(type)}${type === '1' || type === '2' ? ' (a link)' : ''}; only files and directories are allowed`);
|
|
152
|
+
}
|
|
153
|
+
if (entries.length + 1 > maxEntries) throw refuse(`it has more than ${maxEntries} entries`);
|
|
154
|
+
const isDir = type === '5';
|
|
155
|
+
const segments = segmentsOf(name, isDir, bundled);
|
|
156
|
+
if (segments.length === 0) continue;
|
|
157
|
+
const key = fold(segments.join('/'));
|
|
158
|
+
const ancestors = segments.slice(0, -1).map((_, i) => fold(segments.slice(0, i + 1).join('/')));
|
|
159
|
+
if (ancestors.some((a) => files.has(a))) throw refuse(`the member ${JSON.stringify(name)} is under a path that is a file`);
|
|
160
|
+
if (isDir) {
|
|
161
|
+
if (files.has(key)) throw refuse(`the member ${JSON.stringify(name)} is both a file and a directory`);
|
|
162
|
+
} else {
|
|
163
|
+
if (files.has(key) || dirs.has(key)) throw refuse(`the member ${JSON.stringify(name)} is there twice (or as a directory)`);
|
|
164
|
+
if (size > maxFileBytes) throw refuse(`the member ${JSON.stringify(name)} is over the per-file cap of ${maxFileBytes} bytes`);
|
|
165
|
+
total += size;
|
|
166
|
+
if (total > maxBytes) throw refuse(`its files are over the total cap of ${maxBytes} bytes`);
|
|
167
|
+
files.add(key);
|
|
168
|
+
}
|
|
169
|
+
ancestors.forEach((a, i) => { spell(a, segments.slice(0, i + 1).join('/'), name); dirs.add(a); });
|
|
170
|
+
if (isDir) { spell(key, segments.join('/'), name); dirs.add(key); }
|
|
171
|
+
entries.push({segments, isDir, data});
|
|
172
|
+
}
|
|
173
|
+
if (pending != null) throw refuse('a pax header with no member after it');
|
|
174
|
+
return entries;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function extractPackage(buffer, dest, limits = {}) {
|
|
178
|
+
if (fs.existsSync(dest)) throw refuse(`${dest} exists; a package is never unpacked over another`);
|
|
179
|
+
const entries = readEntries(buffer, limits);
|
|
180
|
+
try {
|
|
181
|
+
fs.mkdirSync(dest, {recursive: true});
|
|
182
|
+
for (const {segments, isDir, data} of entries) {
|
|
183
|
+
const at = path.join(dest, ...segments);
|
|
184
|
+
if (isDir) { fs.mkdirSync(at, {recursive: true}); continue; }
|
|
185
|
+
fs.mkdirSync(path.dirname(at), {recursive: true});
|
|
186
|
+
fs.writeFileSync(at, data, {flag: 'wx', mode: 0o644});
|
|
187
|
+
}
|
|
188
|
+
} catch (err) {
|
|
189
|
+
fs.rmSync(dest, {recursive: true, force: true});
|
|
190
|
+
throw err;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// One file's bytes from a tarball in memory, read by the same rules, nothing
|
|
195
|
+
// written (an upgrade reads a new release's lib/release-pins.json so) ->
|
|
196
|
+
// Buffer, or null when the tarball has no such file. member: its path within
|
|
197
|
+
// the package, as "lib/release-pins.json" (the tarball's package/ is not part
|
|
198
|
+
// of it, as extractPackage writes none).
|
|
199
|
+
// bundled: as readEntries' (a runtime package's tarball).
|
|
200
|
+
function readMember(buffer, member, limits = {}, {bundled = false} = {}) {
|
|
201
|
+
const want = member.split('/');
|
|
202
|
+
const found = readEntries(buffer, limits, {bundled}).find((e) => !e.isDir && e.segments.length === want.length && e.segments.every((s, i) => s === want[i]));
|
|
203
|
+
return found != null ? Buffer.from(found.data) : null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Several members of one tarball, its entries read once (the Reviewer's high
|
|
207
|
+
// review of #98, 8: a module's package.json and api.json) -> {member: Buffer
|
|
208
|
+
// | null}. Throws as readEntries does.
|
|
209
|
+
function readMembers(buffer, members, limits = {}, {bundled = false} = {}) {
|
|
210
|
+
const entries = readEntries(buffer, limits, {bundled});
|
|
211
|
+
const out = {};
|
|
212
|
+
for (const member of members) {
|
|
213
|
+
const want = member.split('/');
|
|
214
|
+
const found = entries.find((e) => !e.isDir && e.segments.length === want.length && e.segments.every((s, i) => s === want[i]));
|
|
215
|
+
out[member] = found != null ? Buffer.from(found.data) : null;
|
|
216
|
+
}
|
|
217
|
+
return out;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
module.exports = {extractPackage, readMember, readMembers, LIMITS};
|