prae-cli 0.3.0 → 0.5.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 +16 -0
- package/lib/bin.js +4 -3
- package/lib/{cli-DZ0FPdSr.js → cli-ZfwhJKRw.js} +167 -432
- package/lib/evaluate-BilZez15.js +419 -0
- package/lib/index.js +4 -3
- package/lib/{instructions-C6jwClPO.js → instructions-D4VOn2lk.js} +1 -1
- package/lib/mcp-BH5I4Eyu.js +208 -0
- package/lib/playground.js +38 -1
- package/lib/receipt-check-Dql0uqxw.js +39 -0
- package/lib/secret-catcher.prae.json +49 -0
- package/lib/src-Br1tGPtS.js +182 -0
- package/lib/{src-DGWTvmRZ.js → src-CXU0_W1P.js} +18 -1
- package/lib/src-Kubj3MTX.js +3 -0
- package/lib/src-Vnr0fcpK.js +3 -0
- package/package.json +3 -1
- package/lib/src-Cinsv7Wq.js +0 -3
- /package/lib/{src-CuHszf3f.js → src-BfYsUDW9.js} +0 -0
- /package/lib/{src-2pGbYeGU.js → src-C4fnUm9V.js} +0 -0
- /package/lib/{views-CLLfJPWB.js → views-DalPkBZZ.js} +0 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { c as verifyReceipt, i as fingerprint } from "./src-CXU0_W1P.js";
|
|
2
|
+
|
|
3
|
+
//#region src/receipt-check.ts
|
|
4
|
+
/** Shape we require before we will call it a receipt at all. */
|
|
5
|
+
function looksLikeReceipt(value) {
|
|
6
|
+
if (typeof value !== "object" || value === null) return false;
|
|
7
|
+
const r = value;
|
|
8
|
+
return typeof r.signature === "string" && typeof r.publicKey === "string" && typeof r.entry === "object" && r.entry !== null;
|
|
9
|
+
}
|
|
10
|
+
function checkReceipt(parsed) {
|
|
11
|
+
if (!looksLikeReceipt(parsed)) return {
|
|
12
|
+
ok: false,
|
|
13
|
+
lines: ["✗ not a receipt: expected `entry`, `signature` and `publicKey` fields"]
|
|
14
|
+
};
|
|
15
|
+
const result = verifyReceipt(parsed);
|
|
16
|
+
if (!result.ok) return {
|
|
17
|
+
ok: false,
|
|
18
|
+
lines: [`✗ receipt does NOT verify: ${result.reason}`]
|
|
19
|
+
};
|
|
20
|
+
const { verdict, tool, rule, subject } = parsed.entry;
|
|
21
|
+
return {
|
|
22
|
+
ok: true,
|
|
23
|
+
lines: [
|
|
24
|
+
"✓ receipt verifies — authentic and unaltered",
|
|
25
|
+
` ${[
|
|
26
|
+
verdict,
|
|
27
|
+
tool,
|
|
28
|
+
rule === void 0 ? void 0 : `· ${rule}`,
|
|
29
|
+
subject === void 0 ? void 0 : `· ${subject}`
|
|
30
|
+
].filter((part) => part !== void 0).join(" ")}`,
|
|
31
|
+
` sealed by key ${fingerprint(parsed.publicKey)}`,
|
|
32
|
+
" Compare that fingerprint to the one you pinned out of band.",
|
|
33
|
+
" It matches → this is a decision that key’s holder sealed, unchanged."
|
|
34
|
+
]
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { checkReceipt };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"prae": "0.1",
|
|
3
|
+
"pack": "secret-catcher",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"rules": [
|
|
6
|
+
{
|
|
7
|
+
"id": "SEC-001",
|
|
8
|
+
"title": "Reads carrying credentials are refused",
|
|
9
|
+
"when": {
|
|
10
|
+
"capability": "fs:read",
|
|
11
|
+
"path": {
|
|
12
|
+
"outside": [
|
|
13
|
+
"./**/test/**",
|
|
14
|
+
"./**/tests/**",
|
|
15
|
+
"./**/fixtures/**",
|
|
16
|
+
"./**/*.example",
|
|
17
|
+
"./**/*.sample"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"secrets": { "minConfidence": 0.8 }
|
|
21
|
+
},
|
|
22
|
+
"effect": {
|
|
23
|
+
"kind": "deny",
|
|
24
|
+
"because": "the requested file contains a protected credential; the contents were not returned"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"id": "SEC-002",
|
|
29
|
+
"title": "Private keys are refused everywhere",
|
|
30
|
+
"when": {
|
|
31
|
+
"capability": "fs:read",
|
|
32
|
+
"secrets": { "types": ["private-key"] }
|
|
33
|
+
},
|
|
34
|
+
"effect": {
|
|
35
|
+
"kind": "deny",
|
|
36
|
+
"because": "the requested file contains a private key; the contents were not returned"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "SEC-003",
|
|
41
|
+
"title": "Anything credential-shaped is at least recorded",
|
|
42
|
+
"when": { "capability": "fs:read", "secrets": { "minConfidence": 0.5 } },
|
|
43
|
+
"effect": {
|
|
44
|
+
"kind": "warn",
|
|
45
|
+
"because": "a possible credential was noticed in this file; where no stronger rule fired, the read proceeded and this row is the record"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
//#region ../inspect/src/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* The built-in detectors.
|
|
4
|
+
*
|
|
5
|
+
* Anchored provider formats first — those prefixes exist precisely so that
|
|
6
|
+
* scanners can find them, and they carry the confidence to prove it. The
|
|
7
|
+
* loose assignment patterns at the bottom earn their keep only with an
|
|
8
|
+
* entropy check, because `password = "password"` is not a leak, it is a test.
|
|
9
|
+
*/
|
|
10
|
+
const DETECTORS = [
|
|
11
|
+
{
|
|
12
|
+
rule: "private-key",
|
|
13
|
+
type: "private-key",
|
|
14
|
+
pattern: /-----BEGIN (?:RSA |EC |DSA |OPENSSH |PGP |ENCRYPTED )?PRIVATE KEY(?: BLOCK)?-----/g,
|
|
15
|
+
confidence: .99
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
rule: "aws-access-key-id",
|
|
19
|
+
type: "cloud-credential",
|
|
20
|
+
pattern: /\b(?:AKIA|ASIA|ABIA|ACCA)[A-Z0-9]{16}\b/g,
|
|
21
|
+
confidence: .9
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
rule: "github-token",
|
|
25
|
+
type: "token",
|
|
26
|
+
pattern: /\b(?:gh[poasur]_[A-Za-z0-9]{36,251}|github_pat_[A-Za-z0-9_]{22,255})\b/g,
|
|
27
|
+
confidence: .95
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
rule: "gitlab-token",
|
|
31
|
+
type: "token",
|
|
32
|
+
pattern: /\bglpat-[A-Za-z0-9_-]{20,}\b/g,
|
|
33
|
+
confidence: .95
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
rule: "slack-token",
|
|
37
|
+
type: "token",
|
|
38
|
+
pattern: /\bxox[baprs]-[A-Za-z0-9-]{10,}\b/g,
|
|
39
|
+
confidence: .9
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
rule: "stripe-live-key",
|
|
43
|
+
type: "api-key",
|
|
44
|
+
pattern: /\b[sr]k_live_[A-Za-z0-9]{16,}\b/g,
|
|
45
|
+
confidence: .95
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
rule: "google-api-key",
|
|
49
|
+
type: "api-key",
|
|
50
|
+
pattern: /\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
51
|
+
confidence: .9
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
rule: "anthropic-key",
|
|
55
|
+
type: "api-key",
|
|
56
|
+
pattern: /\bsk-ant-[A-Za-z0-9-]{32,}\b/g,
|
|
57
|
+
confidence: .95
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
rule: "openai-key",
|
|
61
|
+
type: "api-key",
|
|
62
|
+
pattern: /\bsk-(?:proj-)?[A-Za-z0-9_-]{32,}\b/g,
|
|
63
|
+
confidence: .8
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
rule: "npm-token",
|
|
67
|
+
type: "token",
|
|
68
|
+
pattern: /\bnpm_[A-Za-z0-9]{36}\b/g,
|
|
69
|
+
confidence: .95
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
rule: "credential-in-url",
|
|
73
|
+
type: "credential-in-url",
|
|
74
|
+
pattern: /\b(?:postgres(?:ql)?|mysql|mongodb(?:\+srv)?|redis|amqps?|ftp):\/\/[^:\s/@'"]+:[^@\s/'"]+@/g,
|
|
75
|
+
confidence: .85
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
rule: "jwt",
|
|
79
|
+
type: "token",
|
|
80
|
+
pattern: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{5,}\b/g,
|
|
81
|
+
confidence: .6
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
rule: "password-assignment",
|
|
85
|
+
type: "password",
|
|
86
|
+
pattern: /\b(?:password|passwd|pwd)\b\s*[:=]\s*['"]([^'"\s]{6,})['"]/gi,
|
|
87
|
+
confidence: .5,
|
|
88
|
+
minEntropy: 3
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
rule: "secret-assignment",
|
|
92
|
+
type: "generic-secret",
|
|
93
|
+
pattern: /\b(?:secret|token|api[_-]?key|auth[_-]?token|access[_-]?key)\b\w*\s*[:=]\s*['"]([A-Za-z0-9/+_=-]{20,})['"]/gi,
|
|
94
|
+
confidence: .6,
|
|
95
|
+
minEntropy: 3.5
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
/**
|
|
99
|
+
* Markers of a value that exists to be seen.
|
|
100
|
+
*
|
|
101
|
+
* A finding whose match carries one of these is dropped, not down-scored:
|
|
102
|
+
* `AKIAIOSFODNN7EXAMPLE` is in more documentation than any real key is in
|
|
103
|
+
* code, and a gate that denies the README teaches operators to turn it off.
|
|
104
|
+
* The AWS docs key is listed literally because it does not say "example"
|
|
105
|
+
* anywhere a case-insensitive substring would find. Real secrets do not
|
|
106
|
+
* contain these words; a placeholder that does is doing its job.
|
|
107
|
+
*/
|
|
108
|
+
const PLACEHOLDER = /example|changeme|change-me|placeholder|your[_-]|xxxx|dummy|sample|redacted|<[a-z_-]+>|AKIAIOSFODNN7/i;
|
|
109
|
+
/** Shannon entropy in bits per character. */
|
|
110
|
+
function entropy(text) {
|
|
111
|
+
if (text.length === 0) return 0;
|
|
112
|
+
const counts = /* @__PURE__ */ new Map();
|
|
113
|
+
for (const ch of text) counts.set(ch, (counts.get(ch) ?? 0) + 1);
|
|
114
|
+
let sum = 0;
|
|
115
|
+
for (const n of counts.values()) {
|
|
116
|
+
const p = n / text.length;
|
|
117
|
+
sum -= p * Math.log2(p);
|
|
118
|
+
}
|
|
119
|
+
return sum;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Content larger than this is not scanned — the caller is told, not silently
|
|
123
|
+
* covered. Regex over an unbounded file in the hot path of every read is how
|
|
124
|
+
* a gate becomes an outage; 2 MiB covers any file a secret plausibly lives in.
|
|
125
|
+
*/
|
|
126
|
+
const MAX_SCAN_BYTES = 2 * 1024 * 1024;
|
|
127
|
+
/** NUL in the first 8 KiB: binary, not text. Scanned as nothing. */
|
|
128
|
+
function looksBinary(content) {
|
|
129
|
+
return content.slice(0, 8192).includes("\0");
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Scan text for secrets. Findings in document order, deduplicated by span —
|
|
133
|
+
* when two rules claim the same region, the higher confidence keeps it.
|
|
134
|
+
*/
|
|
135
|
+
function scan(content, options = {}) {
|
|
136
|
+
if (looksBinary(content)) return [];
|
|
137
|
+
const detectors = options.detectors ?? DETECTORS;
|
|
138
|
+
const floor = options.minConfidence ?? 0;
|
|
139
|
+
const starts = [0];
|
|
140
|
+
for (let i = 0; i < content.length; i++) if (content[i] === "\n") starts.push(i + 1);
|
|
141
|
+
const position = (offset) => {
|
|
142
|
+
let low = 0;
|
|
143
|
+
let high = starts.length - 1;
|
|
144
|
+
while (low < high) {
|
|
145
|
+
const mid = low + high + 1 >> 1;
|
|
146
|
+
if (starts[mid] <= offset) low = mid;
|
|
147
|
+
else high = mid - 1;
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
line: low + 1,
|
|
151
|
+
column: offset - starts[low] + 1
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
const bySpan = /* @__PURE__ */ new Map();
|
|
155
|
+
for (const detector of detectors) {
|
|
156
|
+
const pattern = new RegExp(detector.pattern.source, detector.pattern.flags);
|
|
157
|
+
for (const match of content.matchAll(pattern)) {
|
|
158
|
+
const text = match[0];
|
|
159
|
+
if (PLACEHOLDER.test(text)) continue;
|
|
160
|
+
if (detector.minEntropy !== void 0) {
|
|
161
|
+
if (entropy(match[1] ?? text) < detector.minEntropy) continue;
|
|
162
|
+
}
|
|
163
|
+
if (detector.confidence < floor) continue;
|
|
164
|
+
const key = `${match.index}:${text.length}`;
|
|
165
|
+
const standing = bySpan.get(key);
|
|
166
|
+
if (standing !== void 0 && standing.confidence >= detector.confidence) continue;
|
|
167
|
+
const { line, column } = position(match.index);
|
|
168
|
+
bySpan.set(key, {
|
|
169
|
+
rule: detector.rule,
|
|
170
|
+
type: detector.type,
|
|
171
|
+
line,
|
|
172
|
+
column,
|
|
173
|
+
length: text.length,
|
|
174
|
+
confidence: detector.confidence
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return [...bySpan.values()].sort((a, b) => a.line - b.line || a.column - b.column);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
export { scan as a, looksBinary as i, MAX_SCAN_BYTES as n, entropy as r, DETECTORS as t };
|
|
@@ -76,6 +76,23 @@ function makeReceipt(entry, privateKeyPem, publicKeyPem) {
|
|
|
76
76
|
publicKey: publicKeyPem
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
+
/** Verify a receipt from nothing but the receipt. */
|
|
80
|
+
function verifyReceipt(receipt) {
|
|
81
|
+
if (receipt.receipt !== "prae/1") return {
|
|
82
|
+
ok: false,
|
|
83
|
+
reason: `unknown receipt format ${String(receipt.receipt)}`
|
|
84
|
+
};
|
|
85
|
+
const { seq, prev, hash, sig,...record } = receipt.entry;
|
|
86
|
+
if (hashEntry(record, seq, prev) !== hash) return {
|
|
87
|
+
ok: false,
|
|
88
|
+
reason: "entry contents do not match their seal; the row was altered"
|
|
89
|
+
};
|
|
90
|
+
if (!verifySignature(receipt.entry, receipt.signature, receipt.publicKey)) return {
|
|
91
|
+
ok: false,
|
|
92
|
+
reason: "signature does not verify; not sealed by this key"
|
|
93
|
+
};
|
|
94
|
+
return { ok: true };
|
|
95
|
+
}
|
|
79
96
|
/**
|
|
80
97
|
* A short identifier for a public key, for pinning by eye.
|
|
81
98
|
*
|
|
@@ -222,4 +239,4 @@ var Ledger = class Ledger {
|
|
|
222
239
|
};
|
|
223
240
|
|
|
224
241
|
//#endregion
|
|
225
|
-
export { generateKeypair as a,
|
|
242
|
+
export { generateKeypair as a, verifyReceipt as c, canonical as d, chain as f, fingerprint as i, verifySignature as l, seal as m, readEntries as n, makeReceipt as o, hashEntry as p, verifyEntries as r, signEntry as s, Ledger as t, GENESIS as u };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as generateKeypair, c as verifyReceipt, d as canonical, f as chain, i as fingerprint, l as verifySignature, m as seal, n as readEntries, o as makeReceipt, p as hashEntry, r as verifyEntries, s as signEntry, t as Ledger, u as GENESIS } from "./src-CXU0_W1P.js";
|
|
2
|
+
|
|
3
|
+
export { GENESIS, Ledger, canonical, chain, fingerprint, generateKeypair, hashEntry, makeReceipt, readEntries, seal, signEntry, verifyEntries, verifyReceipt, verifySignature };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prae-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Operator policy for agent harnesses: validate packs, explain a decision, verify a decision log, and provision a governed DSH profile.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dsh-plugin",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"node": ">=20"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
34
35
|
"capmark": "^0.3.1",
|
|
35
36
|
"dsh-overlay-check": "^0.4.0"
|
|
36
37
|
},
|
|
@@ -41,6 +42,7 @@
|
|
|
41
42
|
"vitest": "^3.2.4",
|
|
42
43
|
"@prae/controls": "0.1.0",
|
|
43
44
|
"@prae/extract": "0.1.0",
|
|
45
|
+
"@prae/inspect": "0.1.0",
|
|
44
46
|
"@prae/instructions": "0.1.0",
|
|
45
47
|
"@prae/kernel": "0.1.0",
|
|
46
48
|
"@prae/ledger": "0.1.0",
|
package/lib/src-Cinsv7Wq.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { a as generateKeypair, c as verifySignature, d as chain, f as hashEntry, i as fingerprint, l as GENESIS, n as readEntries, o as makeReceipt, p as seal, r as verifyEntries, s as signEntry, t as Ledger, u as canonical } from "./src-DGWTvmRZ.js";
|
|
2
|
-
|
|
3
|
-
export { GENESIS, Ledger, canonical, chain, fingerprint, generateKeypair, hashEntry, makeReceipt, readEntries, seal, signEntry, verifyEntries, verifySignature };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|