mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
Escape config file name in agent prompt to prevent prompt injection
JSON-encode configFileName in buildConfigUpdatePrompt, matching the existing treatment of config paths/values, so a file name containing a backtick can't break out of the prompt's code span. Co-Authored-By: mantra <mantra@stack-auth.com>
This commit is contained in:
parent
91920ac661
commit
197eda83f9
@ -352,9 +352,13 @@ function buildConfigUpdatePrompt(configFileName: string, configUpdate: Config):
|
||||
return `- ${JSON.stringify(configPath)}: set to ${JSON.stringify(value)}`;
|
||||
}).join("\n");
|
||||
|
||||
// The file name comes from the on-disk path (effectively untrusted), so it's
|
||||
// JSON-encoded for the same reason the change paths/values are above: a name
|
||||
// containing a backtick would otherwise break out of this code span and could
|
||||
// inject extra instructions into the prompt.
|
||||
return `You are editing a Hexclave / Stack Auth configuration file in place. Apply a set of configuration changes WITHOUT changing how the file is written.
|
||||
|
||||
Config file: \`${configFileName}\` (in the current working directory).
|
||||
Config file: ${JSON.stringify(configFileName)} (in the current working directory).
|
||||
|
||||
The file exports a \`config\` object (it may be wrapped in a helper such as \`defineStackConfig(...)\`). Some config values may be sourced from other files via imports, for example:
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user