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:
Devin AI 2026-06-02 20:34:47 +00:00
parent 91920ac661
commit 197eda83f9

View File

@ -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: