fix(core): remove shell outputChunks buffer caching to prevent memory bloat and sanitize prompt input (#23751)

This commit is contained in:
Spencer
2026-03-26 17:16:07 -04:00
committed by GitHub
parent 30397816da
commit d25ce0e143
4 changed files with 37 additions and 39 deletions

View File

@@ -45,20 +45,18 @@ function addShellCommandToGeminiHistory(
? resultText.substring(0, MAX_OUTPUT_LENGTH) + '\n... (truncated)'
: resultText;
// Escape backticks to prevent prompt injection breakouts
const safeQuery = rawQuery.replace(/\\/g, '\\\\').replace(/\x60/g, '\\\x60');
const safeModelContent = modelContent
.replace(/\\/g, '\\\\')
.replace(/\x60/g, '\\\x60');
// eslint-disable-next-line @typescript-eslint/no-floating-promises
geminiClient.addHistory({
role: 'user',
parts: [
{
text: `I ran the following shell command:
\`\`\`sh
${rawQuery}
\`\`\`
This produced the following result:
\`\`\`
${modelContent}
\`\`\``,
text: `I ran the following shell command:\n\`\`\`sh\n${safeQuery}\n\`\`\`\n\nThis produced the following result:\n\`\`\`\n${safeModelContent}\n\`\`\``,
},
],
});
@@ -444,7 +442,7 @@ export const useShellCommandProcessor = (
}
let mainContent: string;
if (isBinary(result.rawOutput)) {
if (isBinaryStream || isBinary(result.rawOutput)) {
mainContent =
'[Command produced binary output, which is not shown.]';
} else {