fix(model-proxy): settings-backend A1 review P3-1 and P3-3: a short Mosaic key glued to a word (xmso-..., _msk-...) is redacted by one added line after the copied key-prefix line, which the pin test now expects; a history entry whose redacted values, or keys and values, read together still hold an environment secret split across them is answered as { withheld: true }; comments name the split-key journal limit (P3-2) and the unmarked non-object answer (P3-9) (#1873, lane settings-backend-a1)

This commit was merged in pull request #2006.
This commit is contained in:
jason.woltje committed 2026-11-19 21:09:58 -06:00
1 parent db2dc96aa2
commit 37c3854849
5 files changed
+50 -7

No files matched your search

+15 -3
View File
@@ -149,10 +149,16 @@ export function recentReceipts(dataRoot, limit = 10) {
// Console's user, no group or other bits) and backward from `before` in 64 KB chunks. A partial // Console's user, no group or other bits) and backward from `before` in 64 KB chunks. A partial
// last line (a write in progress) waits for a later read; a line that does not parse, or is longer // last line (a write in progress) waits for a later read; a line that does not parse, or is longer
// than 64 KB, is skipped. Each entry is redacted (redact.mjs) before it is answered, so a receipt // than 64 KB, is skipped. Each entry is redacted (redact.mjs) before it is answered, so a receipt
// that ever held key text shows none. A missing file is an empty history; any other failure to // that ever held key text shows none. An entry whose redacted values read together, or whose keys
// read refuses outcome-unknown. `uid` is a test seam. // and values read together, still hold an environment secret split across them is answered as
// { withheld: true }; pieces kept apart by another whole field are not seen (known limit). A missing
// file is an empty history; any other failure to read refuses outcome-unknown. `uid` is a test seam.
export const HISTORY_LIMIT = Object.freeze({ min: 1, max: 100, default: 25 }); export const HISTORY_LIMIT = Object.freeze({ min: 1, max: 100, default: 25 });
const HISTORY_CHUNK = 65536, HISTORY_LINE_MAX = 65536, HISTORY_SCAN_MAX = 2000; const HISTORY_CHUNK = 65536, HISTORY_LINE_MAX = 65536, HISTORY_SCAN_MAX = 2000;
// A redacted entry's values joined in order, with each object key before its value when `keys`.
const entryText = (value, keys) => (value !== null && typeof value === 'object'
? Object.entries(value).map(([key, item]) => (keys && !Array.isArray(value) ? key : '') + entryText(item, keys)).join('')
: String(value));
export function receiptHistory(dataRoot, { limit = HISTORY_LIMIT.default, before = null, uid = process.getuid(), secrets = [] } = {}) { export function receiptHistory(dataRoot, { limit = HISTORY_LIMIT.default, before = null, uid = process.getuid(), secrets = [] } = {}) {
if (!Number.isSafeInteger(limit)) refuse('invalid-request'); if (!Number.isSafeInteger(limit)) refuse('invalid-request');
const n = Math.min(HISTORY_LIMIT.max, Math.max(HISTORY_LIMIT.min, limit)); const n = Math.min(HISTORY_LIMIT.max, Math.max(HISTORY_LIMIT.min, limit));
@@ -202,7 +208,11 @@ export function receiptHistory(dataRoot, { limit = HISTORY_LIMIT.default, before
if (lineEnd - lineStart <= HISTORY_LINE_MAX) { if (lineEnd - lineStart <= HISTORY_LINE_MAX) {
let value = null; let value = null;
try { value = JSON.parse(bytes(lineStart, lineEnd).toString('utf8')); } catch { /* torn line */ } try { value = JSON.parse(bytes(lineStart, lineEnd).toString('utf8')); } catch { /* torn line */ }
if (value && typeof value === 'object' && !Array.isArray(value) && typeof value.op === 'string') entries.push(redactValue(value, secrets)); if (value && typeof value === 'object' && !Array.isArray(value) && typeof value.op === 'string') {
const safe = redactValue(value, secrets);
const split = holdsSecret(entryText(safe, false), secrets) || holdsSecret(entryText(safe, true), secrets);
entries.push(split ? { withheld: true } : safe);
}
} }
cursor = lineStart; cursor = lineStart;
} }
@@ -255,6 +265,8 @@ export async function unitLog({ run = defaultRun, unit, lines = LOG_LINES.defaul
out.push(safe.text); out.push(safe.text);
} }
// The lines that will be shown, read together: a secret split across them drops them all. // The lines that will be shown, read together: a secret split across them drops them all.
// Only environment secrets are checked this way. A key pattern broken across two journal
// lines, each part too short for the long-run rules, is a known limit shared with chat-fail.
if (holdsSecret(out.join(''), secrets)) { dropped += out.length; out.length = 0; } if (holdsSecret(out.join(''), secrets)) { dropped += out.length; out.length = 0; }
} catch { refuse('outcome-unknown'); } } catch { refuse('outcome-unknown'); }
return { unit, lines: out, redacted, dropped }; return { unit, lines: out, redacted, dropped };
+6 -2
View File
@@ -3,7 +3,9 @@
// //
// It is the redaction chat-fail landed for a failed turn's cause (packages/harness/src/failure-notice.mjs, // It is the redaction chat-fail landed for a failed turn's cause (packages/harness/src/failure-notice.mjs,
// its REDACT list), with Mosaic's own key prefixes added to the key-prefix line: mso- (an organization's // its REDACT list), with Mosaic's own key prefixes added to the key-prefix line: mso- (an organization's
// model key), mst- (the Triage key) and msp-, beside msk- (the owner's). failure-notice.mjs does not // model key), mst- (the Triage key) and msp-, beside msk- (the owner's). One line is added after it:
// those four Mosaic prefixes with no word boundary, so a key glued to a word (xmso-...) is caught
// too. Over-redaction there is the safe side. failure-notice.mjs does not
// export its list, and packages/harness/ belongs to another lane now, so the list is copied here. // export its list, and packages/harness/ belongs to another lane now, so the list is copied here.
// tests/redact.test.mjs fails when a copied line no longer matches failure-notice.mjs. // tests/redact.test.mjs fails when a copied line no longer matches failure-notice.mjs.
// //
@@ -18,7 +20,8 @@ export { secretValues } from '../../harness/src/failure-notice.mjs';
export const LINE_MAX = 300; export const LINE_MAX = 300;
export const REDACTED = '[redacted]'; export const REDACTED = '[redacted]';
// Copied from failure-notice.mjs. Only the key-prefix line differs: it adds mso, mst and msp. // Copied from failure-notice.mjs. The key-prefix line adds mso, mst and msp, and the line after
// it is Mosaic's own; every other line is failure-notice's.
const KEY_WORD = "(?:\\w*[_-])?(?:api[_-]?key|key|token|secret|password|passwd|authorization|cookie|session)"; const KEY_WORD = "(?:\\w*[_-])?(?:api[_-]?key|key|token|secret|password|passwd|authorization|cookie|session)";
const REDACT = [ const REDACT = [
/(?<![a-z0-9+.-])[a-z0-9+.-]+:\/\/\S*/gi, // any link, its userinfo and query included, from the run's start /(?<![a-z0-9+.-])[a-z0-9+.-]+:\/\/\S*/gi, // any link, its userinfo and query included, from the run's start
@@ -31,6 +34,7 @@ const REDACT = [
new RegExp(`\\b${KEY_WORD}["']?\\s*[:=]\\s*(?:"[^"]*"?|'[^']*'?|[^\\s,;}]+)`, "gi"), new RegExp(`\\b${KEY_WORD}["']?\\s*[:=]\\s*(?:"[^"]*"?|'[^']*'?|[^\\s,;}]+)`, "gi"),
new RegExp(`\\b${KEY_WORD}["']?\\s+(?:"[^"]*"?|'[^']*'?|(?=[^\\s"',;}]*\\d)[^\\s"',;}]+|[^\\s"',;}]{8,})`, "gi"), new RegExp(`\\b${KEY_WORD}["']?\\s+(?:"[^"]*"?|'[^']*'?|(?=[^\\s"',;}]*\\d)[^\\s"',;}]+|[^\\s"',;}]{8,})`, "gi"),
/\b(?:sk|msk|mso|mst|msp|rk|pk|ghp|gho|ghs|glpat|xox[a-z])[-_]\S+/gi, /\b(?:sk|msk|mso|mst|msp|rk|pk|ghp|gho|ghs|glpat|xox[a-z])[-_]\S+/gi,
/ms[kotp][-_]\S+/gi, // Mosaic's prefixes glued to a word: added here, not in failure-notice.mjs
/\beyJ\S+/g, // JWT /\beyJ\S+/g, // JWT
/[A-Za-z0-9_\-+/=.]{32,}/g, /[A-Za-z0-9_\-+/=.]{32,}/g,
/(?<![A-Za-z0-9_\-+/=.])(?=[A-Za-z0-9_\-+/=.]*\d)(?=[A-Za-z0-9_\-+/=.]*[A-Za-z])[A-Za-z0-9_\-+/=.]{16,}/g, /(?<![A-Za-z0-9_\-+/=.])(?=[A-Za-z0-9_\-+/=.]*\d)(?=[A-Za-z0-9_\-+/=.]*[A-Za-z])[A-Za-z0-9_\-+/=.]{16,}/g,
+12
View File
@@ -346,6 +346,18 @@ test('receiptHistory refuses a cursor that is not a line start, past the end, ne
assert.equal(receiptHistory(dataRoot, { before: size }).entries.length, 3); assert.equal(receiptHistory(dataRoot, { before: size }).entries.length, 3);
}); });
test('receiptHistory withholds an entry whose fields hold an environment secret split across them', t => {
const dataRoot = scratch(t);
appendReceipt(dataRoot, { op: 'fetch', n: 1 });
appendReceipt(dataRoot, { op: 'x', a: 'plainword', b: 'sonly' });
appendReceipt(dataRoot, { op: 'x', plainw: 'ordsonly' });
appendReceipt(dataRoot, { op: 'x', list: ['plainwo', 'rdsonly'] });
appendReceipt(dataRoot, { op: 'fetch', n: 2 });
const all = receiptHistory(dataRoot, { limit: 10, secrets: secretValues({ PROXY_TOKEN: ENV_SECRET }) });
assert.deepEqual(all.entries, [{ op: 'fetch', n: 1 }, { withheld: true }, { withheld: true }, { withheld: true }, { op: 'fetch', n: 2 }]);
assert.equal(receiptHistory(dataRoot, { limit: 10 }).entries[1].a, 'plainword', 'with no secrets nothing is withheld');
});
test('receiptHistory: a missing file is an empty history; a symlink, FIFO, directory, group-readable or foreign file refuses', t => { test('receiptHistory: a missing file is an empty history; a symlink, FIFO, directory, group-readable or foreign file refuses', t => {
const dataRoot = scratch(t); const dataRoot = scratch(t);
assert.deepEqual(receiptHistory(dataRoot), { entries: [], next: null }); assert.deepEqual(receiptHistory(dataRoot), { entries: [], next: null });
+16 -2
View File
@@ -22,6 +22,17 @@ for (const [prefix, key] of Object.entries(SHORT)) {
}); });
} }
test('a short Mosaic key glued to a word or an underscore is redacted', () => {
for (const key of Object.values(SHORT)) {
for (const glued of [`x${key}`, `_${key}`, `id=x${key}`, `9${key.toUpperCase()}`]) {
const safe = redactLine(`proxy said ${glued} was refused`);
assert.equal(safe.redacted, true, glued);
assert.equal(safe.text.toLowerCase().includes(key.slice(4)), false, glued);
assert.match(safe.text, / was refused$/);
}
}
});
test('the real key shapes of each prefix are redacted', () => { test('the real key shapes of each prefix are redacted', () => {
const tail = 'Ab3_dE5-fG7hJ9kL1mN3pQ5rS7tU9vW1xY3zA5bC7dE'; const tail = 'Ab3_dE5-fG7hJ9kL1mN3pQ5rS7tU9vW1xY3zA5bC7dE';
for (const key of [`msk-k1a2-${tail}`, `mso-k1a2-acme-${tail}`, `mst-k1a2-triage-${tail}`, `msp-k1a2-${tail}`, `sk-ant-${tail}`]) { for (const key of [`msk-k1a2-${tail}`, `mso-k1a2-acme-${tail}`, `mst-k1a2-triage-${tail}`, `msp-k1a2-${tail}`, `sk-ant-${tail}`]) {
@@ -92,8 +103,9 @@ test('a 128000-character run with no spaces is redacted in well under a second',
}); });
// The list is a copy of failure-notice.mjs's. Every line must still match it, except the key-prefix // The list is a copy of failure-notice.mjs's. Every line must still match it, except the key-prefix
// line, which is the original with mso, mst and msp added after msk. // line, which is the original with mso, mst and msp added after msk, and Mosaic's glued-prefix line
test('the redaction list matches failure-notice.mjs line for line, with only the prefixes added', () => { // right after it.
test('the redaction list matches failure-notice.mjs line for line, with only the prefixes and one line added', () => {
const source = file => fs.readFileSync(fileURLToPath(new URL(file, import.meta.url)), 'utf8'); const source = file => fs.readFileSync(fileURLToPath(new URL(file, import.meta.url)), 'utf8');
const block = text => { const block = text => {
const body = /const REDACT = \[\n([\s\S]*?)\n\];/.exec(text)[1]; const body = /const REDACT = \[\n([\s\S]*?)\n\];/.exec(text)[1];
@@ -104,5 +116,7 @@ test('the redaction list matches failure-notice.mjs line for line, with only the
assert.equal(keyWord(ours), keyWord(theirs)); assert.equal(keyWord(ours), keyWord(theirs));
const expected = block(theirs).map(line => line.replace('(?:sk|msk|rk|', '(?:sk|msk|mso|mst|msp|rk|')); const expected = block(theirs).map(line => line.replace('(?:sk|msk|rk|', '(?:sk|msk|mso|mst|msp|rk|'));
assert.equal(expected.filter((line, i) => line !== block(theirs)[i]).length, 1, 'the original has one key-prefix line'); assert.equal(expected.filter((line, i) => line !== block(theirs)[i]).length, 1, 'the original has one key-prefix line');
const at = expected.findIndex(line => line.includes('(?:sk|msk|mso|mst|msp|rk|'));
expected.splice(at + 1, 0, '/ms[kotp][-_]\\S+/gi');
assert.deepEqual(block(ours), expected); assert.deepEqual(block(ours), expected);
}); });
+1
View File
@@ -62,6 +62,7 @@ export async function proxyHTTP(req, res, { path, call, named, tester, granted,
if (req.method === 'POST' && typeof record === 'function') { if (req.method === 'POST' && typeof record === 'function') {
let recorded; let recorded;
try { recorded = record({ verb: route[1], args, result: value, user: user ?? null }); } catch { recorded = false; } try { recorded = record({ verb: route[1], args, result: value, user: user ?? null }); } catch { recorded = false; }
// All four recorded verbs answer a plain object; any other answer is passed on unmarked.
if (recorded === false && value && typeof value === 'object' && !Array.isArray(value)) value = { ...value, recorded: false }; if (recorded === false && value && typeof value === 'object' && !Array.isArray(value)) value = { ...value, recorded: false };
} }
return done(200, value); return done(200, value);