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();