typebox icon indicating copy to clipboard operation
typebox copied to clipboard

Value.Clone drops own properties named constructor, prototype, and __proto__

Open CheckPickerUpper opened this issue 1 month ago • 1 comments

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).

CheckPickerUpper avatar Oct 27 '26 15:10 CheckPickerUpper

Closing as per comment https://github.com/sinclairzx81/typebox/pull/1730#issuecomment-6600428420

sinclairzx81 avatar Nov 03 '26 09:11 sinclairzx81