mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix: tie proto key blocking to ownPropertyOnly policy
Block __proto__, constructor, and prototype only when ownPropertyOnly is true or when access would traverse the prototype chain. Allow own properties with those names when ownPropertyOnly is false. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
+11
-1
@@ -13,6 +13,16 @@ export function isBlockedScopeKey (key: PropertyKey): boolean {
|
||||
return typeof key === 'string' && BLOCKED_SCOPE_KEYS.has(key)
|
||||
}
|
||||
|
||||
export function shouldBlockScopeKeyRead (obj: Scope, key: PropertyKey, ownPropertyOnly: boolean): boolean {
|
||||
if (!isBlockedScopeKey(key)) return false
|
||||
if (ownPropertyOnly) return true
|
||||
return !hasOwnProperty.call(obj, key)
|
||||
}
|
||||
|
||||
export function shouldBlockScopeKeyWrite (key: PropertyKey, ownPropertyOnly: boolean): boolean {
|
||||
return ownPropertyOnly && isBlockedScopeKey(key)
|
||||
}
|
||||
|
||||
export function createScope (from?: ScopeObject): ScopeObject {
|
||||
return from ? sanitizeScope(from) : Object.create(null)
|
||||
}
|
||||
@@ -20,7 +30,7 @@ export function createScope (from?: ScopeObject): ScopeObject {
|
||||
export function sanitizeScope (obj: ScopeObject): ScopeObject {
|
||||
const scope = Object.create(null)
|
||||
for (const key of Object.keys(obj)) {
|
||||
if (!isBlockedScopeKey(key) && hasOwnProperty.call(obj, key)) {
|
||||
if (hasOwnProperty.call(obj, key)) {
|
||||
scope[key] = obj[key]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user