Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit 9eb7f38

Browse files
author
the-djmaze
committed
KnockoutJS secure bindings using Proxy
1 parent 82ab4c4 commit 9eb7f38

File tree

3 files changed

+71
-43
lines changed

3 files changed

+71
-43
lines changed

vendors/knockout/build/output/knockout-latest.debug.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,7 @@ ko.bindingProvider = new class
16181618
try {
16191619
let cacheKey = bindingsString,
16201620
bindingFunction = bindingCache.get(cacheKey);
1621+
/*
16211622
if (!bindingFunction) {
16221623
// Build the source for a function that evaluates "expression"
16231624
// For each scope variable, add an extra level of "with" nesting
@@ -1631,6 +1632,23 @@ ko.bindingProvider = new class
16311632
return bindingFunction(bindingContext,
16321633
bindingContext["$root"], bindingContext["$parent"], bindingContext["$data"] || {}, node
16331634
);
1635+
*/
1636+
if (!bindingFunction) {
1637+
// Build the source for a function that evaluates "expression"
1638+
// Use one "with" that has one secure scope handling Proxy
1639+
// Deprecated: with is no longer recommended
1640+
var rewrittenBindings = ko.expressionRewriting.preProcessBindings(bindingsString),
1641+
functionBody = "$context = new Proxy(\
1642+
$context,\
1643+
{\
1644+
has: () => true,\
1645+
get: (target, key) => target[key] || target['$data'][key]\
1646+
}\
1647+
);with($context){return{" + rewrittenBindings + "}}";
1648+
bindingFunction = new Function("$context", functionBody);
1649+
bindingCache.set(cacheKey, bindingFunction);
1650+
}
1651+
return bindingFunction(bindingContext);
16341652
} catch (ex) {
16351653
ex.message = "Unable to parse bindings.\nBindings value: " + bindingsString
16361654
+ "\nMessage: " + ex.message;

0 commit comments

Comments
 (0)