SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
On Contracts, Sandboxes,
and Proxies for JavaScript
Matthias Keil, Peter Thiemann
University of Freiburg, Germany
October 5, 2015, 18. Kolloquium Programmiersprachen und Grundlagen der Programmierung, KPS 2015
P¨ortschach am W¨orthersee, ¨Osterreich
TreatJS
Language embedded contract system for JavaScript
Enforced by run-time monitoring
Standard abstractions for higher-order-contracts (base,
function, and dependent contracts) [Findler,Felleisen’02]
Systematic blame calculation
Contract constructors generalize dependent contracts
Internal noninterference
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 2 / 14
Base Contract [Findler,Felleisen’02]
Base Contracts are built from predicates
Specified by a plain JavaScript function
Base Contract
function isNumber (arg) {
return (typeof arg) === ’number’;
};
var Number = Contract.Base(isNumber);
assert(1, Number ); 
assert(’a’, Number );  blame the subject
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 3 / 14
Function Contract [Findler,Felleisen’02]
// Number × Number → Number
function plus (x, y) {
return (x + y);
}
Function Contract
var Plus = Contract.Function([ Number , Number ],
Number );
var plusNumber = assert(plus, Plus );
plusNumber(1, 1); 
plusNumber(’a’, ’a’);  blame the context
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 4 / 14
JavaScript Proxies
Handler
Proxy Target Shadow
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
JavaScript Proxies
Handler
Proxy Target Shadow
proxy.x;
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
JavaScript Proxies
Handler
Proxy Target Shadow
proxy.x;
handler.get(target, ’x’, proxy);
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
JavaScript Proxies
Handler
Proxy Target Shadow
proxy.x;
handler.get(target, ’x’, proxy);
target[’x’];
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
JavaScript Proxies
Handler
Proxy Target Shadow
proxy.x;
proxy.y=1;
...
handler.get(target, ’x’, proxy);
handler.set(target, ’y’, 1, proxy);
...
target[’x’];
target[’y’]=1;
...
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
Noninterference
Noninterference
The contract system should not interfere with the execution of
application code.
External Noninterference arises from the interaction of the
contract system with the host program
1 Exceptions
2 Object equality
Internal Noninterference arises from executing unrestricted
code in predicates
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 6 / 14
Internal Noninterference
No syntactic restrictions on predicates
Predicates may try to write to data that is visible to the
application
Solution: Predicate evaluation takes place in a sandbox
Faulty Predicate
function isNumber (arg) {
type = (typeof arg);
return type === ’number’;
};
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 7 / 14
Internal Noninterference
No syntactic restrictions on predicates
Predicates may try to write to data that is visible to the
application
Solution: Predicate evaluation takes place in a sandbox
Faulty Predicate
function isNumber (arg) {
type = (typeof arg);  access forbidden
return type === ’number’;
};
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 7 / 14
TreatJS Sandbox
All contracts guarantee noninterference
Read-only access is safe
Predicate with Read-Access
function isArray (arg) {
return (arg instanceof Array); 
}
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 8 / 14
TreatJS Sandbox
Predicate execution may violate contracts
Solution: Sandbox redefines the responsibility
Predicate with Read-Access
function addOne (arg) {
return plusNumber(arg, ’1’);  blame the ?
}
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 9 / 14
TreatJS Sandbox
Predicate execution may violate contracts
Solution: Sandbox redefines the responsibility
Predicate with Read-Access
function addOne (arg) {
return plusNumber(arg, ’1’);  blame the contract
}
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 9 / 14
Sandbox Encapsulation
Faulty Predicate
function isNumber (arg) {
type = (typeof arg);
return type === ’number’;
};
1 Place a write protection on objects (e.g. this, arg)
2 Remove external bindings of functions (e.g. type)
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 10 / 14
Identity Preserving Membrane
ProxyA
?ProxyB
ProxyC
TargetA
TargetB
TargetC
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
Identity Preserving Membrane
ProxyA
?ProxyB
ProxyC
TargetA
TargetB
TargetC
x
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
Identity Preserving Membrane
ProxyA
?ProxyB
ProxyC
TargetA
TargetB
TargetC
x x
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
Identity Preserving Membrane
ProxyA
?ProxyB
ProxyC
TargetA
TargetB
TargetC
x x
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
Identity Preserving Membrane
ProxyA
?ProxyB
ProxyC
TargetA
TargetB
TargetC
x
y
x
y
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
Identity Preserving Membrane
ProxyA
?ProxyB
ProxyC
TargetA
TargetB
TargetC
x
z
y
x
z
y
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
Shadow Objects
Handler
Proxy Target Shadow
proxy.x;
proxy.y=1;
handler.get(target, ’x’, proxy);
handler.set(target, ’y’, 1, proxy);
target[’x’];
target[’y’]=1;
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
Shadow Objects
Handler
Proxy Target Shadow
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
Shadow Objects
Handler
Proxy Target Shadow
proxy.x;
handler.get(target, ’x’, proxy);
target[’x’];
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
Shadow Objects
Handler
Proxy Target Shadow
proxy.x;
proxy.y=1;
handler.get(target, ’x’, proxy);
handler.set(target, ’y’, 1, proxy);
target[’x’]; shadow[’y’]=1;
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
Shadow Objects
Handler
Proxy Target Shadow
proxy.x;
proxy.y=1;
proxy.y;
handler.get(target, ’x’, proxy);
handler.set(target, ’y’, 1, proxy);
handler.get(target, ’y’, proxy);
target[’x’]; shadow[’y’]=1;
shadow[’y’];
Meta-Level
Base-Level
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
Function Recompilation
var x = 1;
function f (){
function g (y) {
var z = 1;
return x+y+z;
}
}
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
Function Recompilation
var x = 1;
function f (){
”function g (y) {
var z = 1;
return x+y+z;
}”
}
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
Function Recompilation
var x = 1;
with(sbxglobal){
eval( ”function g (y) {
var z = 1;
return x+y+z;
}”);
}
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
Function Recompilation
var x = 1;
with(sbxglobal){
function g (y) {
var z = 1;
return x+y+z;
}
}
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
Conclusion
TreatJS:
Language embedded, dynamic, higher-order contract system
for full JavaScript
Guarantees noninterference
Sandbox:
Language embedded sandbox for full JavaScript
Runs JavaScript code in isolation isolation
Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 14 / 14

Mais conteúdo relacionado

Destaque (10)

100 років унр зош19
100 років унр  зош19100 років унр  зош19
100 років унр зош19
 
на сайт про права дитини
на сайт про права дитинина сайт про права дитини
на сайт про права дитини
 
документ Microsoft word
документ Microsoft wordдокумент Microsoft word
документ Microsoft word
 
білицька зош 8. свято україночка 2017.
білицька зош 8. свято україночка 2017.білицька зош 8. свято україночка 2017.
білицька зош 8. свято україночка 2017.
 
пожарные
пожарныепожарные
пожарные
 
Drug approval process
Drug approval processDrug approval process
Drug approval process
 
зош № 9 день добровольця
зош № 9 день добровольцязош № 9 день добровольця
зош № 9 день добровольця
 
100 річчя оригинал
100 річчя оригинал100 річчя оригинал
100 річчя оригинал
 
Sibylle Rudin: Erlebnis Bibliothek: Wiki für die Schule
Sibylle Rudin: Erlebnis Bibliothek: Wiki für die SchuleSibylle Rudin: Erlebnis Bibliothek: Wiki für die Schule
Sibylle Rudin: Erlebnis Bibliothek: Wiki für die Schule
 
Compu training (1)
Compu training (1)Compu training (1)
Compu training (1)
 

Semelhante a On Contracts, Sandboxes, and Proxies for JavaScript

Semelhante a On Contracts, Sandboxes, and Proxies for JavaScript (6)

On Contracts and Sandboxes for JavaScript
On Contracts and Sandboxes for JavaScriptOn Contracts and Sandboxes for JavaScript
On Contracts and Sandboxes for JavaScript
 
Transparent Object Proxies for JavaScript
Transparent Object Proxies for JavaScriptTransparent Object Proxies for JavaScript
Transparent Object Proxies for JavaScript
 
Efficient Dynamic Access Analysis Using JavaScript Proxies
Efficient Dynamic Access Analysis Using JavaScript ProxiesEfficient Dynamic Access Analysis Using JavaScript Proxies
Efficient Dynamic Access Analysis Using JavaScript Proxies
 
Building a (Really) Secure Cloud Product
Building a (Really) Secure Cloud ProductBuilding a (Really) Secure Cloud Product
Building a (Really) Secure Cloud Product
 
Interacting with the Exchange Web Services
Interacting with the Exchange Web ServicesInteracting with the Exchange Web Services
Interacting with the Exchange Web Services
 
Istio Cloud Native Online Series - Intro to Istio Security
Istio Cloud Native Online Series - Intro to Istio SecurityIstio Cloud Native Online Series - Intro to Istio Security
Istio Cloud Native Online Series - Intro to Istio Security
 

Mais de Matthias Keil (6)

Blame Assignment for Higher-Order Contracts with Intersection and Union
Blame Assignment for Higher-Order Contracts with Intersection and UnionBlame Assignment for Higher-Order Contracts with Intersection and Union
Blame Assignment for Higher-Order Contracts with Intersection and Union
 
TreatJS: Higher-Order Contracts for JavaScripts
TreatJS: Higher-Order Contracts for JavaScriptsTreatJS: Higher-Order Contracts for JavaScripts
TreatJS: Higher-Order Contracts for JavaScripts
 
Symbolic Solving of Extended Regular Expression Inequalities
Symbolic Solving of Extended Regular Expression InequalitiesSymbolic Solving of Extended Regular Expression Inequalities
Symbolic Solving of Extended Regular Expression Inequalities
 
TreatJS: Higher-Order Contracts for JavaScript
TreatJS: Higher-Order Contracts for JavaScriptTreatJS: Higher-Order Contracts for JavaScript
TreatJS: Higher-Order Contracts for JavaScript
 
Type-based Dependency Analysis for JavaScript
Type-based Dependency Analysis for JavaScriptType-based Dependency Analysis for JavaScript
Type-based Dependency Analysis for JavaScript
 
Type-based Dependency Analysis
Type-based Dependency AnalysisType-based Dependency Analysis
Type-based Dependency Analysis
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

On Contracts, Sandboxes, and Proxies for JavaScript

  • 1. On Contracts, Sandboxes, and Proxies for JavaScript Matthias Keil, Peter Thiemann University of Freiburg, Germany October 5, 2015, 18. Kolloquium Programmiersprachen und Grundlagen der Programmierung, KPS 2015 P¨ortschach am W¨orthersee, ¨Osterreich
  • 2. TreatJS Language embedded contract system for JavaScript Enforced by run-time monitoring Standard abstractions for higher-order-contracts (base, function, and dependent contracts) [Findler,Felleisen’02] Systematic blame calculation Contract constructors generalize dependent contracts Internal noninterference Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 2 / 14
  • 3. Base Contract [Findler,Felleisen’02] Base Contracts are built from predicates Specified by a plain JavaScript function Base Contract function isNumber (arg) { return (typeof arg) === ’number’; }; var Number = Contract.Base(isNumber); assert(1, Number ); assert(’a’, Number ); blame the subject Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 3 / 14
  • 4. Function Contract [Findler,Felleisen’02] // Number × Number → Number function plus (x, y) { return (x + y); } Function Contract var Plus = Contract.Function([ Number , Number ], Number ); var plusNumber = assert(plus, Plus ); plusNumber(1, 1); plusNumber(’a’, ’a’); blame the context Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 4 / 14
  • 5. JavaScript Proxies Handler Proxy Target Shadow Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
  • 6. JavaScript Proxies Handler Proxy Target Shadow proxy.x; Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
  • 7. JavaScript Proxies Handler Proxy Target Shadow proxy.x; handler.get(target, ’x’, proxy); Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
  • 8. JavaScript Proxies Handler Proxy Target Shadow proxy.x; handler.get(target, ’x’, proxy); target[’x’]; Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
  • 9. JavaScript Proxies Handler Proxy Target Shadow proxy.x; proxy.y=1; ... handler.get(target, ’x’, proxy); handler.set(target, ’y’, 1, proxy); ... target[’x’]; target[’y’]=1; ... Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 5 / 14
  • 10. Noninterference Noninterference The contract system should not interfere with the execution of application code. External Noninterference arises from the interaction of the contract system with the host program 1 Exceptions 2 Object equality Internal Noninterference arises from executing unrestricted code in predicates Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 6 / 14
  • 11. Internal Noninterference No syntactic restrictions on predicates Predicates may try to write to data that is visible to the application Solution: Predicate evaluation takes place in a sandbox Faulty Predicate function isNumber (arg) { type = (typeof arg); return type === ’number’; }; Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 7 / 14
  • 12. Internal Noninterference No syntactic restrictions on predicates Predicates may try to write to data that is visible to the application Solution: Predicate evaluation takes place in a sandbox Faulty Predicate function isNumber (arg) { type = (typeof arg); access forbidden return type === ’number’; }; Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 7 / 14
  • 13. TreatJS Sandbox All contracts guarantee noninterference Read-only access is safe Predicate with Read-Access function isArray (arg) { return (arg instanceof Array); } Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 8 / 14
  • 14. TreatJS Sandbox Predicate execution may violate contracts Solution: Sandbox redefines the responsibility Predicate with Read-Access function addOne (arg) { return plusNumber(arg, ’1’); blame the ? } Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 9 / 14
  • 15. TreatJS Sandbox Predicate execution may violate contracts Solution: Sandbox redefines the responsibility Predicate with Read-Access function addOne (arg) { return plusNumber(arg, ’1’); blame the contract } Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 9 / 14
  • 16. Sandbox Encapsulation Faulty Predicate function isNumber (arg) { type = (typeof arg); return type === ’number’; }; 1 Place a write protection on objects (e.g. this, arg) 2 Remove external bindings of functions (e.g. type) Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 10 / 14
  • 17. Identity Preserving Membrane ProxyA ?ProxyB ProxyC TargetA TargetB TargetC Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
  • 18. Identity Preserving Membrane ProxyA ?ProxyB ProxyC TargetA TargetB TargetC x Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
  • 19. Identity Preserving Membrane ProxyA ?ProxyB ProxyC TargetA TargetB TargetC x x Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
  • 20. Identity Preserving Membrane ProxyA ?ProxyB ProxyC TargetA TargetB TargetC x x Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
  • 21. Identity Preserving Membrane ProxyA ?ProxyB ProxyC TargetA TargetB TargetC x y x y Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
  • 22. Identity Preserving Membrane ProxyA ?ProxyB ProxyC TargetA TargetB TargetC x z y x z y Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 11 / 14
  • 23. Shadow Objects Handler Proxy Target Shadow proxy.x; proxy.y=1; handler.get(target, ’x’, proxy); handler.set(target, ’y’, 1, proxy); target[’x’]; target[’y’]=1; Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
  • 24. Shadow Objects Handler Proxy Target Shadow Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
  • 25. Shadow Objects Handler Proxy Target Shadow proxy.x; handler.get(target, ’x’, proxy); target[’x’]; Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
  • 26. Shadow Objects Handler Proxy Target Shadow proxy.x; proxy.y=1; handler.get(target, ’x’, proxy); handler.set(target, ’y’, 1, proxy); target[’x’]; shadow[’y’]=1; Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
  • 27. Shadow Objects Handler Proxy Target Shadow proxy.x; proxy.y=1; proxy.y; handler.get(target, ’x’, proxy); handler.set(target, ’y’, 1, proxy); handler.get(target, ’y’, proxy); target[’x’]; shadow[’y’]=1; shadow[’y’]; Meta-Level Base-Level Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 12 / 14
  • 28. Function Recompilation var x = 1; function f (){ function g (y) { var z = 1; return x+y+z; } } Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
  • 29. Function Recompilation var x = 1; function f (){ ”function g (y) { var z = 1; return x+y+z; }” } Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
  • 30. Function Recompilation var x = 1; with(sbxglobal){ eval( ”function g (y) { var z = 1; return x+y+z; }”); } Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
  • 31. Function Recompilation var x = 1; with(sbxglobal){ function g (y) { var z = 1; return x+y+z; } } Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 13 / 14
  • 32. Conclusion TreatJS: Language embedded, dynamic, higher-order contract system for full JavaScript Guarantees noninterference Sandbox: Language embedded sandbox for full JavaScript Runs JavaScript code in isolation isolation Matthias Keil, Peter Thiemann On Contracts, Sandboxes, and Proxies October 5, 2015 14 / 14