Web security: Securing Untrusted Web Content in Browsers

Phú Phùng
Phú PhùngResearch Associate at UIC
ACM Chicago Chapter seminar 
September 10, 2014 
Loyola University Chicago 
Computer Science Department 
Web security: Securing 
untrusted web content at 
browsers 
Phu H. Phung 
University of Illinois at Chicago
Web page is rendered at 
browsers 
• Web pages contain JavaScript code, a 
scripting language run at browsers 
• JavaScript can provide a lot of functionalities 
rich interactions 
2
92% of all websites use 
JavaScript [w3techs.com] 
3 
“88.45% of the Alexa top 10,000 
web sites included at least one 
remote JavaScript library” 
CCS’12
Web-based mobile 
applications 
• HTML5 + JavaScript is a new trend for mobile 
developers 
o Cross-platform development, 
“Write one run everywhere” 
4
Third-party JavaScript is 
everywhere 
• Advertisements 
o Adhese ad network 
• Social web 
o Facebook Connect 
o Google+ 
o Twitter 
o Feedsburner 
• Tracking 
o Scorecardresearch 
• Web Analytics 
o Yahoo! Web 
Analytics 
o Google Analytics 
• … 
5
Two basic composition 
techniques 
• Iframe integration 
6 
<html><body> 
… 
<iframe 
src=“http://3rdparty.com/frame.html”> 
</iframe> 
… 
</body></html> 
3rd party
Two basic composition 
techniques 
7 
<html><body> 
… 
<script src=“http://3rdparty.com/script.js”> 
</script> 
… 
</body></html> 
3rd party 
Script inclusion
Third-party JavaScript issues 
• Third-party script inclusion run with the 
same privilege of the hosting page. 
• Security issues: 
o Malicious third-party code 
o Trusted third-party is compromised 
o Confidentiality, integrity, and other 
security risks 
8
Difficult issues with 
JavaScript 
• JavaScript is a powerful language, but the 
language design is bad for security, e.g.: 
o Dynamic scripts: document.write, eval, ... 
o Encapsulation leakage 
o ... 
9 
A lot of 
<script> 
document.write(‘<attacks scr’); 
were 
document.write(‘ipt> malic’); 
var i= 1; 
launched in 
document.write(‘ious code; </sc’); 
document.write(‘ript>’); 
practice 
</script> 
<script> malicious code; </script>
Samy attack on Myspace 
• MySpace tries to 
filter out JavaScript 
code in user data 
• BUT: The malicious 
code was injected in a 
“strange” way that 
escapes the filter 
10 
<div id=mycode style="BACKGROUND: url('java 
script:eval(document.all.mycode.expr)')" 
expr="var B=String.fromCharCode(34);………"> 
</div>
Another real world attack 
• Million Browser Botnet 
(July 2013) 
o Leverage Advertising 
Networks using JavaScript 
to launch Application-Level 
DDoS 
o Paid on 2 ad networks for 
Jeremiah Grossman & Matt Johansen 
WhiteHat SECURITY 
displaying treacherous 
advertisements on pages visited 
by hundreds of thousands of people 
(Malicious code run automatically without user 
knowledge) 
11
A recent attack on Reuter 
homepage (June 2014) 
12 
• Reuters website was compromised by the 
Syrian Electronic Army 
o By code injection via a compromised third party 
ad network.
State-of-the-art 
• Limit third-party code to safe subset of JavaScript 
o Facebook JS, ADSafe, ADSafety, ... 
• Browser-based sandboxing solutions 
o ConScript, WebJail, Contego, ... 
• Server-side transformations of scripts to be included 
o Google Caja, BrowserShield, ... 
13 
No compatibility with existing scripts 
Browser modifications imply short-term 
deployment issues 
No direct script delivery to browser 
Great runtime overhead
Our approach 
Lightweight Self-Protecting JavaScript 
• A behavioral sandbox model for 
JavaScript 
o Using only JS libraries and wrappers 
o No browser modification is required 
o The JS code is keep in original 
o Easily dealing with dynamic features of 
JavaScript 
14
API call interception 
15 
JavaScript execution environment 
(e.g. browsers) 
Native implementations 
alert 
implementation 
code pointers User 
functions 
alert(‘Hi!’) window.alert 
unique 
alert 
wrapper 
(+policy code) 
Attacker code 
alert = 
function(){...}; 
alert 
wrapper 
(enforced by SPJS)
Deployment illustration 
16 
<html> 
<head> 
<script src=“selfprotectingJS.js"></script> 
<title>Self-protecting JavaScript </title> 
<meta content=…> <style>…</style> 
<script>…</script> 
<!-- more heading setting --> 
70 
60 
50 
</head> 
<body> 
<script type="text/javascript"> 
(function() {..})(); 
</script> 
<!-- the content of page --> 
</body> 
40 
30 
20 
10 
</html> 
Policy code 
and 
enforcement 
code defined 
in a text file 
The enforcement code can 
be deployed anywhere: 
server side, proxy or 
browser plug-in, i.e. no 
need for a modified 
browser 
The orgininal 
code is not 
syntactically 
modified 
6.33 
66.03 
0 
Self-Protecting BrowserShield 
Slowdown (times) 
Runtime overhead
Effectiveness 
• Defend almost all of the known XSS attacker 
vectors 
o 34 attack vectors over 38 successful attack 
vectors 
• Provide Security Policy Patterns to build realistic 
policies e.g. prevent the attack of Firesheep on 
Facebook 
• Defend real-world exploits 
o phpBB 2.0.18 vulnerabilities – a stored XSS attack 
o WebCal vulnerabilities –a reflected XSS attack 
17
Lightweight Self-Protecting 
JavaScript 
Lightweight Self-Protecting 
JavaScript 
Safe Wrappers and Sane 
Policies for 
Self-Protecting JavaScript
SPJS with Untrusted JavaScript 
• No privilege 
distinguish between 
hosting code and 
external code 
19 
Self-Protecting 
JavaScript Code 
TRUSTED 
UNTRUSTED 
Hosting 
code 
Hosting 
code 
Hosting 
code 
external 
code 
external 
code
Goals 
• Deploy SPJS in the context of untrusted JS 
o Load and execute untrusted code without pre-processing 
the code 
o No browser modification is required 
• Enforce modular and fined-grained, stateful 
security policies for a piece of untrusted 
code 
o Protect the hosting page from untrusted code 
• Robust to potential flaws in security policies 
o Bad written policies might not break security 
20
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 
22 
var api = loadAPI(…); 
var outerSandbox = 
cajaVM.compileModule(policyCode); 
var enforcedAPI = outerSandbox(api); 
var innerSandbox = 
cajaVM.compileModule(untrustedCode); 
innerSandbox(enforcedAPI);
The architecture in multiple-principal 
untrusted code 
23 
Policy 2 
Policy 1 
untrusted 
Policy 3 
untrusted 
Base-line API 
implementation 
in e.g. `api.js’ 
file 
untrusted
Sandboxing untrusted code 
• Use Secure ECMAScript (SES) library 
developed by Google Caja team 
o Load a piece of code to execute within an 
isolated environment 
• The code can only interact with the outside world via 
provided APIs 
24 
var api = {...}; //constructing 
var makeSandbox = 
cajaVM.compileModule(untrustedCodeSrc); 
var sandboxed = makeSandbox(api);
Isolation technique: The SES 
library 
Object-capability environment 
• Scripts can access 
o Objects they create themselves 
o Objects explicitly handed to them 
25 
API 
Global 
context 
untrustedCode 
sandbox
Isolation technique: The SES 
library 
26
Policy definition 
• Base-line APIs implementation 
o Can enforce coarse-grained, generic policies, e.g.: 
• Sanitize HTML 
• Ensure complete mediation 
• Fine-grained policies for multiple 
untrusted JavaScript code 
o Modular, principal-specific, e.g.: script1 is allowed to 
read/write reg_A, script2 is allowed to read reg_A 
o Stafeful, e.g.: limit the number of popups to 3 
o Cross-principal stateful policies, e.g: after script1 write 
to reg_A, disallow access from script2 to reg_A 
27
Base-line APIs 
implementation 
• Create a Virtual DOM 
o Intercepting wrapper around real DOM 
o Consult security policy on each operation 
o Use Harmony Proxies to generically intercept 
property accesses on objects 
• Virtual DOM implementation uses the 
Membrane Pattern 
o Wrap any object passed from DOM to sandbox 
(return values) 
o Unwrap any object passed from sandbox to DOM 
(arguments) 
28
Deployment model 
• Untrusted code is loaded into a string 
variable 
o Using server-side proxy + XMLHttpRequest (to 
overcome same origin policy) 
o CORS/UMP headers set by the script provider 
29 
<script src= 
“http://3rdparty.com/script.js”> 
</script> 
<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); 
before </script> 
after
Secure dynamic script 
evaluation 
• Special handlers to intercept all methods 
that allow script tags to be added 
o node.appendChild, node.insertBefore, 
node.replaceChild, node.insertAfter 
o document.write, … 
o Event handlers in HTML, e.g. 
<…onclick=“javascript:xyz(…)”> 
1. Parse partial DOM tree/HTML 
2. Execute scripts in the sandbox 
environment 
30
Case studies 
• Single principal code 
• Multiple-principal code 
o Context-aware ads 
31
Two-tier Sandbox 
Architecture 
A Two-tier Sandbox 
Architecture for 
Untrusted JavaScript 
JSand: complete client-side 
sandboxing of third-party 
JavaScript without 
browser modifications
A recent published work 
Phu H. Phung, Maliheh Monshizadeh, Meera Sridhar, Kevin W. 
Hamlen, and V.N. Venkatakrishnan. 
Between Worlds: Securing Mixed JavaScript/ActionScript Multi-party 
Web Content. IEEE Transactions on Dependable and 
Secure Computing (TDSC), forthcoming. 
33
Web security: Securing Untrusted Web Content in Browsers
Extra slides 
35
Wrapper example 
36
Different parsing techniques 
• Via a sandboxed iframe 
1. Create sandbox iframe 
2. Set content via srcdoc attribute 
o More performance 
o Parsed exactly as will be interpreted by browser 
o Executed asynchronously 
• (Alternative) Via a HTML parsing library 
in JavaScript 
37
Loading additional code in 
the sandbox 
• Several use cases require external 
code to be executed in a previously 
set up sandbox 
o Loading API + glue code 
o Dynamic script loading 
• Two new operations: 
o innerEval(code) 
o innerLoadScript(url) 
38
1 of 38

Recommended

Web security: Securing untrusted web content at browsers by
Web security: Securing untrusted web content at browsersWeb security: Securing untrusted web content at browsers
Web security: Securing untrusted web content at browsersPhú Phùng
801 views49 slides
Looking for Vulnerable Code. Vlad Savitsky by
Looking for Vulnerable Code. Vlad SavitskyLooking for Vulnerable Code. Vlad Savitsky
Looking for Vulnerable Code. Vlad SavitskyVlad Savitsky
1.2K views41 slides
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf by
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolfDefeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolfdrewz lin
1.6K views24 slides
Javascript Security by
Javascript SecurityJavascript Security
Javascript Securityjgrahamc
13.1K views41 slides
JavaScript Security by
JavaScript SecurityJavaScript Security
JavaScript SecurityJason Harwig
2.4K views81 slides
Bypass SOP, Theft Your Data - XSS Allstars from Japan / OWASP AppSec APAC 2014 by
Bypass SOP, Theft Your Data - XSS Allstars from Japan / OWASP AppSec APAC 2014Bypass SOP, Theft Your Data - XSS Allstars from Japan / OWASP AppSec APAC 2014
Bypass SOP, Theft Your Data - XSS Allstars from Japan / OWASP AppSec APAC 2014Yosuke HASEGAWA
7.7K views18 slides

More Related Content

What's hot

Client-side JavaScript Vulnerabilities by
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript VulnerabilitiesOry Segal
28.1K views24 slides
Phu appsec13 by
Phu appsec13Phu appsec13
Phu appsec13drewz lin
1.2K views33 slides
Hack Into Drupal Sites (or, How to Secure Your Drupal Site) by
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)nyccamp
39.1K views46 slides
Web Apps Security by
Web Apps SecurityWeb Apps Security
Web Apps SecurityVictor Bucutea
1.5K views35 slides
Secure coding in C# by
Secure coding in C#Secure coding in C#
Secure coding in C#Siddharth Bezalwar
7.1K views32 slides
XSS Injection Vulnerabilities by
XSS Injection VulnerabilitiesXSS Injection Vulnerabilities
XSS Injection VulnerabilitiesMindfire Solutions
3.5K views20 slides

What's hot(20)

Client-side JavaScript Vulnerabilities by Ory Segal
Client-side JavaScript VulnerabilitiesClient-side JavaScript Vulnerabilities
Client-side JavaScript Vulnerabilities
Ory Segal28.1K views
Phu appsec13 by drewz lin
Phu appsec13Phu appsec13
Phu appsec13
drewz lin1.2K views
Hack Into Drupal Sites (or, How to Secure Your Drupal Site) by nyccamp
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
Hack Into Drupal Sites (or, How to Secure Your Drupal Site)
nyccamp39.1K views
Dev and Blind - Attacking the weakest Link in IT Security by Mario Heiderich
Dev and Blind - Attacking the weakest Link in IT SecurityDev and Blind - Attacking the weakest Link in IT Security
Dev and Blind - Attacking the weakest Link in IT Security
Mario Heiderich5.6K views
Defeating Cross-Site Scripting with Content Security Policy (updated) by Francois Marier
Defeating Cross-Site Scripting with Content Security Policy (updated)Defeating Cross-Site Scripting with Content Security Policy (updated)
Defeating Cross-Site Scripting with Content Security Policy (updated)
Francois Marier3.3K views
Securing your AngularJS Application by Philippe De Ryck
Securing your AngularJS ApplicationSecuring your AngularJS Application
Securing your AngularJS Application
Philippe De Ryck2.7K views
XSS - Do you know EVERYTHING? by Yurii Bilyk
XSS - Do you know EVERYTHING?XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?
Yurii Bilyk4.8K views
Post XSS Exploitation : Advanced Attacks and Remedies by Adwiteeya Agrawal
Post XSS Exploitation : Advanced Attacks and RemediesPost XSS Exploitation : Advanced Attacks and Remedies
Post XSS Exploitation : Advanced Attacks and Remedies
Adwiteeya Agrawal3.4K views
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining by OWASP
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-miningOWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining
OWASP160 views
OWASP San Diego Training Presentation by owaspsd
OWASP San Diego Training PresentationOWASP San Diego Training Presentation
OWASP San Diego Training Presentation
owaspsd2.4K views
Modern Web Application Defense by Frank Kim
Modern Web Application DefenseModern Web Application Defense
Modern Web Application Defense
Frank Kim1.1K views
Identifying Cross Site Scripting Vulnerabilities in Web Applications by Porfirio Tramontana
Identifying Cross Site Scripting Vulnerabilities in Web ApplicationsIdentifying Cross Site Scripting Vulnerabilities in Web Applications
Identifying Cross Site Scripting Vulnerabilities in Web Applications
Porfirio Tramontana18.4K views
Case Study of Django: Web Frameworks that are Secure by Default by Mohammed ALDOUB
Case Study of Django: Web Frameworks that are Secure by DefaultCase Study of Django: Web Frameworks that are Secure by Default
Case Study of Django: Web Frameworks that are Secure by Default
Mohammed ALDOUB9.3K views
The Image that called me - Active Content Injection with SVG Files by Mario Heiderich
The Image that called me - Active Content Injection with SVG FilesThe Image that called me - Active Content Injection with SVG Files
The Image that called me - Active Content Injection with SVG Files
Mario Heiderich10.1K views
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses by OWASP
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
OWASP198 views
Front end-security by Miao Siyu
Front end-securityFront end-security
Front end-security
Miao Siyu936 views

Viewers also liked

Fine-grained policy enforcement for untrusted software by
Fine-grained policy enforcement for untrusted softwareFine-grained policy enforcement for untrusted software
Fine-grained policy enforcement for untrusted softwarePhú Phùng
727 views19 slides
Governing Bot-as-a-Service in Sustainability Platforms - Issues and Approaches by
Governing Bot-as-a-Service in Sustainability Platforms - Issues and ApproachesGoverning Bot-as-a-Service in Sustainability Platforms - Issues and Approaches
Governing Bot-as-a-Service in Sustainability Platforms - Issues and ApproachesPhú Phùng
641 views19 slides
A Two-Tier Sandbox Architecture for Untrusted JavaScript by
A Two-Tier Sandbox Architecture for Untrusted JavaScriptA Two-Tier Sandbox Architecture for Untrusted JavaScript
A Two-Tier Sandbox Architecture for Untrusted JavaScriptPhú Phùng
3.2K views36 slides
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli... by
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...Phú Phùng
963 views25 slides
Lightweight Self-Protecting JavaScript by
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptPhú Phùng
672 views26 slides
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr... by
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...Phú Phùng
562 views20 slides

Viewers also liked(6)

Fine-grained policy enforcement for untrusted software by Phú Phùng
Fine-grained policy enforcement for untrusted softwareFine-grained policy enforcement for untrusted software
Fine-grained policy enforcement for untrusted software
Phú Phùng727 views
Governing Bot-as-a-Service in Sustainability Platforms - Issues and Approaches by Phú Phùng
Governing Bot-as-a-Service in Sustainability Platforms - Issues and ApproachesGoverning Bot-as-a-Service in Sustainability Platforms - Issues and Approaches
Governing Bot-as-a-Service in Sustainability Platforms - Issues and Approaches
Phú Phùng641 views
A Two-Tier Sandbox Architecture for Untrusted JavaScript by Phú Phùng
A Two-Tier Sandbox Architecture for Untrusted JavaScriptA Two-Tier Sandbox Architecture for Untrusted JavaScript
A Two-Tier Sandbox Architecture for Untrusted JavaScript
Phú Phùng3.2K views
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli... by Phú Phùng
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
Phú Phùng963 views
Lightweight Self-Protecting JavaScript by Phú Phùng
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScript
Phú Phùng672 views
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr... by Phú Phùng
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
Phú Phùng562 views

Similar to Web security: Securing Untrusted Web Content in Browsers

Waf.js: How to Protect Web Applications using JavaScript by
Waf.js: How to Protect Web Applications using JavaScriptWaf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptDenis Kolegov
21.4K views84 slides
OWASP SF - Reviewing Modern JavaScript Applications by
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript ApplicationsLewis Ardern
5.2K views44 slides
Devopsdays london: Let’s talk about security by
Devopsdays london:  Let’s talk about securityDevopsdays london:  Let’s talk about security
Devopsdays london: Let’s talk about securityJustin Cormack
74 views28 slides
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S... by
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...Divyanshu
796 views21 slides
Building Client-Side Attacks with HTML5 Features by
Building Client-Side Attacks with HTML5 FeaturesBuilding Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 FeaturesConviso Application Security
3.2K views30 slides
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets by
WWW/Internet 2011 - A Framework for Web 2.0 Secure WidgetsWWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
WWW/Internet 2011 - A Framework for Web 2.0 Secure WidgetsVagner Santana
551 views32 slides

Similar to Web security: Securing Untrusted Web Content in Browsers(20)

Waf.js: How to Protect Web Applications using JavaScript by Denis Kolegov
Waf.js: How to Protect Web Applications using JavaScriptWaf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScript
Denis Kolegov21.4K views
OWASP SF - Reviewing Modern JavaScript Applications by Lewis Ardern
OWASP SF - Reviewing Modern JavaScript ApplicationsOWASP SF - Reviewing Modern JavaScript Applications
OWASP SF - Reviewing Modern JavaScript Applications
Lewis Ardern5.2K views
Devopsdays london: Let’s talk about security by Justin Cormack
Devopsdays london:  Let’s talk about securityDevopsdays london:  Let’s talk about security
Devopsdays london: Let’s talk about security
Justin Cormack74 views
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S... by Divyanshu
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Browser Hacking For Fun and Profit | Null Bangalore Meetup 2019 | Divyanshu S...
Divyanshu 796 views
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets by Vagner Santana
WWW/Internet 2011 - A Framework for Web 2.0 Secure WidgetsWWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
Vagner Santana551 views
W3 conf hill-html5-security-realities by Brad Hill
W3 conf hill-html5-security-realitiesW3 conf hill-html5-security-realities
W3 conf hill-html5-security-realities
Brad Hill10.4K views
How do JavaScript frameworks impact the security of applications? by Ksenia Peguero
How do JavaScript frameworks impact the security of applications?How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?
Ksenia Peguero651 views
Rails and Content Security Policies by Matias Korhonen
Rails and Content Security PoliciesRails and Content Security Policies
Rails and Content Security Policies
Matias Korhonen1.6K views
Automated JavaScript Deobfuscation - PacSec 2007 by Stephan Chenette
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007
Stephan Chenette1.5K views
Securing TodoMVC Using the Web Cryptography API by Kevin Hakanson
Securing TodoMVC Using the Web Cryptography APISecuring TodoMVC Using the Web Cryptography API
Securing TodoMVC Using the Web Cryptography API
Kevin Hakanson3.2K views
Cross Site Scripting - Mozilla Security Learning Center by Michael Coates
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
Michael Coates6.1K views
Web Hacking Series Part 4 by Aditya Kamat
Web Hacking Series Part 4Web Hacking Series Part 4
Web Hacking Series Part 4
Aditya Kamat274 views
Groovy In the Cloud by Jim Driscoll
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
Jim Driscoll1.9K views
JavaScript - Chapter 3 - Introduction by WebStackAcademy
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy3.2K views
XSS Countermeasures in Grails by theratpack
XSS Countermeasures in GrailsXSS Countermeasures in Grails
XSS Countermeasures in Grails
theratpack3.2K views
XSS Countermeasures in Grails by OSOCO
XSS Countermeasures in GrailsXSS Countermeasures in Grails
XSS Countermeasures in Grails
OSOCO1.1K views

Recently uploaded

Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...TomHalpin9
5 views29 slides
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...Deltares
5 views28 slides
Copilot Prompting Toolkit_All Resources.pdf by
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdfRiccardo Zamana
8 views4 slides
A first look at MariaDB 11.x features and ideas on how to use them by
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use themFederico Razzoli
45 views36 slides
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...Deltares
9 views24 slides
Fleet Management Software in India by
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India Fleetable
11 views1 slide

Recently uploaded(20)

Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin95 views
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 views
Copilot Prompting Toolkit_All Resources.pdf by Riccardo Zamana
Copilot Prompting Toolkit_All Resources.pdfCopilot Prompting Toolkit_All Resources.pdf
Copilot Prompting Toolkit_All Resources.pdf
Riccardo Zamana8 views
A first look at MariaDB 11.x features and ideas on how to use them by Federico Razzoli
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use them
Federico Razzoli45 views
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J... by Deltares
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
DSD-INT 2023 3D hydrodynamic modelling of microplastic transport in lakes - J...
Deltares9 views
Fleet Management Software in India by Fleetable
Fleet Management Software in India Fleet Management Software in India
Fleet Management Software in India
Fleetable11 views
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares17 views
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI... by Marc Müller
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Dev-Cloud Conference 2023 - Continuous Deployment Showdown: Traditionelles CI...
Marc Müller37 views
SUGCON ANZ Presentation V2.1 Final.pptx by Jack Spektor
SUGCON ANZ Presentation V2.1 Final.pptxSUGCON ANZ Presentation V2.1 Final.pptx
SUGCON ANZ Presentation V2.1 Final.pptx
Jack Spektor22 views
Dapr Unleashed: Accelerating Microservice Development by Miroslav Janeski
Dapr Unleashed: Accelerating Microservice DevelopmentDapr Unleashed: Accelerating Microservice Development
Dapr Unleashed: Accelerating Microservice Development
Miroslav Janeski10 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok5 views
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols by Deltares
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - DolsDSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
DSD-INT 2023 European Digital Twin Ocean and Delft3D FM - Dols
Deltares7 views
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 views
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta5 views

Web security: Securing Untrusted Web Content in Browsers

  • 1. ACM Chicago Chapter seminar September 10, 2014 Loyola University Chicago Computer Science Department Web security: Securing untrusted web content at browsers Phu H. Phung University of Illinois at Chicago
  • 2. Web page is rendered at browsers • Web pages contain JavaScript code, a scripting language run at browsers • JavaScript can provide a lot of functionalities rich interactions 2
  • 3. 92% of all websites use JavaScript [w3techs.com] 3 “88.45% of the Alexa top 10,000 web sites included at least one remote JavaScript library” CCS’12
  • 4. Web-based mobile applications • HTML5 + JavaScript is a new trend for mobile developers o Cross-platform development, “Write one run everywhere” 4
  • 5. Third-party JavaScript is everywhere • Advertisements o Adhese ad network • Social web o Facebook Connect o Google+ o Twitter o Feedsburner • Tracking o Scorecardresearch • Web Analytics o Yahoo! Web Analytics o Google Analytics • … 5
  • 6. Two basic composition techniques • Iframe integration 6 <html><body> … <iframe src=“http://3rdparty.com/frame.html”> </iframe> … </body></html> 3rd party
  • 7. Two basic composition techniques 7 <html><body> … <script src=“http://3rdparty.com/script.js”> </script> … </body></html> 3rd party Script inclusion
  • 8. Third-party JavaScript issues • Third-party script inclusion run with the same privilege of the hosting page. • Security issues: o Malicious third-party code o Trusted third-party is compromised o Confidentiality, integrity, and other security risks 8
  • 9. Difficult issues with JavaScript • JavaScript is a powerful language, but the language design is bad for security, e.g.: o Dynamic scripts: document.write, eval, ... o Encapsulation leakage o ... 9 A lot of <script> document.write(‘<attacks scr’); were document.write(‘ipt> malic’); var i= 1; launched in document.write(‘ious code; </sc’); document.write(‘ript>’); practice </script> <script> malicious code; </script>
  • 10. Samy attack on Myspace • MySpace tries to filter out JavaScript code in user data • BUT: The malicious code was injected in a “strange” way that escapes the filter 10 <div id=mycode style="BACKGROUND: url('java script:eval(document.all.mycode.expr)')" expr="var B=String.fromCharCode(34);………"> </div>
  • 11. Another real world attack • Million Browser Botnet (July 2013) o Leverage Advertising Networks using JavaScript to launch Application-Level DDoS o Paid on 2 ad networks for Jeremiah Grossman & Matt Johansen WhiteHat SECURITY displaying treacherous advertisements on pages visited by hundreds of thousands of people (Malicious code run automatically without user knowledge) 11
  • 12. A recent attack on Reuter homepage (June 2014) 12 • Reuters website was compromised by the Syrian Electronic Army o By code injection via a compromised third party ad network.
  • 13. State-of-the-art • Limit third-party code to safe subset of JavaScript o Facebook JS, ADSafe, ADSafety, ... • Browser-based sandboxing solutions o ConScript, WebJail, Contego, ... • Server-side transformations of scripts to be included o Google Caja, BrowserShield, ... 13 No compatibility with existing scripts Browser modifications imply short-term deployment issues No direct script delivery to browser Great runtime overhead
  • 14. Our approach Lightweight Self-Protecting JavaScript • A behavioral sandbox model for JavaScript o Using only JS libraries and wrappers o No browser modification is required o The JS code is keep in original o Easily dealing with dynamic features of JavaScript 14
  • 15. API call interception 15 JavaScript execution environment (e.g. browsers) Native implementations alert implementation code pointers User functions alert(‘Hi!’) window.alert unique alert wrapper (+policy code) Attacker code alert = function(){...}; alert wrapper (enforced by SPJS)
  • 16. Deployment illustration 16 <html> <head> <script src=“selfprotectingJS.js"></script> <title>Self-protecting JavaScript </title> <meta content=…> <style>…</style> <script>…</script> <!-- more heading setting --> 70 60 50 </head> <body> <script type="text/javascript"> (function() {..})(); </script> <!-- the content of page --> </body> 40 30 20 10 </html> Policy code and enforcement code defined in a text file The enforcement code can be deployed anywhere: server side, proxy or browser plug-in, i.e. no need for a modified browser The orgininal code is not syntactically modified 6.33 66.03 0 Self-Protecting BrowserShield Slowdown (times) Runtime overhead
  • 17. Effectiveness • Defend almost all of the known XSS attacker vectors o 34 attack vectors over 38 successful attack vectors • Provide Security Policy Patterns to build realistic policies e.g. prevent the attack of Firesheep on Facebook • Defend real-world exploits o phpBB 2.0.18 vulnerabilities – a stored XSS attack o WebCal vulnerabilities –a reflected XSS attack 17
  • 18. Lightweight Self-Protecting JavaScript Lightweight Self-Protecting JavaScript Safe Wrappers and Sane Policies for Self-Protecting JavaScript
  • 19. SPJS with Untrusted JavaScript • No privilege distinguish between hosting code and external code 19 Self-Protecting JavaScript Code TRUSTED UNTRUSTED Hosting code Hosting code Hosting code external code external code
  • 20. Goals • Deploy SPJS in the context of untrusted JS o Load and execute untrusted code without pre-processing the code o No browser modification is required • Enforce modular and fined-grained, stateful security policies for a piece of untrusted code o Protect the hosting page from untrusted code • Robust to potential flaws in security policies o Bad written policies might not break security 20
  • 21. 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
  • 22. Two-tier sandbox architecture 22 var api = loadAPI(…); var outerSandbox = cajaVM.compileModule(policyCode); var enforcedAPI = outerSandbox(api); var innerSandbox = cajaVM.compileModule(untrustedCode); innerSandbox(enforcedAPI);
  • 23. The architecture in multiple-principal untrusted code 23 Policy 2 Policy 1 untrusted Policy 3 untrusted Base-line API implementation in e.g. `api.js’ file untrusted
  • 24. Sandboxing untrusted code • Use Secure ECMAScript (SES) library developed by Google Caja team o Load a piece of code to execute within an isolated environment • The code can only interact with the outside world via provided APIs 24 var api = {...}; //constructing var makeSandbox = cajaVM.compileModule(untrustedCodeSrc); var sandboxed = makeSandbox(api);
  • 25. Isolation technique: The SES library Object-capability environment • Scripts can access o Objects they create themselves o Objects explicitly handed to them 25 API Global context untrustedCode sandbox
  • 26. Isolation technique: The SES library 26
  • 27. Policy definition • Base-line APIs implementation o Can enforce coarse-grained, generic policies, e.g.: • Sanitize HTML • Ensure complete mediation • Fine-grained policies for multiple untrusted JavaScript code o Modular, principal-specific, e.g.: script1 is allowed to read/write reg_A, script2 is allowed to read reg_A o Stafeful, e.g.: limit the number of popups to 3 o Cross-principal stateful policies, e.g: after script1 write to reg_A, disallow access from script2 to reg_A 27
  • 28. Base-line APIs implementation • Create a Virtual DOM o Intercepting wrapper around real DOM o Consult security policy on each operation o Use Harmony Proxies to generically intercept property accesses on objects • Virtual DOM implementation uses the Membrane Pattern o Wrap any object passed from DOM to sandbox (return values) o Unwrap any object passed from sandbox to DOM (arguments) 28
  • 29. Deployment model • Untrusted code is loaded into a string variable o Using server-side proxy + XMLHttpRequest (to overcome same origin policy) o CORS/UMP headers set by the script provider 29 <script src= “http://3rdparty.com/script.js”> </script> <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); before </script> after
  • 30. Secure dynamic script evaluation • Special handlers to intercept all methods that allow script tags to be added o node.appendChild, node.insertBefore, node.replaceChild, node.insertAfter o document.write, … o Event handlers in HTML, e.g. <…onclick=“javascript:xyz(…)”> 1. Parse partial DOM tree/HTML 2. Execute scripts in the sandbox environment 30
  • 31. Case studies • Single principal code • Multiple-principal code o Context-aware ads 31
  • 32. Two-tier Sandbox Architecture A Two-tier Sandbox Architecture for Untrusted JavaScript JSand: complete client-side sandboxing of third-party JavaScript without browser modifications
  • 33. A recent published work Phu H. Phung, Maliheh Monshizadeh, Meera Sridhar, Kevin W. Hamlen, and V.N. Venkatakrishnan. Between Worlds: Securing Mixed JavaScript/ActionScript Multi-party Web Content. IEEE Transactions on Dependable and Secure Computing (TDSC), forthcoming. 33
  • 37. Different parsing techniques • Via a sandboxed iframe 1. Create sandbox iframe 2. Set content via srcdoc attribute o More performance o Parsed exactly as will be interpreted by browser o Executed asynchronously • (Alternative) Via a HTML parsing library in JavaScript 37
  • 38. Loading additional code in the sandbox • Several use cases require external code to be executed in a previously set up sandbox o Loading API + glue code o Dynamic script loading • Two new operations: o innerEval(code) o innerLoadScript(url) 38