opencode-self-improvement 0.15.31 → 0.15.33
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/package.json +1 -1
- package/src/store/secrets.ts +53 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-self-improvement",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.33",
|
|
4
4
|
"description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"exports": {
|
package/src/store/secrets.ts
CHANGED
|
@@ -4,8 +4,58 @@
|
|
|
4
4
|
// named field and they look high-entropy, so ordinary identifiers survive.
|
|
5
5
|
export const REDACTED_SECRET = "[redacted]";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// PEM redaction is a linear marker-pair scan, not one lazy regex. The old
|
|
8
|
+
// /-----BEGIN...[\s\S]*?-----END.../g re-scanned to end-of-input at every
|
|
9
|
+
// unmatched BEGIN, so a large tool output of repeated BEGIN lines with no END
|
|
10
|
+
// line stalled the hook for seconds per megabyte (#290). The marker regexes
|
|
11
|
+
// below are anchored (sticky) and never span lines, so each probe is bounded.
|
|
12
|
+
const PRIVATE_KEY_BEGIN = "-----BEGIN";
|
|
13
|
+
const PRIVATE_KEY_END = "-----END";
|
|
14
|
+
const BEGIN_MARKER = /-----BEGIN(?: [A-Z0-9]+)* PRIVATE KEY-----/y;
|
|
15
|
+
const END_MARKER = /-----END(?: [A-Z0-9]+)* PRIVATE KEY-----/y;
|
|
16
|
+
|
|
17
|
+
function scanMarkers(
|
|
18
|
+
text: string,
|
|
19
|
+
probe: string,
|
|
20
|
+
marker: RegExp,
|
|
21
|
+
): Array<{ start: number; end: number }> {
|
|
22
|
+
const found: Array<{ start: number; end: number }> = [];
|
|
23
|
+
for (let i = text.indexOf(probe); i >= 0; i = text.indexOf(probe, i + 1)) {
|
|
24
|
+
marker.lastIndex = i;
|
|
25
|
+
const m = marker.exec(text);
|
|
26
|
+
if (m) found.push({ start: i, end: i + m[0].length });
|
|
27
|
+
}
|
|
28
|
+
return found;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Equivalent to the old global regex replace with REDACTED_SECRET: earliest
|
|
32
|
+
// BEGIN wins, the lazy quantifier pairs it with the earliest END at or after
|
|
33
|
+
// the BEGIN marker, matches never overlap, and an unmatched BEGIN stays.
|
|
34
|
+
function redactPrivateKeyBlocks(text: string): string {
|
|
35
|
+
const begins = scanMarkers(text, PRIVATE_KEY_BEGIN, BEGIN_MARKER);
|
|
36
|
+
if (begins.length === 0) return text;
|
|
37
|
+
const ends = scanMarkers(text, PRIVATE_KEY_END, END_MARKER);
|
|
38
|
+
if (ends.length === 0) return text;
|
|
39
|
+
let out = "";
|
|
40
|
+
let pos = 0;
|
|
41
|
+
for (const begin of begins) {
|
|
42
|
+
if (begin.start < pos) continue;
|
|
43
|
+
let lo = 0;
|
|
44
|
+
let hi = ends.length;
|
|
45
|
+
while (lo < hi) {
|
|
46
|
+
const mid = (lo + hi) >> 1;
|
|
47
|
+
if (ends[mid].start < begin.end) lo = mid + 1;
|
|
48
|
+
else hi = mid;
|
|
49
|
+
}
|
|
50
|
+
// No END at or after this BEGIN: this pair cannot match. A later BEGIN
|
|
51
|
+
// may still pair with an END inside this BEGIN's span, so keep going.
|
|
52
|
+
if (lo === ends.length) continue;
|
|
53
|
+
out += text.slice(pos, begin.start) + REDACTED_SECRET;
|
|
54
|
+
pos = ends[lo].end;
|
|
55
|
+
}
|
|
56
|
+
return pos === 0 ? text : out + text.slice(pos);
|
|
57
|
+
}
|
|
58
|
+
|
|
9
59
|
const PREFIXED_SECRET =
|
|
10
60
|
/\b(?:sk-[A-Za-z0-9_-]{16,}|gh[po]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|xox[bp]-[A-Za-z0-9-]{16,}|AKIA[A-Z0-9]{16}|AIza[A-Za-z0-9_-]{20,})\b/g;
|
|
11
61
|
// A real bearer token has digits; prose like "Bearer authentication-scheme" doesn't.
|
|
@@ -28,7 +78,7 @@ function looksHighEntropy(value: string): boolean {
|
|
|
28
78
|
|
|
29
79
|
export function redactSecrets(text: string): string {
|
|
30
80
|
if (!text) return text;
|
|
31
|
-
let out = text
|
|
81
|
+
let out = redactPrivateKeyBlocks(text);
|
|
32
82
|
out = out.replace(PREFIXED_SECRET, REDACTED_SECRET);
|
|
33
83
|
out = out.replace(BEARER_SECRET, REDACTED_SECRET);
|
|
34
84
|
return out.replace(ASSIGNED_SECRET, (match, prefix: string, value: string) =>
|