Harden verify-work checkpoint rendering

This commit is contained in:
3metaJun
2026-03-24 01:16:27 +08:00
committed by Tom Boucher
parent f43e0237f2
commit aaaa8e96fe
7 changed files with 249 additions and 15 deletions

View File

@@ -223,6 +223,32 @@ function sanitizeForPrompt(text) {
return sanitized;
}
/**
* Sanitize text that will be displayed back to the user.
* Removes protocol-like leak markers that should never surface in checkpoints.
*
* @param {string} text - Text to sanitize
* @returns {string} Sanitized text
*/
function sanitizeForDisplay(text) {
if (!text || typeof text !== 'string') return text;
let sanitized = sanitizeForPrompt(text);
const protocolLeakPatterns = [
/^\s*(?:assistant|user|system)\s+to=[^:\s]+:[^\n]+$/i,
/^\s*(?:assistant|user|system)\s+to=all:[^\n]+$/i,
/^\s*<\|(?:assistant|user|system)[^|]*\|>\s*$/i,
];
sanitized = sanitized
.split('\n')
.filter(line => !protocolLeakPatterns.some(pattern => pattern.test(line)))
.join('\n');
return sanitized;
}
// ─── Shell Safety ───────────────────────────────────────────────────────────
/**
@@ -343,6 +369,7 @@ module.exports = {
INJECTION_PATTERNS,
scanForInjection,
sanitizeForPrompt,
sanitizeForDisplay,
// Shell safety
validateShellArg,