Harden diagnostic response redaction

Redact every diagnostic response at the agent boundary, fail closed when sanitization cannot complete, and remove Windows, UNC, and slash-UNC paths from returned data. Preserve benign text while removing complete configured secret values, including nested JSON escapes and quoted HTML credential fields. Add focused regression coverage for collector errors, successful responses, support bundles, path variants, and punctuation secrets.
This commit is contained in:
Sucukdeluxe
2026-08-13 21:08:26 +02:00
parent 76ad81a0d3
commit 4c48044a95
6 changed files with 244 additions and 39 deletions
+19 -4
View File
@@ -1,3 +1,5 @@
const { valueScrub } = require('./support-bundle');
function createAgent(collectors) {
const OPS = {
get_system_info: (a) => collectors.getSystemInfo(a),
@@ -14,15 +16,28 @@ function createAgent(collectors) {
get_health: () => collectors.getHealth()
};
function redactResponse(value) {
try {
const redacted = typeof collectors.redactResponse === 'function'
? collectors.redactResponse(value)
: valueScrub(value, []);
const response = valueScrub(redacted, []);
if (!response || typeof response !== 'object' || Array.isArray(response)) throw new Error('invalid redaction result');
return response;
} catch {
return { ok: false, error: 'diagnostic response could not be safely returned' };
}
}
function handle(op, args) {
const fn = (typeof op === 'string' && Object.prototype.hasOwnProperty.call(OPS, op)) ? OPS[op] : null;
if (typeof fn !== 'function') return { ok: false, error: `unknown or non-readonly op: ${op}` };
if (typeof fn !== 'function') return redactResponse({ ok: false, error: `unknown or non-readonly op: ${op}` });
try {
const data = fn(args || {});
if (data && data.ok === false) return data;
return { ok: true, data };
if (data && data.ok === false) return redactResponse(data);
return redactResponse({ ok: true, data });
} catch (e) {
return { ok: false, error: String((e && e.message) || e) };
return redactResponse({ ok: false, error: String((e && e.message) || e) });
}
}