@rightkit/release 0.2.80 → 0.2.81

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/hardeningscan.mjs CHANGED
@@ -1,139 +1,144 @@
1
- #!/usr/bin/env node
2
- import { createHash } from "node:crypto";
3
- import { createReadStream, readFileSync, realpathSync } from "node:fs";
4
- import { lstat, readdir } from "node:fs/promises";
5
- import path from "node:path";
6
- import { HARDENING_RULES } from "./hardening-evidence.mjs";
7
-
8
- const rawArgs = process.argv.slice(2);
9
- if (rawArgs.length === 0 || rawArgs.includes("-h") || rawArgs.includes("--help")) {
10
- console.error("usage: node hardeningscan.mjs [--allow-evidence <json>] <artifact-path>...");
11
- process.exit(rawArgs.length === 0 ? 2 : 0);
12
- }
13
- const allowIndex = rawArgs.indexOf("--allow-evidence");
14
- const allowEvidencePath = allowIndex >= 0 ? rawArgs[allowIndex + 1] : null;
15
- if (allowIndex >= 0 && !allowEvidencePath) throw new Error("--allow-evidence requires a JSON path");
16
- const args = rawArgs.filter((_, index) => index !== allowIndex && index !== allowIndex + 1);
17
- if (!args.length) throw new Error("at least one artifact path is required");
18
-
19
- const root = realpathSync(process.cwd());
20
- const findings = [];
21
- const evidence = allowEvidencePath ? JSON.parse(readFileSync(allowEvidencePath, "utf8")) : { allowances: [] };
22
- if (allowEvidencePath && (evidence.schemaVersion !== 1 || evidence.kind !== "rightkit-hardening-evidence")) {
23
- throw new Error("invalid hardening evidence");
24
- }
25
- const allowances = evidence.allowances ?? [];
26
- for (const allowance of allowances) {
27
- const sourceMatch = typeof allowance.sourceEvidence === "string" ? /^(.*):([1-9]\d*)$/.exec(allowance.sourceEvidence) : null;
28
- const knownRule = HARDENING_RULES[allowance.rule];
29
- if (!knownRule || allowance.exact !== knownRule.exact || !sourceMatch || !/^[a-f0-9]{64}$/.test(allowance.artifactSha256 ?? "") || !/^[a-f0-9]{64}$/.test(allowance.sourceSha256 ?? "") || allowance.sourceLine !== Number(sourceMatch[2]) || typeof allowance.rationale !== "string" || allowance.rationale.trim().length < 12) {
30
- throw new Error("invalid hardening allowance source binding");
31
- }
32
- const sourcePath = realpathSync(path.resolve(root, sourceMatch[1]));
33
- const sourceRelative = path.relative(root, sourcePath);
34
- if (sourceRelative === ".." || sourceRelative.startsWith("../") || sourceRelative.startsWith("..\\") || path.isAbsolute(sourceRelative)) {
35
- throw new Error("hardening allowance source escapes release root");
36
- }
37
- const sourceBytes = readFileSync(sourcePath);
38
- if (createHash("sha256").update(sourceBytes).digest("hex") !== allowance.sourceSha256) throw new Error("hardening allowance source digest mismatch");
39
- const line = sourceBytes.toString("utf8").split(/\r?\n/)[allowance.sourceLine - 1];
40
- if (typeof line !== "string" || !line.includes(allowance.exact)) throw new Error("hardening allowance source token mismatch");
41
- }
42
-
43
- const fileNameRules = [
44
- [/\.map$/i, "source map shipped"],
45
- [/\.pdb$/i, "Windows debug symbols shipped"],
46
- [/\.dSYM(?:$|[/\\])/i, "macOS debug symbols shipped"],
47
- [/\.mlpackage(?:$|[/\\])/i, "raw CoreML package shipped"],
48
- [/[/\\]docs[/\\]experiments(?:$|[/\\])/i, "experiment docs shipped"],
49
- [/[/\\]\.scratch(?:$|[/\\])/i, "scratch directory shipped"],
50
- [/[/\\]\.git(?:$|[/\\])/i, "git metadata shipped"],
51
- [/[/\\]node_modules(?:$|[/\\])/i, "node_modules shipped"],
52
- [/[/\\](?:src|tests?|benches|benchmarks)(?:$|[/\\])/i, "source/test tree shipped"],
53
- [/[/\\]tdt_w15_p6(?:$|[/\\])/i, "stale TDT p6 model shipped"],
54
- ];
55
-
56
- const contentRules = [
57
- ["local-source-path", /\/Users\/adrdsouza\/claude/gi, "local source path leaked"],
58
- ["local-cargo-path", /\/Users\/adrdsouza\/\.cargo/gi, "local cargo path leaked"],
59
- ["local-windows-path", /C:\\Users\\adrdsouza\\(?:claude|\.cargo)/gi, "local Windows source path leaked"],
60
- ["experiment-path", /docs\/experiments/gi, "experiment path leaked"],
61
- ["cleanup-prompt-marker", /l3_cleanup_prompt/gi, "L3 cleanup prompt marker leaked"],
62
- ["system-prompt-marker", /SYSTEM_PROMPT/gi, "system prompt marker leaked"],
63
- ["secret-env-name", /OPENAI_API_KEY|ANTHROPIC_API_KEY|APPLE_PASSWORD|NOTARY_PROFILE/gi, "secret/env key name leaked"],
64
- ["gpl-flag", /--enable-gpl|--enable-nonfree/gi, "GPL/nonfree ffmpeg flag leaked"],
65
- ["stale-model", /tdt_w15_p6/gi, "stale TDT p6 string leaked"],
66
- ["experiment-model", /Canary-Qwen|Nemotron|dqlstm|bias-experiments/gi, "experiment/model-history marker leaked"],
67
- ];
68
-
69
- const maxPatternLen = Math.max(...contentRules.map(([, rule]) => String(rule).length), 256);
70
-
71
- function add(kind, file, message, detail = "") {
72
- findings.push({ kind, file: path.relative(root, file) || file, message, detail });
73
- }
74
-
75
- async function walk(target) {
76
- const st = await lstat(target);
77
- const normalized = target.split(path.sep).join("/");
78
- for (const [rule, message] of fileNameRules) if (rule.test(normalized)) add("path", target, message);
79
- if (st.isDirectory()) {
80
- const entries = await readdir(target);
81
- await Promise.all(entries.map((name) => walk(path.join(target, name))));
82
- return;
83
- }
84
- if (st.isFile()) await scanFile(target);
85
- }
86
-
87
- function scanFile(file) {
88
- return new Promise((resolveScan) => {
89
- const artifactSha256 = createHash("sha256").update(readFileSync(file)).digest("hex");
90
- const stream = createReadStream(file, { highWaterMark: 256 * 1024 });
91
- let tail = "";
92
- stream.on("data", (chunk) => {
93
- const text = tail + chunk.toString("latin1");
94
- for (const [ruleId, rule, message] of contentRules) {
95
- if (/ffmpeg-LICENSE\.txt$/i.test(file) && ruleId === "gpl-flag") continue;
96
- rule.lastIndex = 0;
97
- for (const match of text.matchAll(rule)) {
98
- const allowed = allowances.some((allowance) =>
99
- allowance.rule === ruleId &&
100
- allowance.artifactSha256 === artifactSha256 &&
101
- allowance.exact === match[0] &&
102
- typeof allowance.sourceEvidence === "string" &&
103
- typeof allowance.rationale === "string"
104
- );
105
- if (!allowed) add("content", file, message, rule.source);
106
- }
107
- }
108
- tail = text.slice(-maxPatternLen);
109
- });
110
- stream.on("error", (error) => {
111
- add("read", file, "could not scan file", error.message);
112
- resolveScan();
113
- });
114
- stream.on("end", resolveScan);
115
- });
116
- }
117
-
118
- for (const arg of args) {
119
- const target = path.resolve(arg);
120
- try {
121
- await walk(target);
122
- } catch (error) {
123
- add("target", target, "could not scan target", error.message);
124
- }
125
- }
126
-
127
- const unique = new Map();
128
- for (const finding of findings) unique.set([finding.kind, finding.file, finding.message].join("\0"), finding);
129
- const deduped = [...unique.values()].sort((left, right) =>
130
- (left.file + " " + left.message).localeCompare(right.file + " " + right.message),
131
- );
132
-
133
- if (deduped.length) {
134
- console.error("hardeningscan: " + deduped.length + " finding(s)");
135
- for (const finding of deduped) console.error("- [" + finding.kind + "] " + finding.file + ": " + finding.message);
136
- process.exit(1);
137
- }
138
-
139
- console.log("hardeningscan: clean");
1
+ #!/usr/bin/env node
2
+ import { createHash } from "node:crypto";
3
+ import { createReadStream, readFileSync, realpathSync } from "node:fs";
4
+ import { lstat, readdir } from "node:fs/promises";
5
+ import path from "node:path";
6
+ import { HARDENING_RULES } from "./hardening-evidence.mjs";
7
+
8
+ const rawArgs = process.argv.slice(2);
9
+ if (rawArgs.length === 0 || rawArgs.includes("-h") || rawArgs.includes("--help")) {
10
+ console.error("usage: node hardeningscan.mjs [--allow-evidence <json>] <artifact-path>...");
11
+ process.exit(rawArgs.length === 0 ? 2 : 0);
12
+ }
13
+ const allowIndex = rawArgs.indexOf("--allow-evidence");
14
+ const allowEvidencePath = allowIndex >= 0 ? rawArgs[allowIndex + 1] : null;
15
+ if (allowIndex >= 0 && !allowEvidencePath) throw new Error("--allow-evidence requires a JSON path");
16
+ // Only strip the flag pair when the flag is present: with allowIndex = -1,
17
+ // filtering out index `allowIndex + 1` would silently drop the first
18
+ // artifact path (a lone artifact arg then failed as "no artifact path").
19
+ const args = allowIndex >= 0
20
+ ? rawArgs.filter((_, index) => index !== allowIndex && index !== allowIndex + 1)
21
+ : rawArgs;
22
+ if (!args.length) throw new Error("at least one artifact path is required");
23
+
24
+ const root = realpathSync(process.cwd());
25
+ const findings = [];
26
+ const evidence = allowEvidencePath ? JSON.parse(readFileSync(allowEvidencePath, "utf8")) : { allowances: [] };
27
+ if (allowEvidencePath && (evidence.schemaVersion !== 1 || evidence.kind !== "rightkit-hardening-evidence")) {
28
+ throw new Error("invalid hardening evidence");
29
+ }
30
+ const allowances = evidence.allowances ?? [];
31
+ for (const allowance of allowances) {
32
+ const sourceMatch = typeof allowance.sourceEvidence === "string" ? /^(.*):([1-9]\d*)$/.exec(allowance.sourceEvidence) : null;
33
+ const knownRule = HARDENING_RULES[allowance.rule];
34
+ if (!knownRule || allowance.exact !== knownRule.exact || !sourceMatch || !/^[a-f0-9]{64}$/.test(allowance.artifactSha256 ?? "") || !/^[a-f0-9]{64}$/.test(allowance.sourceSha256 ?? "") || allowance.sourceLine !== Number(sourceMatch[2]) || typeof allowance.rationale !== "string" || allowance.rationale.trim().length < 12) {
35
+ throw new Error("invalid hardening allowance source binding");
36
+ }
37
+ const sourcePath = realpathSync(path.resolve(root, sourceMatch[1]));
38
+ const sourceRelative = path.relative(root, sourcePath);
39
+ if (sourceRelative === ".." || sourceRelative.startsWith("../") || sourceRelative.startsWith("..\\") || path.isAbsolute(sourceRelative)) {
40
+ throw new Error("hardening allowance source escapes release root");
41
+ }
42
+ const sourceBytes = readFileSync(sourcePath);
43
+ if (createHash("sha256").update(sourceBytes).digest("hex") !== allowance.sourceSha256) throw new Error("hardening allowance source digest mismatch");
44
+ const line = sourceBytes.toString("utf8").split(/\r?\n/)[allowance.sourceLine - 1];
45
+ if (typeof line !== "string" || !line.includes(allowance.exact)) throw new Error("hardening allowance source token mismatch");
46
+ }
47
+
48
+ const fileNameRules = [
49
+ [/\.map$/i, "source map shipped"],
50
+ [/\.pdb$/i, "Windows debug symbols shipped"],
51
+ [/\.dSYM(?:$|[/\\])/i, "macOS debug symbols shipped"],
52
+ [/\.mlpackage(?:$|[/\\])/i, "raw CoreML package shipped"],
53
+ [/[/\\]docs[/\\]experiments(?:$|[/\\])/i, "experiment docs shipped"],
54
+ [/[/\\]\.scratch(?:$|[/\\])/i, "scratch directory shipped"],
55
+ [/[/\\]\.git(?:$|[/\\])/i, "git metadata shipped"],
56
+ [/[/\\]node_modules(?:$|[/\\])/i, "node_modules shipped"],
57
+ [/[/\\](?:src|tests?|benches|benchmarks)(?:$|[/\\])/i, "source/test tree shipped"],
58
+ [/[/\\]tdt_w15_p6(?:$|[/\\])/i, "stale TDT p6 model shipped"],
59
+ ];
60
+
61
+ const contentRules = [
62
+ ["local-source-path", /\/Users\/adrdsouza\/claude/gi, "local source path leaked"],
63
+ ["local-cargo-path", /\/Users\/adrdsouza\/\.cargo/gi, "local cargo path leaked"],
64
+ ["local-windows-path", /C:\\Users\\adrdsouza\\(?:claude|\.cargo)/gi, "local Windows source path leaked"],
65
+ ["experiment-path", /docs\/experiments/gi, "experiment path leaked"],
66
+ ["cleanup-prompt-marker", /l3_cleanup_prompt/gi, "L3 cleanup prompt marker leaked"],
67
+ ["system-prompt-marker", /SYSTEM_PROMPT/gi, "system prompt marker leaked"],
68
+ ["secret-env-name", /OPENAI_API_KEY|ANTHROPIC_API_KEY|APPLE_PASSWORD|NOTARY_PROFILE/gi, "secret/env key name leaked"],
69
+ ["gpl-flag", /--enable-gpl|--enable-nonfree/gi, "GPL/nonfree ffmpeg flag leaked"],
70
+ ["stale-model", /tdt_w15_p6/gi, "stale TDT p6 string leaked"],
71
+ ["experiment-model", /Canary-Qwen|Nemotron|dqlstm|bias-experiments/gi, "experiment/model-history marker leaked"],
72
+ ];
73
+
74
+ const maxPatternLen = Math.max(...contentRules.map(([, rule]) => String(rule).length), 256);
75
+
76
+ function add(kind, file, message, detail = "") {
77
+ findings.push({ kind, file: path.relative(root, file) || file, message, detail });
78
+ }
79
+
80
+ async function walk(target) {
81
+ const st = await lstat(target);
82
+ const normalized = target.split(path.sep).join("/");
83
+ for (const [rule, message] of fileNameRules) if (rule.test(normalized)) add("path", target, message);
84
+ if (st.isDirectory()) {
85
+ const entries = await readdir(target);
86
+ await Promise.all(entries.map((name) => walk(path.join(target, name))));
87
+ return;
88
+ }
89
+ if (st.isFile()) await scanFile(target);
90
+ }
91
+
92
+ function scanFile(file) {
93
+ return new Promise((resolveScan) => {
94
+ const artifactSha256 = createHash("sha256").update(readFileSync(file)).digest("hex");
95
+ const stream = createReadStream(file, { highWaterMark: 256 * 1024 });
96
+ let tail = "";
97
+ stream.on("data", (chunk) => {
98
+ const text = tail + chunk.toString("latin1");
99
+ for (const [ruleId, rule, message] of contentRules) {
100
+ if (/ffmpeg-LICENSE\.txt$/i.test(file) && ruleId === "gpl-flag") continue;
101
+ rule.lastIndex = 0;
102
+ for (const match of text.matchAll(rule)) {
103
+ const allowed = allowances.some((allowance) =>
104
+ allowance.rule === ruleId &&
105
+ allowance.artifactSha256 === artifactSha256 &&
106
+ allowance.exact === match[0] &&
107
+ typeof allowance.sourceEvidence === "string" &&
108
+ typeof allowance.rationale === "string"
109
+ );
110
+ if (!allowed) add("content", file, message, rule.source);
111
+ }
112
+ }
113
+ tail = text.slice(-maxPatternLen);
114
+ });
115
+ stream.on("error", (error) => {
116
+ add("read", file, "could not scan file", error.message);
117
+ resolveScan();
118
+ });
119
+ stream.on("end", resolveScan);
120
+ });
121
+ }
122
+
123
+ for (const arg of args) {
124
+ const target = path.resolve(arg);
125
+ try {
126
+ await walk(target);
127
+ } catch (error) {
128
+ add("target", target, "could not scan target", error.message);
129
+ }
130
+ }
131
+
132
+ const unique = new Map();
133
+ for (const finding of findings) unique.set([finding.kind, finding.file, finding.message].join("\0"), finding);
134
+ const deduped = [...unique.values()].sort((left, right) =>
135
+ (left.file + " " + left.message).localeCompare(right.file + " " + right.message),
136
+ );
137
+
138
+ if (deduped.length) {
139
+ console.error("hardeningscan: " + deduped.length + " finding(s)");
140
+ for (const finding of deduped) console.error("- [" + finding.kind + "] " + finding.file + ": " + finding.message);
141
+ process.exit(1);
142
+ }
143
+
144
+ console.log("hardeningscan: clean");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rightkit/release",
3
- "version": "0.2.80",
3
+ "version": "0.2.81",
4
4
  "description": "Portable Right Suite release CLI/SDK: signed native archives, direct bootstrap transactions, immutable GitHub Release upload, R2 bootstrap publication, and add-on adoption.",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "type": "module",
@@ -22,7 +22,7 @@
22
22
  "@rightkit/logs": "0.1.4",
23
23
  "@rightkit/platform-ui": "0.1.1",
24
24
  "@rightkit/qa": "0.2.1",
25
- "@rightkit/release": "0.2.80",
25
+ "@rightkit/release": "0.2.81",
26
26
  "@rightkit/tauri": "0.1.1",
27
27
  "@rightkit/updates": "0.2.4"
28
28
  },