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:
@@ -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) });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user