security(hooks): Wrap hook-injected context in distinct XML tags (#17237)

Co-authored-by: Yuna Seol <yunaseol@google.com>
This commit is contained in:
Yuna Seol
2026-01-21 21:11:45 -05:00
committed by GitHub
parent 75e4f492ab
commit 5debf86854
8 changed files with 136 additions and 12 deletions
+2 -3
View File
@@ -664,9 +664,8 @@ export async function main() {
const additionalContext = result.getAdditionalContext();
if (additionalContext) {
// Prepend context to input (System Context -> Stdin -> Question)
input = input
? `${additionalContext}\n\n${input}`
: additionalContext;
const wrappedContext = `<hook_context>${additionalContext}</hook_context>`;
input = input ? `${wrappedContext}\n\n${input}` : wrappedContext;
}
}
}
+3 -1
View File
@@ -317,7 +317,9 @@ export const AppContainer = (props: AppContainerProps) => {
if (additionalContext && geminiClient) {
await geminiClient.addHistory({
role: 'user',
parts: [{ text: additionalContext }],
parts: [
{ text: `<hook_context>${additionalContext}</hook_context>` },
],
});
}
}