From daa0e2372db0ffa3ee61d8077575d77a1bab0bbe Mon Sep 17 00:00:00 2001 From: Shinya Fujino Date: Fri, 6 Nov 2026 03:14:52 +0900 Subject: [PATCH] fix(env): pass Object.prototype members through the env proxy `readKey` looked keys up with `registry.schema[key]`, which also finds inherited members. With a schema registered, `env.hasOwnProperty`, `env.constructor` and `String(env)` treated those members as validators and threw a TypeError. Co-Authored-By: Claude Opus 5.5 --- packages/void/src/runtime/env-public.ts | 3 ++- packages/void/test/unit/env-schema.test.ts | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/void/src/runtime/env-public.ts b/packages/void/src/runtime/env-public.ts index dcb57b1f8..ff8ca3a75 100644 --- a/packages/void/src/runtime/env-public.ts +++ b/packages/void/src/runtime/env-public.ts @@ -252,7 +252,8 @@ function readKey(key: string): unknown { if (!registry.schema) { return rawValue; } - const validator = registry.schema[key]; + // `env.hasOwnProperty` and the like come from Object.prototype, not from the schema. + const validator = Object.hasOwn(registry.schema, key) ? registry.schema[key] : undefined; if (!validator) { return rawValue; } diff --git a/packages/void/test/unit/env-schema.test.ts b/packages/void/test/unit/env-schema.test.ts index 890b9a81d..dd213cce1 100644 --- a/packages/void/test/unit/env-schema.test.ts +++ b/packages/void/test/unit/env-schema.test.ts @@ -127,6 +127,15 @@ describe('defineEnv + env proxy', () => { }); }); + it('passes through Object.prototype members without validation', () => { + defineEnv({ STRIPE_KEY: string() }); + withRuntimeEnv({ STRIPE_KEY: 'sk' }, () => { + expect(env.hasOwnProperty).toBe(Object.prototype.hasOwnProperty); + expect(env.constructor).toBe(Object); + expect(String(env)).toBe('[object Object]'); + }); + }); + it('caches validated values per env identity (no re-validation)', () => { let calls = 0; const inner = string();