typebox
typebox copied to clipboard
Value.Clone drops own properties named constructor, prototype, and __proto__
Description
Value.Clone silently drops own JSON properties named constructor, prototype, and __proto__. Schema preprocessing also loses __proto__, so Value.Decode rejects valid input that contains that key with a DecodeError.
Reproduction
import { Type } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value'
const value = {
constructor: 1,
prototype: 2,
__proto__: 3,
}
console.log(Value.Clone(value))
// expected: { constructor: 1, prototype: 2, __proto__: 3 }
// actual: {}
const schema = Type.Object({
__proto__: Type.Number(),
})
console.log(Value.Decode(schema, { __proto__: 1 }))
// throws DecodeError
Expected
Own data properties with those names should survive cloning and preprocessing. Inherited prototype behaviour and schema metadata should stay unchanged.
Environment
Reproduced on @sinclair/typebox 1.4.2 (main).
Closing as per comment https://github.com/sinclairzx81/typebox/pull/1730#issuecomment-6600428420