mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 02:54:31 -07:00
feat(security): Introduce Conseca framework (#13193)
This commit is contained in:
committed by
GitHub
parent
05bc0399f3
commit
dde844dbe1
@@ -82,3 +82,24 @@ export function truncateString(
|
||||
}
|
||||
return str.slice(0, maxLength) + suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely replaces placeholders in a template string with values from a replacements object.
|
||||
* This performs a single-pass replacement to prevent double-interpolation attacks.
|
||||
*
|
||||
* @param template The template string containing {{key}} placeholders.
|
||||
* @param replacements A record of keys to their replacement values.
|
||||
* @returns The resulting string with placeholders replaced.
|
||||
*/
|
||||
export function safeTemplateReplace(
|
||||
template: string,
|
||||
replacements: Record<string, string>,
|
||||
): string {
|
||||
// Regex to match {{key}} in the template string. The regex enforces string naming rules.
|
||||
const placeHolderRegex = /\{\{(\w+)\}\}/g;
|
||||
return template.replace(placeHolderRegex, (match, key) =>
|
||||
Object.prototype.hasOwnProperty.call(replacements, key)
|
||||
? replacements[key]
|
||||
: match,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user