SlideShare a Scribd company logo
Sandboxing JavaScript via Libraries
and Wrappers
Phu H. Phung
University of Gothenburg, Sweden, and
University of Illinois at Chicago
About Me

• Receipt of international postdoc grant (3
years) by Swedish Research Council
(VR), employed by Univ. of Gothenburg.
• Research Associate at UIC.
• PhD in Computer Science in 2011 from
Chalmers University, Sweden.

Hosted by OWASP & the NYC Chapter
• Selected research projects
– European WebSand (complete)
• End-to-end secure web framework

– Secure Web Advertisements, funded by NSF
(on-going)
– Defensive Optimizing Compiler, funded by
DARPA (on-going)

Hosted by OWASP & the NYC Chapter
This talk

• Based on the two published papers:
– PH Phung, L Desmet. A two-tier sandbox
architecture for untrusted JavaScript, invited
paper, JSTools’12.
– P Agten, S Van Acker, Y Brondsema, PH Phung, L
Desmet, F Piessens. JSand: complete client-side
sandboxing of third-party JavaScript without
browser modifications, ACSAC’12.
92% of all websites use JavaScript
[w3techs.com]

“88.45% of the Alexa top 10,000 web
sites included at least one remote
JavaScript library”
CCS’12

5
Third-party JavaScript is
everywhere
• Advertisements
– Adhese ad network

• Social web
–
–
–
–

Facebook Connect
Google+
Twitter
Feedsburner

• Tracking
– Scorecardresearch

• Web Analytics
– Yahoo! Web Analytics
– Google Analytics

• …
6
Two basic composition
techniques

Iframe integration
<html><body>
…
<iframe src=“http://3rdparty.com/frame.html”>
</iframe>
…
</body></html>

3rd party

7
Two basic composition techniques

Script inclusion
<html><body>
…
<script src=“http://3rdparty.com/script.js”>
</script>
…
</body></html>
3rd party

8
Third-party JavaScript issues

• Third-party script inclusion run with the same
privilege of the hosting page.
• Security issues:
– Malicious third-party code
– Trusted third-party is compromised
– Confidentiality, integrity, and other security risks

9
Difficult issues with JavaScript

• JavaScript is a powerful language, but the language
design is bad for security, e.g.:
– Dynamic scripts: document.write, eval, ...
– Encapsulation leakage
– ...
A lot of
<script>
document.write(‘<scr’);
document.write(‘ipt> malic’);
var i= 1;
document.write(‘ious code; </sc’);
document.write(‘ript>’);
</script>

attacks were
launched in
practice

<script> malicious code; </script>

10
Malicious third-party JavaScript
example

The most reliable, cost effective
method to inject evil code is to buy
an ad.
Principles of Security. Douglas Crockford
http://fromonesrc.com/blog/page/2/
An attack scenario

Million Browser Botnet
(July 2013)
– Leverage Advertising
Networks using JavaScript
to launch Application-Level
Jeremiah Grossman & Matt Johansen
DDoS
WhiteHat SECURITY
– Paid on 2 ad networks for
displaying treacherous
advertisements on pages visited
by hundreds of thousands of people

– One day, got 13.6 million views of the ads, just spent less
than $100
12
State-of-the-art

• Limit third-party code to safe subset of JavaScript
– Facebook JS, ADSafe, ADSafety, ...
No compatibility with existing scripts

• Browser-based sandboxing solutions
– ConScript, WebJail, Contego, ...
Browser modifications imply short-term
deployment issues

• Server-side transformations of scripts to be included
– Google Caja, BrowserShield, ...
No direct script delivery to browser
Great runtime overhead
13
Our approach

• A sandbox model for third-party JavaScript
– Using only JS libraries and wrappers
– Whitelist (least-privilege) implementation approach
• Only properties and objects defined in policies are
available to the untrusted code

– No browser modification is required
– The third-party code is keep in original
– Easily dealing with dynamic features of JavaScript

“Lightweight Self-Protecting JavaScript”, ASIACCS’09
14
Two-tier sandbox architecture
Base-line API
implementation,
in e.g. `api.js’ file
Sandbox running policy
code, defined in a
separate JS e.g. `policy.js’

Sandbox running
untrusted
code, defined in a
separate file e.g.
`untrusted.js’

The policy code can only access the
base-line API and provided
wrapper functions

The untrusted code can only
access objects returned by
the outer sandbox

JavaScript
environment,
e.g. the DOM
Two-tier sandbox architecture

var api = loadAPI(…);
var outerSandbox =
cajaVM.compileModule(policyCode);
var enforcedAPI = outerSandbox(api);
var innerSandbox =
cajaVM.compileModule(untrustedCode);

innerSandbox(enforcedAPI);
16
The architecture in multipleprincipal untrusted code

Base-line API
implementation,
in e.g. `api.js’ file

Policy 1
untrusted

Policy 2

untrusted

Policy 3

untrusted
17
Sandboxing untrusted code

• Use Secure ECMAScript (SES) library
developed by Google Caja team
– Load a piece of code to execute within an isolated
environment
• The code can only interact with the outside world via provided
APIs

var api = {...}; //constructing
var makeSandbox =
cajaVM.compileModule(untrustedCodeSrc);
var sandboxed = makeSandbox(api);
18
Isolation technique: The SES library

Object-capability environment
• Scripts can access
– Objects they create themselves
– Objects explicitly handed to them

untrustedCode
API
sandbox

Global
context

19
Isolation technique: The SES library

20
Base-line APIs implementation

• Create a Virtual DOM
– Intercepting wrapper around real DOM
– Use Harmony Proxies to generically intercept
property accesses on objects

• Virtual DOM implementation uses the
Membrane Pattern
– Wrap any object passed from DOM to sandbox (return
values)
– Unwrap any object passed from sandbox to DOM
(arguments)
21
Wrapper example

22
Policy definition

• Base-line APIs implementation
– Can enforce coarse-grained, generic policies, e.g.:
• Sanitize HTML
• Ensure complete mediation

• Fine-grained policies for multiple untrusted
JavaScript code
– Modular, principal-specific, e.g.: script1 is allowed to read/write
elemt_A, script2 is allowed to read elemt_A
– Stafeful, e.g.: limit the number of popups to 3
– Cross-principal stateful policies, e.g: after script1 write to
elemt_A, disallow access from script2 to elemt_A
23
Deployment model

• Untrusted code is loaded into a string variable
– Using server-side proxy + XMLHttpRequest (to
overcome same origin policy)
– CORS (Cross-Origin Resource Sharing)
/UMP(Uniform Messaging Policy) headers set by
the script provider
<script src=
“http://3rdparty.com/script.js”>
</script>

before

<script src=“ses.js”></script>
<script src=“api.js”></script>
<script src=“policy0.js”></script>
<script>
var script = get(“http://3rdparty.com/script.js”);
ses.execute(script,policy0);
</script>
Secure dynamic script
evaluation

• Special handlers to intercept all methods that
allow script tags to be added
– node.appendChild, node.insertBefore, node.replaceCh
ild, node.insertAfter
– document.write, …
– Event handlers in HTML, e.g.
<…onclick=“javascript:xyz(…)”>

1. Parse partial DOM tree/HTML
2. Execute scripts in the sandbox environment
25
Dynamic script loading in
JavaScript

• Example from Google Maps

26
Different parsing techniques

• Via a sandboxed iframe
1. Create sandbox iframe
2. Set content via srcdoc attribute
– Better performance
– Parsed exactly as will be interpreted by browser
– Executed asynchronously

• (Alternative) Via a HTML parsing library in
JavaScript

27
Loading additional code in the
sandbox

• External code needs to be executed in a
previously set up sandbox
– Loading API + glue code
– Dynamic script loading

• Two new operations:
– innerEval(code)
– innerLoadScript(url)

28
Case studies

• Single principal code

• Multiple-principal code
– Context-aware ads
29
Implementation challenges

• Legacy scripts need additional preprocessing to be compatible with the
framework
– Secure ECMAScript restrictions
• A subset of ECMAScritp strict mode
• Global variables aliased as window
properties
• No ‘this’ auto coercion
30
JS transformation examples

31
Summary

– A client-side JavaScript architecture for
untrusted JavaScript
• Only using libraries and wrappers

– Complete mediation using Secure
ECMAScript
• DOM node operations
• JavaScript APIs

– Backward compatibility
• No browser modifications
• Direct script delivery to the browser
• Support for legacy scripts
32
33

More Related Content

ODP
Csrf not-all-defenses-are-created-equal
PDF
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
PPTX
Web security-–-everything-we-know-is-wrong-eoin-keary
PPTX
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
PPT
Django (Web Applications that are Secure by Default)
PPTX
Breaking the cyber kill chain!
PPTX
[Wroclaw #2] Web Application Security Headers
PDF
Defeating Cross-Site Scripting with Content Security Policy (updated)
Csrf not-all-defenses-are-created-equal
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
Web security-–-everything-we-know-is-wrong-eoin-keary
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Django (Web Applications that are Secure by Default)
Breaking the cyber kill chain!
[Wroclaw #2] Web Application Security Headers
Defeating Cross-Site Scripting with Content Security Policy (updated)

What's hot (20)

PDF
When Ajax Attacks! Web application security fundamentals
PPTX
Cross Site Scripting (XSS)
PPTX
MITM Attacks on HTTPS: Another Perspective
PPTX
Advanced Client Side Exploitation Using BeEF
 
PPTX
Owasp Top 10 A3: Cross Site Scripting (XSS)
PDF
Securing your AngularJS Application
PPTX
Devouring Security XML Attack surface and Defences
PDF
Introduction to Mod security session April 2016
PPTX
Java script, security and you - Tri-Cities Javascript Developers Group
PDF
Java ist doch schon sicher?!
PDF
Modern Web Application Defense
PDF
How to Make Your NodeJS Application Secure (24 Best Security Tips )
PPTX
Case Study of Django: Web Frameworks that are Secure by Default
PPTX
Nguyen phuong truong anh a story of bug bounty hunter
PDF
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
PDF
Node JS reverse shell
KEY
mod_security introduction at study2study #3
KEY
DVWA BruCON Workshop
PDF
Abusing & Securing XPC in macOS apps
PPTX
DVWA(Damn Vulnerabilities Web Application)
When Ajax Attacks! Web application security fundamentals
Cross Site Scripting (XSS)
MITM Attacks on HTTPS: Another Perspective
Advanced Client Side Exploitation Using BeEF
 
Owasp Top 10 A3: Cross Site Scripting (XSS)
Securing your AngularJS Application
Devouring Security XML Attack surface and Defences
Introduction to Mod security session April 2016
Java script, security and you - Tri-Cities Javascript Developers Group
Java ist doch schon sicher?!
Modern Web Application Defense
How to Make Your NodeJS Application Secure (24 Best Security Tips )
Case Study of Django: Web Frameworks that are Secure by Default
Nguyen phuong truong anh a story of bug bounty hunter
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Node JS reverse shell
mod_security introduction at study2study #3
DVWA BruCON Workshop
Abusing & Securing XPC in macOS apps
DVWA(Damn Vulnerabilities Web Application)
Ad

Similar to Phu appsec13 (20)

PPTX
Web security: Securing Untrusted Web Content in Browsers
PPTX
Web security: Securing untrusted web content at browsers
PDF
Securing TodoMVC Using the Web Cryptography API
PPTX
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
PDF
Waf.js: How to Protect Web Applications using JavaScript
PDF
Building Client-Side Attacks with HTML5 Features
PDF
OWASP SF - Reviewing Modern JavaScript Applications
PDF
Testing NodeJS Security
PDF
Automated JavaScript Deobfuscation - PacSec 2007
PPTX
Fine-grained policy enforcement for untrusted software
PDF
Always on! Or not?
KEY
Cross Site Scripting - Mozilla Security Learning Center
PDF
XSS Injection Vulnerabilities
PPTX
Cross site scripting
PDF
Java script and web cryptography (cf.objective)
PPTX
W3 conf hill-html5-security-realities
PPTX
Warning Ahead: SecurityStorms are Brewing in Your JavaScript
PPTX
Docker practical solutions
PPTX
Hacking WebApps for fun and profit : how to approach a target?
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing untrusted web content at browsers
Securing TodoMVC Using the Web Cryptography API
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
Waf.js: How to Protect Web Applications using JavaScript
Building Client-Side Attacks with HTML5 Features
OWASP SF - Reviewing Modern JavaScript Applications
Testing NodeJS Security
Automated JavaScript Deobfuscation - PacSec 2007
Fine-grained policy enforcement for untrusted software
Always on! Or not?
Cross Site Scripting - Mozilla Security Learning Center
XSS Injection Vulnerabilities
Cross site scripting
Java script and web cryptography (cf.objective)
W3 conf hill-html5-security-realities
Warning Ahead: SecurityStorms are Brewing in Your JavaScript
Docker practical solutions
Hacking WebApps for fun and profit : how to approach a target?
Ad

More from drewz lin (20)

PDF
Via forensics appsecusa-nov-2013
PPTX
Owasp2013 johannesullrich
PDF
Owasp advanced mobile-application-code-review-techniques-v0.2
PPTX
I mas appsecusa-nov13-v2
PPTX
Chuck willis-owaspbwa-beyond-1.0-app secusa-2013-11-21
PPTX
Appsec usa roberthansen
PDF
Appsec usa2013 js_libinsecurity_stefanodipaola
PPT
Appsec2013 presentation-dickson final-with_all_final_edits
PPTX
Appsec2013 presentation
PPTX
Appsec 2013-krehel-ondrej-forensic-investigations-of-web-exploitations
PPTX
Appsec2013 assurance tagging-robert martin
PPTX
Amol scadaowasp
PPTX
Agile sdlc-v1.1-owasp-app sec-usa
PPTX
Vulnex app secusa2013
PDF
基于虚拟化技术的分布式软件测试框架
PPTX
新浪微博稳定性经验谈
PPTX
无线App的性能分析和监控实践 rickyqiu
PPT
网易移动自动化测试实践(孔庆云)
PDF
天猫后端技术架构优化实践
PPTX
天猫大促性能测试实践 耿电
Via forensics appsecusa-nov-2013
Owasp2013 johannesullrich
Owasp advanced mobile-application-code-review-techniques-v0.2
I mas appsecusa-nov13-v2
Chuck willis-owaspbwa-beyond-1.0-app secusa-2013-11-21
Appsec usa roberthansen
Appsec usa2013 js_libinsecurity_stefanodipaola
Appsec2013 presentation-dickson final-with_all_final_edits
Appsec2013 presentation
Appsec 2013-krehel-ondrej-forensic-investigations-of-web-exploitations
Appsec2013 assurance tagging-robert martin
Amol scadaowasp
Agile sdlc-v1.1-owasp-app sec-usa
Vulnex app secusa2013
基于虚拟化技术的分布式软件测试框架
新浪微博稳定性经验谈
无线App的性能分析和监控实践 rickyqiu
网易移动自动化测试实践(孔庆云)
天猫后端技术架构优化实践
天猫大促性能测试实践 耿电

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
Big Data Technologies - Introduction.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Empathic Computing: Creating Shared Understanding
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Big Data Technologies - Introduction.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Digital-Transformation-Roadmap-for-Companies.pptx
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25 Week I
Network Security Unit 5.pdf for BCA BBA.
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Building Integrated photovoltaic BIPV_UPV.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Encapsulation_ Review paper, used for researhc scholars
Empathic Computing: Creating Shared Understanding
Mobile App Security Testing_ A Comprehensive Guide.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Phu appsec13

  • 1. Sandboxing JavaScript via Libraries and Wrappers Phu H. Phung University of Gothenburg, Sweden, and University of Illinois at Chicago
  • 2. About Me • Receipt of international postdoc grant (3 years) by Swedish Research Council (VR), employed by Univ. of Gothenburg. • Research Associate at UIC. • PhD in Computer Science in 2011 from Chalmers University, Sweden. Hosted by OWASP & the NYC Chapter
  • 3. • Selected research projects – European WebSand (complete) • End-to-end secure web framework – Secure Web Advertisements, funded by NSF (on-going) – Defensive Optimizing Compiler, funded by DARPA (on-going) Hosted by OWASP & the NYC Chapter
  • 4. This talk • Based on the two published papers: – PH Phung, L Desmet. A two-tier sandbox architecture for untrusted JavaScript, invited paper, JSTools’12. – P Agten, S Van Acker, Y Brondsema, PH Phung, L Desmet, F Piessens. JSand: complete client-side sandboxing of third-party JavaScript without browser modifications, ACSAC’12.
  • 5. 92% of all websites use JavaScript [w3techs.com] “88.45% of the Alexa top 10,000 web sites included at least one remote JavaScript library” CCS’12 5
  • 6. Third-party JavaScript is everywhere • Advertisements – Adhese ad network • Social web – – – – Facebook Connect Google+ Twitter Feedsburner • Tracking – Scorecardresearch • Web Analytics – Yahoo! Web Analytics – Google Analytics • … 6
  • 7. Two basic composition techniques Iframe integration <html><body> … <iframe src=“http://3rdparty.com/frame.html”> </iframe> … </body></html> 3rd party 7
  • 8. Two basic composition techniques Script inclusion <html><body> … <script src=“http://3rdparty.com/script.js”> </script> … </body></html> 3rd party 8
  • 9. Third-party JavaScript issues • Third-party script inclusion run with the same privilege of the hosting page. • Security issues: – Malicious third-party code – Trusted third-party is compromised – Confidentiality, integrity, and other security risks 9
  • 10. Difficult issues with JavaScript • JavaScript is a powerful language, but the language design is bad for security, e.g.: – Dynamic scripts: document.write, eval, ... – Encapsulation leakage – ... A lot of <script> document.write(‘<scr’); document.write(‘ipt> malic’); var i= 1; document.write(‘ious code; </sc’); document.write(‘ript>’); </script> attacks were launched in practice <script> malicious code; </script> 10
  • 11. Malicious third-party JavaScript example The most reliable, cost effective method to inject evil code is to buy an ad. Principles of Security. Douglas Crockford http://fromonesrc.com/blog/page/2/
  • 12. An attack scenario Million Browser Botnet (July 2013) – Leverage Advertising Networks using JavaScript to launch Application-Level Jeremiah Grossman & Matt Johansen DDoS WhiteHat SECURITY – Paid on 2 ad networks for displaying treacherous advertisements on pages visited by hundreds of thousands of people – One day, got 13.6 million views of the ads, just spent less than $100 12
  • 13. State-of-the-art • Limit third-party code to safe subset of JavaScript – Facebook JS, ADSafe, ADSafety, ... No compatibility with existing scripts • Browser-based sandboxing solutions – ConScript, WebJail, Contego, ... Browser modifications imply short-term deployment issues • Server-side transformations of scripts to be included – Google Caja, BrowserShield, ... No direct script delivery to browser Great runtime overhead 13
  • 14. Our approach • A sandbox model for third-party JavaScript – Using only JS libraries and wrappers – Whitelist (least-privilege) implementation approach • Only properties and objects defined in policies are available to the untrusted code – No browser modification is required – The third-party code is keep in original – Easily dealing with dynamic features of JavaScript “Lightweight Self-Protecting JavaScript”, ASIACCS’09 14
  • 15. Two-tier sandbox architecture Base-line API implementation, in e.g. `api.js’ file Sandbox running policy code, defined in a separate JS e.g. `policy.js’ Sandbox running untrusted code, defined in a separate file e.g. `untrusted.js’ The policy code can only access the base-line API and provided wrapper functions The untrusted code can only access objects returned by the outer sandbox JavaScript environment, e.g. the DOM
  • 16. Two-tier sandbox architecture var api = loadAPI(…); var outerSandbox = cajaVM.compileModule(policyCode); var enforcedAPI = outerSandbox(api); var innerSandbox = cajaVM.compileModule(untrustedCode); innerSandbox(enforcedAPI); 16
  • 17. The architecture in multipleprincipal untrusted code Base-line API implementation, in e.g. `api.js’ file Policy 1 untrusted Policy 2 untrusted Policy 3 untrusted 17
  • 18. Sandboxing untrusted code • Use Secure ECMAScript (SES) library developed by Google Caja team – Load a piece of code to execute within an isolated environment • The code can only interact with the outside world via provided APIs var api = {...}; //constructing var makeSandbox = cajaVM.compileModule(untrustedCodeSrc); var sandboxed = makeSandbox(api); 18
  • 19. Isolation technique: The SES library Object-capability environment • Scripts can access – Objects they create themselves – Objects explicitly handed to them untrustedCode API sandbox Global context 19
  • 20. Isolation technique: The SES library 20
  • 21. Base-line APIs implementation • Create a Virtual DOM – Intercepting wrapper around real DOM – Use Harmony Proxies to generically intercept property accesses on objects • Virtual DOM implementation uses the Membrane Pattern – Wrap any object passed from DOM to sandbox (return values) – Unwrap any object passed from sandbox to DOM (arguments) 21
  • 23. Policy definition • Base-line APIs implementation – Can enforce coarse-grained, generic policies, e.g.: • Sanitize HTML • Ensure complete mediation • Fine-grained policies for multiple untrusted JavaScript code – Modular, principal-specific, e.g.: script1 is allowed to read/write elemt_A, script2 is allowed to read elemt_A – Stafeful, e.g.: limit the number of popups to 3 – Cross-principal stateful policies, e.g: after script1 write to elemt_A, disallow access from script2 to elemt_A 23
  • 24. Deployment model • Untrusted code is loaded into a string variable – Using server-side proxy + XMLHttpRequest (to overcome same origin policy) – CORS (Cross-Origin Resource Sharing) /UMP(Uniform Messaging Policy) headers set by the script provider <script src= “http://3rdparty.com/script.js”> </script> before <script src=“ses.js”></script> <script src=“api.js”></script> <script src=“policy0.js”></script> <script> var script = get(“http://3rdparty.com/script.js”); ses.execute(script,policy0); </script>
  • 25. Secure dynamic script evaluation • Special handlers to intercept all methods that allow script tags to be added – node.appendChild, node.insertBefore, node.replaceCh ild, node.insertAfter – document.write, … – Event handlers in HTML, e.g. <…onclick=“javascript:xyz(…)”> 1. Parse partial DOM tree/HTML 2. Execute scripts in the sandbox environment 25
  • 26. Dynamic script loading in JavaScript • Example from Google Maps 26
  • 27. Different parsing techniques • Via a sandboxed iframe 1. Create sandbox iframe 2. Set content via srcdoc attribute – Better performance – Parsed exactly as will be interpreted by browser – Executed asynchronously • (Alternative) Via a HTML parsing library in JavaScript 27
  • 28. Loading additional code in the sandbox • External code needs to be executed in a previously set up sandbox – Loading API + glue code – Dynamic script loading • Two new operations: – innerEval(code) – innerLoadScript(url) 28
  • 29. Case studies • Single principal code • Multiple-principal code – Context-aware ads 29
  • 30. Implementation challenges • Legacy scripts need additional preprocessing to be compatible with the framework – Secure ECMAScript restrictions • A subset of ECMAScritp strict mode • Global variables aliased as window properties • No ‘this’ auto coercion 30
  • 32. Summary – A client-side JavaScript architecture for untrusted JavaScript • Only using libraries and wrappers – Complete mediation using Secure ECMAScript • DOM node operations • JavaScript APIs – Backward compatibility • No browser modifications • Direct script delivery to the browser • Support for legacy scripts 32
  • 33. 33