@volter/teams 0.2.42 → 0.2.44
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/redact.mjs +26 -15
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volter/teams",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
|
|
6
6
|
"license": "MIT",
|
package/redact.mjs
CHANGED
|
@@ -134,23 +134,29 @@ const anyKeyword = new RegExp([...new Set(RULES.flatMap((rule) => rule.keywords)
|
|
|
134
134
|
const CUSTODY_LOOK_MS = 30_000;
|
|
135
135
|
let custodyCache = null, custodyStamp = null, custodyLookedAt = 0;
|
|
136
136
|
const stampOf = (file) => { try { const s = statSync(file); return `${s.ino}:${s.size}:${s.mtimeMs}`; } catch { return '-'; } };
|
|
137
|
-
|
|
137
|
+
const custodyUnreadable=()=>Object.assign(new Error('a declared custody file or its registry could not be read; capture transfer refused'),{code:'custody_unreadable'});
|
|
138
|
+
function custodyFiles(env, fresh) {
|
|
138
139
|
const home = env.SUPERCODE_HOME || join(env.XDG_CONFIG_HOME || join(homedir(), '.config'), 'supercode');
|
|
139
140
|
let files = String(env.SUPERCODE_CUSTODY_FILES ?? '').split(delimiter).filter(Boolean);
|
|
140
|
-
try {
|
|
141
|
+
try {
|
|
142
|
+
const named=JSON.parse(readFileSync(join(home, 'custody.json'), 'utf8')).files??[];
|
|
143
|
+
if(fresh&&(!Array.isArray(named)||named.some(file=>typeof file!=='string')))throw custodyUnreadable();
|
|
144
|
+
files=files.concat(named);
|
|
145
|
+
} catch(error) { if(fresh&&error?.code!=='ENOENT')throw custodyUnreadable(); }
|
|
141
146
|
return { files, stamp: [join(home, 'custody.json'), ...files].map(stampOf).join('|') };
|
|
142
147
|
}
|
|
143
|
-
/** Each custody value (at least 8 characters) with the variable that holds it, longest first.
|
|
144
|
-
|
|
148
|
+
/** Each custody value (at least 8 characters) with the variable that holds it, longest first. `fresh` bypasses both
|
|
149
|
+
* the interval and stat memo and refuses unreadable declared files or a malformed/unreadable registry. */
|
|
150
|
+
export function custodyValues(env = process.env, { fresh = false } = {}) {
|
|
145
151
|
const now = Date.now();
|
|
146
|
-
if (custodyCache && now - custodyLookedAt < CUSTODY_LOOK_MS) return custodyCache;
|
|
152
|
+
if (!fresh && custodyCache && now - custodyLookedAt < CUSTODY_LOOK_MS) return custodyCache;
|
|
147
153
|
custodyLookedAt = now;
|
|
148
|
-
const { files, stamp } = custodyFiles(env);
|
|
149
|
-
if (custodyCache && stamp === custodyStamp) return custodyCache;
|
|
154
|
+
const { files, stamp } = custodyFiles(env, fresh);
|
|
155
|
+
if (!fresh && custodyCache && stamp === custodyStamp) return custodyCache;
|
|
150
156
|
custodyStamp = stamp;
|
|
151
157
|
const values = new Map();
|
|
152
158
|
for (const file of files) {
|
|
153
|
-
let text = ''; try { if (existsSync(file)) text = readFileSync(file, 'utf8'); } catch { continue; }
|
|
159
|
+
let text = ''; try { if (fresh||existsSync(file)) text = readFileSync(file, 'utf8'); } catch { if(fresh)throw custodyUnreadable();continue; }
|
|
154
160
|
for (const line of text.split('\n')) {
|
|
155
161
|
const m = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
|
|
156
162
|
if (!m) continue;
|
|
@@ -169,7 +175,12 @@ export function custodyValues(env = process.env) {
|
|
|
169
175
|
let custodyBasis = null;
|
|
170
176
|
/** What a redaction was made under (the rule set and the custody values), as a digest: text found clean under one
|
|
171
177
|
* basis is clean under it again, and needs another look only when it changes. */
|
|
172
|
-
export function redactionBasis(env = process.env) { custodyValues(env); return custodyBasis; }
|
|
178
|
+
export function redactionBasis(env = process.env, options) { custodyValues(env, options); return custodyBasis; }
|
|
179
|
+
/** One custody observation and its basis, for a batch that must not change policy between its values. */
|
|
180
|
+
export function redactionSnapshot(env = process.env, options) {
|
|
181
|
+
const values = custodyValues(env, options);
|
|
182
|
+
return { values, basis: custodyBasis };
|
|
183
|
+
}
|
|
173
184
|
|
|
174
185
|
// Text this far either side of a keyword is searched by a bounded rule, beyond its longest match.
|
|
175
186
|
const WINDOW_MARGIN = 256;
|
|
@@ -184,12 +195,12 @@ function keywordSpans(hits, length, keywords, reach) {
|
|
|
184
195
|
}
|
|
185
196
|
|
|
186
197
|
/** `text` with every secret replaced by its marker. */
|
|
187
|
-
export function redactText(text, env = process.env) {
|
|
198
|
+
export function redactText(text, env = process.env, custody) {
|
|
188
199
|
if (typeof text !== 'string' || text.length < 8) return text;
|
|
189
200
|
let out = text;
|
|
190
201
|
// Custody values are random, so one alternation of them gives the regex engine nothing to skip on: each is looked
|
|
191
202
|
// for on its own, which reads a 5 MB text in a few dozen milliseconds.
|
|
192
|
-
for (const { value, name } of custodyValues(env)) if (out.includes(value)) out = out.split(value).join(`[redacted:${name}]`);
|
|
203
|
+
for (const { value, name } of custody ?? custodyValues(env)) if (out.includes(value)) out = out.split(value).join(`[redacted:${name}]`);
|
|
193
204
|
if (/(?:sct|sci|sca|sat|whsec)_/.test(out)) out = out.replace(TEAM_TOKENS, (_, kind, hook) => `[redacted:teams-${kind ?? hook}-token]`);
|
|
194
205
|
// Every rule has keywords, so a text holding none of them is done (the one test is cheap; finding where each keyword
|
|
195
206
|
// occurs is not, and most texts are short and hold none).
|
|
@@ -220,9 +231,9 @@ export function redactText(text, env = process.env) {
|
|
|
220
231
|
}
|
|
221
232
|
|
|
222
233
|
/** A JSON value with every string in it redacted (keys kept). */
|
|
223
|
-
export function redactValue(value, env = process.env) {
|
|
224
|
-
if (typeof value === 'string') return redactText(value, env);
|
|
225
|
-
if (Array.isArray(value)) return value.map((item) => redactValue(item, env));
|
|
226
|
-
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactValue(item, env)]));
|
|
234
|
+
export function redactValue(value, env = process.env, custody) {
|
|
235
|
+
if (typeof value === 'string') return redactText(value, env, custody);
|
|
236
|
+
if (Array.isArray(value)) return value.map((item) => redactValue(item, env, custody));
|
|
237
|
+
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, redactValue(item, env, custody)]));
|
|
227
238
|
return value;
|
|
228
239
|
}
|