mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-14 03:50:49 -07:00
fix(core): secure argsPattern and revert WEB_FETCH_TOOL_NAME escalation (#22104)
Co-authored-by: Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
@@ -57,7 +57,11 @@
|
||||
* // Returns: '{"safe":"data"}'
|
||||
*/
|
||||
export function stableStringify(obj: unknown): string {
|
||||
const stringify = (currentObj: unknown, ancestors: Set<unknown>): string => {
|
||||
const stringify = (
|
||||
currentObj: unknown,
|
||||
ancestors: Set<unknown>,
|
||||
isTopLevel = false,
|
||||
): string => {
|
||||
// Handle primitives and null
|
||||
if (currentObj === undefined) {
|
||||
return 'null'; // undefined in arrays becomes null in JSON
|
||||
@@ -89,7 +93,10 @@ export function stableStringify(obj: unknown): string {
|
||||
if (jsonValue === null) {
|
||||
return 'null';
|
||||
}
|
||||
return stringify(jsonValue, ancestors);
|
||||
// The result of toJSON is effectively a new object graph, but it
|
||||
// takes the place of the current node, so we preserve the top-level
|
||||
// status of the current node.
|
||||
return stringify(jsonValue, ancestors, isTopLevel);
|
||||
} catch {
|
||||
// If toJSON throws, treat as a regular object
|
||||
}
|
||||
@@ -101,7 +108,7 @@ export function stableStringify(obj: unknown): string {
|
||||
if (item === undefined || typeof item === 'function') {
|
||||
return 'null';
|
||||
}
|
||||
return stringify(item, ancestors);
|
||||
return stringify(item, ancestors, false);
|
||||
});
|
||||
return '[' + items.join(',') + ']';
|
||||
}
|
||||
@@ -115,7 +122,17 @@ export function stableStringify(obj: unknown): string {
|
||||
const value = (currentObj as Record<string, unknown>)[key];
|
||||
// Skip undefined and function values in objects (per JSON spec)
|
||||
if (value !== undefined && typeof value !== 'function') {
|
||||
pairs.push(JSON.stringify(key) + ':' + stringify(value, ancestors));
|
||||
let pairStr =
|
||||
JSON.stringify(key) + ':' + stringify(value, ancestors, false);
|
||||
|
||||
if (isTopLevel) {
|
||||
// We use a null byte (\0) to denote structural boundaries.
|
||||
// This is safe because any literal \0 in the user's data will
|
||||
// be escaped by JSON.stringify into "\u0000" before reaching here.
|
||||
pairStr = '\0' + pairStr + '\0';
|
||||
}
|
||||
|
||||
pairs.push(pairStr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,5 +142,5 @@ export function stableStringify(obj: unknown): string {
|
||||
}
|
||||
};
|
||||
|
||||
return stringify(obj, new Set());
|
||||
return stringify(obj, new Set(), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user