@devries-cameron20 / composio-1 / commits / 991c57af8
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(core): keep properties named like prototype keys under strict mode

toStrictJsonSchema assigned rewritten property schemas by name, so a property called __proto__ set the prototype of the properties map instead of being stored and disappeared from the strict schema. Own properties are now defined explicitly, matching the other schema walkers in this module. Co-authored-by: AseemPrasad <aseemprasad0520@gmail.com> Claude-Session: https://claude.ai/code/session_01TDrxCHn2hg51HmxVstSUgs

jkomyno committed Aug 26, 2026 at 17:37 UTC 991c57af809a21385468eaec705775bdc0cb6a46
1 file changed +29 -14
ts/packages/core/src/utils/jsonSchema.ts
+29 -14
@@ -568,6 +568,19 @@ type StrictWalkMode = 'schema' | 'schema-array' | 'schema-map' | 'value';
568
569 const joinPath = (parent: string, key: string): string => (parent ? `${parent}.${key}` : key);
570
571 +/**
572 + * Sets an own property regardless of its name: a plain assignment to a key
573 + * such as `__proto__` would set the prototype instead of storing the value.
574 + */
575 +function setOwn(target: Record<string, unknown>, key: string, value: unknown): void {
576 + Object.defineProperty(target, key, {
577 + configurable: true,
578 + enumerable: true,
579 + value,
580 + writable: true,
581 + });
582 +}
583 +
584 /**
585 * Widens a property schema so that `null` is an accepted value, without
586 * placing `type` beside `anyOf` (the API rejects that combination).
@@ -690,17 +703,16 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
703 if (childMode === 'schema-map' && isPlainObject(child)) {
704 const mapClone: Record<string, unknown> = {};
705 for (const [name, subSchema] of Object.entries(child)) {
693 - mapClone[name] = walk(
694 - subSchema,
695 - 'schema',
696 - depth + 1,
697 - joinPath(joinPath(path, key), name)
706 + setOwn(
707 + mapClone,
708 + name,
709 + walk(subSchema, 'schema', depth + 1, joinPath(joinPath(path, key), name))
710 );
711 }
700 - clone[key] = mapClone;
712 + setOwn(clone, key, mapClone);
713 continue;
714 }
703 - clone[key] = walk(child, childMode, depth + 1, joinPath(path, key));
715 + setOwn(clone, key, walk(child, childMode, depth + 1, joinPath(path, key)));
716 }
717 return clone;
718 }
@@ -725,7 +737,7 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
737 });
738 continue;
739 }
728 - node[key] = child;
740 + setOwn(node, key, child);
741 }
742 if (Array.isArray(node.oneOf) && node.anyOf === undefined) {
743 node.anyOf = node.oneOf;
@@ -763,15 +775,18 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
775 out.type === 'object' || (Array.isArray(out.type) && out.type.includes('object'));
776 if (!declaresObjectType && !isPlainObject(out.properties)) return out;
777
766 - const properties: Record<string, unknown> = isPlainObject(out.properties)
767 - ? { ...out.properties }
768 - : {};
778 + const properties: Record<string, unknown> = {};
779 + if (isPlainObject(out.properties)) {
780 + for (const [name, propertySchema] of Object.entries(out.properties)) {
781 + setOwn(properties, name, propertySchema);
782 + }
783 + }
784 const declaredRequired = new Set(
785 Array.isArray(out.required) ? out.required.filter(entry => typeof entry === 'string') : []
786 );
787 for (const [name, propertySchema] of Object.entries(properties)) {
788 if (declaredRequired.has(name) || !isPlainObject(propertySchema)) continue;
774 - properties[name] = widenToNullable(propertySchema);
789 + setOwn(properties, name, widenToNullable(propertySchema));
790 recordChange({
791 path: joinPath(path, `properties.${name}`),
792 reason: 'optional-property-nullable',
@@ -877,11 +892,11 @@ function omitNulls(
892 : undefined;
893 if (child === null) {
894 if (propertySchema === undefined || schemaAcceptsNull(propertySchema, root)) {
880 - clone[key] = child;
895 + setOwn(clone, key, child);
896 }
897 continue;
898 }
884 - clone[key] = omitNulls(child, propertySchema, root, depth + 1);
899 + setOwn(clone, key, omitNulls(child, propertySchema, root, depth + 1));
900 }
901 return clone;
902 }