fix: apply ownPropertyOnly uniformly in readJSProperty

Proto keys block inherited access only; ownPropertyOnly is checked once before return for all keys. Own __proto__/constructor/prototype properties are readable—sanitize untrusted scope input.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-07-23 22:59:37 +08:00
co-authored by Cursor
parent d32da49925
commit 85321c6d64
5 changed files with 24 additions and 14 deletions
@@ -39,4 +39,16 @@ describe('scope security', function () {
{ drop: new IterableDrop() }
)).resolves.toBe('ab')
})
it('should allow own blocked keys when ownPropertyOnly=true', async function () {
const scope = JSON.parse('{"__proto__": {"polluted": true}, "constructor": {"name": "Custom"}, "name": "Alice"}')
await expect(liquid.parseAndRender('{{ __proto__.polluted }}', scope)).resolves.toBe('true')
await expect(liquid.parseAndRender('{{ constructor.name }}', scope)).resolves.toBe('Custom')
})
it('should still block inherited blocked keys when ownPropertyOnly=true', async function () {
const scope = { foo: Object.create({ __proto__: { bar: 'BAR' }, constructor: { name: 'Evil' } }) }
await expect(liquid.parseAndRender('{{ foo.__proto__.bar }}', scope)).resolves.toBe('')
await expect(liquid.parseAndRender('{{ foo.constructor.name }}', scope)).resolves.toBe('')
})
})