mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-13 11:30:39 -07:00
Change formatting to prevent UI redressing attacks (#17611)
This commit is contained in:
committed by
GitHub
parent
43c98ce4f1
commit
5484766fb5
@@ -124,18 +124,16 @@ export function stripUnsafeCharacters(str: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize a string for display in list-like UI components (e.g. Help, Suggestions).
|
||||
* Removes ANSI codes, collapses whitespace characters into a single space, and optionally truncates.
|
||||
* Sanitize a string for display in inline UI components (e.g. Help, Suggestions).
|
||||
* Removes ANSI codes, dangerous control characters, collapses whitespace
|
||||
* characters into a single space, and optionally truncates.
|
||||
*/
|
||||
export function sanitizeForListDisplay(
|
||||
str: string,
|
||||
maxLength?: number,
|
||||
): string {
|
||||
export function sanitizeForDisplay(str: string, maxLength?: number): string {
|
||||
if (!str) {
|
||||
return '';
|
||||
}
|
||||
|
||||
let sanitized = stripAnsi(str).replace(/\s+/g, ' ');
|
||||
let sanitized = stripUnsafeCharacters(str).replace(/\s+/g, ' ');
|
||||
|
||||
if (maxLength && sanitized.length > maxLength) {
|
||||
sanitized = sanitized.substring(0, maxLength - 3) + '...';
|
||||
|
||||
Reference in New Issue
Block a user