@peac/cli 0.14.1 → 0.14.3
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/dist/commands/bridge/start.d.ts.map +1 -1
- package/dist/commands/bridge/status.d.ts.map +1 -1
- package/dist/commands/bridge/stop.d.ts.map +1 -1
- package/dist/commands/bundle.d.ts.map +1 -1
- package/dist/commands/policy.d.ts.map +1 -1
- package/dist/commands/reconcile.d.ts.map +1 -1
- package/dist/commands/verify.d.ts.map +1 -1
- package/dist/index.cjs +96 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +97 -23
- package/dist/index.mjs.map +1 -1
- package/dist/lib/bridge-url.d.ts +25 -0
- package/dist/lib/bridge-url.d.ts.map +1 -0
- package/dist/lib/safe-file.d.ts +88 -0
- package/dist/lib/safe-file.d.ts.map +1 -0
- package/package.json +8 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/commands/bridge/start.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"start.d.ts","sourceRoot":"","sources":["../../../src/commands/bridge/start.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAcpC,wBAAgB,YAAY,YA+I3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/commands/bridge/status.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../../src/commands/bridge/status.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,aAAa,YAgM5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../src/commands/bridge/stop.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"stop.d.ts","sourceRoot":"","sources":["../../../src/commands/bridge/stop.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwCpC,wBAAgB,WAAW,YAiG1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/commands/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/commands/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAuGpC,QAAA,MAAM,MAAM,SAA4E,CAAC;AAkTzF,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/commands/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/commands/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6EpC,QAAA,MAAM,MAAM,SAIsC,CAAC;AA6tBnD,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../../src/commands/reconcile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"reconcile.d.ts","sourceRoot":"","sources":["../../src/commands/reconcile.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4OpC,wBAAgB,gBAAgB,IAAI,OAAO,CAuH1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/commands/verify.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/commands/verify.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAgB,MAAM,aAAa,CAAC;AAI3E,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,aAAa;IAClB,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;CAmDxF"}
|
package/dist/index.cjs
CHANGED
|
@@ -7,8 +7,8 @@ var crypto = require('@peac/crypto');
|
|
|
7
7
|
var fs6 = require('fs');
|
|
8
8
|
var path6 = require('path');
|
|
9
9
|
var policyKit = require('@peac/policy-kit');
|
|
10
|
-
var child_process = require('child_process');
|
|
11
10
|
var crypto$1 = require('crypto');
|
|
11
|
+
var child_process = require('child_process');
|
|
12
12
|
var schema = require('@peac/schema');
|
|
13
13
|
var kernel = require('@peac/kernel');
|
|
14
14
|
var audit = require('@peac/audit');
|
|
@@ -40,6 +40,55 @@ var fs6__namespace = /*#__PURE__*/_interopNamespace(fs6);
|
|
|
40
40
|
var path6__namespace = /*#__PURE__*/_interopNamespace(path6);
|
|
41
41
|
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
42
42
|
|
|
43
|
+
function readFileBufferSnapshot(path9, options) {
|
|
44
|
+
let fd;
|
|
45
|
+
try {
|
|
46
|
+
fd = fs6.openSync(path9, fs6.constants.O_RDONLY);
|
|
47
|
+
const stat = fs6.fstatSync(fd);
|
|
48
|
+
if (stat.isDirectory()) {
|
|
49
|
+
throw makeErrnoError("EISDIR", `is a directory: ${path9}`);
|
|
50
|
+
}
|
|
51
|
+
if (options?.maxBytes !== void 0 && stat.size > options.maxBytes) {
|
|
52
|
+
throw makeFileTooLargeError(path9, stat.size, options.maxBytes);
|
|
53
|
+
}
|
|
54
|
+
const data = fs6.readFileSync(fd);
|
|
55
|
+
if (options?.maxBytes !== void 0 && data.length > options.maxBytes) {
|
|
56
|
+
throw makeFileTooLargeError(path9, data.length, options.maxBytes);
|
|
57
|
+
}
|
|
58
|
+
return data;
|
|
59
|
+
} finally {
|
|
60
|
+
if (fd !== void 0) {
|
|
61
|
+
try {
|
|
62
|
+
fs6.closeSync(fd);
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function makeFileTooLargeError(path9, actualSize, maxBytes) {
|
|
69
|
+
const err = new Error(
|
|
70
|
+
`file size ${actualSize} bytes exceeds limit ${maxBytes} bytes: ${path9}`
|
|
71
|
+
);
|
|
72
|
+
err.code = "E_PEAC_FILE_TOO_LARGE";
|
|
73
|
+
err.actualSize = actualSize;
|
|
74
|
+
err.maxBytes = maxBytes;
|
|
75
|
+
return err;
|
|
76
|
+
}
|
|
77
|
+
function writeFileNoOverwrite(path9, data, options) {
|
|
78
|
+
const encoding = typeof data === "string" ? options?.encoding : null;
|
|
79
|
+
fs6.writeFileSync(path9, data, {
|
|
80
|
+
encoding,
|
|
81
|
+
flag: "wx",
|
|
82
|
+
mode: options?.mode
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
function makeErrnoError(code, message) {
|
|
86
|
+
const err = new Error(message);
|
|
87
|
+
err.code = code;
|
|
88
|
+
return err;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/commands/policy.ts
|
|
43
92
|
function getGlobalOptions(cmd) {
|
|
44
93
|
const parent = cmd.parent;
|
|
45
94
|
if (!parent) return {};
|
|
@@ -64,14 +113,6 @@ policy.command("init").description("Create a new PEAC policy file").option("-f,
|
|
|
64
113
|
try {
|
|
65
114
|
const format = options.format?.toLowerCase() || "yaml";
|
|
66
115
|
const outputPath = options.output || (format === "json" ? "peac-policy.json" : "peac-policy.yaml");
|
|
67
|
-
if (fs6__namespace.existsSync(outputPath) && !options.force && !globalOpts.yes) {
|
|
68
|
-
outputError(
|
|
69
|
-
`File already exists: ${outputPath}`,
|
|
70
|
-
{ path: outputPath, hint: "Use --force or --yes to overwrite" },
|
|
71
|
-
globalOpts
|
|
72
|
-
);
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
116
|
let content;
|
|
76
117
|
let policyName;
|
|
77
118
|
if (options.profile) {
|
|
@@ -92,7 +133,24 @@ policy.command("init").description("Create a new PEAC policy file").option("-f,
|
|
|
92
133
|
content = format === "json" ? policyKit.serializePolicyJson(example) : policyKit.serializePolicyYaml(example);
|
|
93
134
|
policyName = "Example Policy";
|
|
94
135
|
}
|
|
95
|
-
|
|
136
|
+
const allowOverwrite = options.force === true || globalOpts.yes === true;
|
|
137
|
+
try {
|
|
138
|
+
if (allowOverwrite) {
|
|
139
|
+
fs6__namespace.writeFileSync(outputPath, content, { encoding: "utf-8", flag: "w" });
|
|
140
|
+
} else {
|
|
141
|
+
writeFileNoOverwrite(outputPath, content, { encoding: "utf-8" });
|
|
142
|
+
}
|
|
143
|
+
} catch (err) {
|
|
144
|
+
if (err.code === "EEXIST") {
|
|
145
|
+
outputError(
|
|
146
|
+
`File already exists: ${outputPath}`,
|
|
147
|
+
{ path: outputPath, hint: "Use --force or --yes to overwrite" },
|
|
148
|
+
globalOpts
|
|
149
|
+
);
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
throw err;
|
|
153
|
+
}
|
|
96
154
|
if (globalOpts.json) {
|
|
97
155
|
output(
|
|
98
156
|
{
|
|
@@ -508,7 +566,6 @@ policy.command("show-profile").description("Show details of a specific policy pr
|
|
|
508
566
|
const globalOpts = getGlobalOptions(cmd);
|
|
509
567
|
try {
|
|
510
568
|
const profile = policyKit.loadProfile(id);
|
|
511
|
-
const summary = policyKit.getProfileSummary(id);
|
|
512
569
|
if (globalOpts.json) {
|
|
513
570
|
output(
|
|
514
571
|
{
|
|
@@ -2383,20 +2440,37 @@ function findDiffFields(jwsA, jwsB) {
|
|
|
2383
2440
|
return diffs.sort();
|
|
2384
2441
|
}
|
|
2385
2442
|
async function readBundle(bundlePath, label) {
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2443
|
+
let resolved;
|
|
2444
|
+
try {
|
|
2445
|
+
resolved = fs6__namespace.realpathSync(bundlePath);
|
|
2446
|
+
} catch (err) {
|
|
2447
|
+
if (err.code === "ENOENT") {
|
|
2448
|
+
return { ok: false, error: `Bundle file not found: ${bundlePath}` };
|
|
2449
|
+
}
|
|
2450
|
+
return { ok: false, error: `Failed to read ${label}: ${err.message}` };
|
|
2392
2451
|
}
|
|
2393
|
-
const resolved = fs6__namespace.realpathSync(bundlePath);
|
|
2394
2452
|
if (resolved !== bundlePath && !resolved.startsWith(process.cwd())) {
|
|
2395
|
-
|
|
2396
|
-
|
|
2453
|
+
return { ok: false, error: `Path traversal detected for ${label}` };
|
|
2454
|
+
}
|
|
2455
|
+
let zipBuffer;
|
|
2456
|
+
try {
|
|
2457
|
+
zipBuffer = readFileBufferSnapshot(bundlePath, { maxBytes: MAX_BUNDLE_SIZE });
|
|
2458
|
+
} catch (err) {
|
|
2459
|
+
const e = err;
|
|
2460
|
+
if (e.code === "ENOENT") {
|
|
2461
|
+
return { ok: false, error: `Bundle file not found: ${bundlePath}` };
|
|
2462
|
+
}
|
|
2463
|
+
if (e.code === "EISDIR") {
|
|
2464
|
+
return { ok: false, error: `Bundle ${label} is not a regular file: ${bundlePath}` };
|
|
2397
2465
|
}
|
|
2466
|
+
if (e.code === "E_PEAC_FILE_TOO_LARGE") {
|
|
2467
|
+
return {
|
|
2468
|
+
ok: false,
|
|
2469
|
+
error: `Bundle ${label} exceeds 16 MB size limit (${e.actualSize ?? "unknown"} bytes)`
|
|
2470
|
+
};
|
|
2471
|
+
}
|
|
2472
|
+
return { ok: false, error: `Failed to read ${label}: ${err.message}` };
|
|
2398
2473
|
}
|
|
2399
|
-
const zipBuffer = fs6__namespace.readFileSync(bundlePath);
|
|
2400
2474
|
const result = await audit.readDisputeBundle(zipBuffer);
|
|
2401
2475
|
if (!result.ok) {
|
|
2402
2476
|
return { ok: false, error: `Failed to read ${label}: ${result.error.message}` };
|
|
@@ -4755,7 +4829,7 @@ program.command("verify").description("Verify a PEAC receipt JWS").argument("<jw
|
|
|
4755
4829
|
jws = fs6__namespace.readFileSync(jwsInput, "utf-8").trim();
|
|
4756
4830
|
}
|
|
4757
4831
|
console.log("Verifying PEAC receipt...\n");
|
|
4758
|
-
const {
|
|
4832
|
+
const { payload } = crypto.decode(jws);
|
|
4759
4833
|
console.log("Receipt Information:");
|
|
4760
4834
|
console.log(` Receipt ID: ${payload.rid}`);
|
|
4761
4835
|
console.log(` Issuer: ${payload.iss}`);
|