SlideShare a Scribd company logo
1 of 25
Stanford Security Seminar 
July 12, 2010 
Self-Protecting JavaScript: 
A Lightweight Approach to Enforcing 
Security Policies* 
Phu H. Phung 
Chalmers, Sweden 
* This talk is based 2 joint papers with David Sands, Andrey Chudnov, Jonas Magazinius 
appeared on ASIACCS’09 & OWASP AppSec’10
The concern 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
Difficult issues 
• Parser mismatch problem: 
– 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: 
Use an Inlined Reference Monitor 
• “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 
– its implementation is a small and simple adaptation of an 
aspect-oriented programming 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
Enforcement method 
• Intercept JavaScript built-in method calls by 
inlining policy into the call 
– control or modify the bad behaviour 
• Monitor access to sensitive properties
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
Implementation 
• Use aspect-oriented programming (AOP) style 
to intercept JavaScript API method calls 
var wrapper = function(object, method, Policy) { 
//... 
var original = object[method]; 
var aspect = function() { 
//... 
return Policy.apply(..., 
proceed : function(){ 
return original.apply(...) 
}); 
}; 
object[method] = aspect; 
return aspect; 
};
Monitoring Property access 
• Use the setter and getter 
object.prototype.__defineGetter__(...), 
object.prototype.__defineSetter__(...) 
• Property: even can redefine setter/getter, 
original wrapped properties are still protected
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 in any 
sides: server side, proxy or plug-in 
Dagstuhl 09141, 2 April 2009
Secure the wrapper 
• There are several issues that an attacker can 
exploit the wrapper 
– Function and Object Subversion 
• Modifying the Function/ Object –prototype 
– Global setter subversion 
– Recover the wrapped built-in using aliases 
• Static aliases 
• Dynamic aliases
Function and Object Subversion 
Object 
• prototype • valueOf( ) 
Function 
• constructor 
• prototype 
• apply( ) 
• call( ) 
{function instance} 
• constructor 
Modifying subverts 
expected behavior 
Wrapper: 
original.apply(this,args) 
Attack code: 
var org; 
Function.prototype.apply = 
function(){ org = this} 
Fixing : 
original.apply= $virgin_apply
Global Setter subversion 
Wrapper code 
policy({args: 
arguments, 
proceed: original}) 
Subversion 
var org; 
Object.prototype. 
__defineSetter__(‘proceed’, 
function(o) { org = o }); 
Fixing the wrapper: 
• No temporary objects? 
• Use “safe” objects… 
• Change JavaScript: Don’t execute setters upon 
instantiation (IE, Firefox)
Static aliases 
window.alert 
alert 
Window.prototype.alert 
window.window.alert 
window.__proto__.alert constructor.prototype.alert
Dynamic aliases 
alert alert 
wrapper 
alert 
We provide pre-defined policies which enforce methods 
that possible return a window object with the same 
policies as the current window
Sane Policies 
• Object and Function Subversion in Policies 
• Non Declarative Arguments
Function and Object Subversion in 
Policies 
Policy code 
var whitelist = 
{"good.com":true, 
"good2.org":true} 
if(whitelist[ 
address.substr(...))]) 
Fixing subversion 
• hasLocalProperty() 
• 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… 
Credit: Meyerovich at el, WWW’10
“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
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’; 
} 
}
Types for Declarative Arguments 
argument array cloning by type: 
policy.toString(b) === ’xyz’ 
inspection type 
? ‘string’ 
a b c 
? ‘xyz’ 
original argument array 
Computation by policy code 
leading to call to 
invocation.proceed() 
inspection 
argument array 
policy’s modified 
argument array 
? ‘xy’ 42 
Recombine with 
original argument 
and pass to 
original built-in 
a ‘xy’ 42 
policy function proceed function 
Example policy computation for some built-in called with (a,b,c). In 
this example the policy inspects b at type string and removes the 
last character, and sets the third parameter to 42 before calling 
proceed() in order to access the original built-in function. In the 
diagram ? is an abbreviation for undefined, and array objects are 
depicted as boxes.
Summary 
• Our approach is to control and modify the 
behaviour of JavaScript by transforming the code 
to make it self-protecting 
– no browser modifications 
– non-invasive 
• 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 
Dagstuhl 09141, 2 April 2009
References 
• Jonas Magazinius, Phu H. Phung, and David 
Sands (2010). Safe Wrappers and Sane Policies 
for Self Protecting JavaScript. OWASP AppSec 
Research 2010, June 2010. 
• Phu H. Phung, David Sands, and Andrey 
Chudnov (2009). Lightweight Self-Protecting 
Javascript (ASIACCS 2009) 
The papers are available at: 
http://www.cse.chalmers.se/~phung/projects/jss
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!

More Related Content

Viewers also liked

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
 
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
 
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
 
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
 
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
 

Viewers also liked (7)

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
 
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
 
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
 
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
 
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...
 

Similar to Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Policies

Phu appsec13
Phu appsec13Phu appsec13
Phu appsec13drewz lin
 
Lightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptPhú Phùng
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web applicationSecurity Bootcamp
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncubeMalisa Ncube
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointBob German
 
2015 09-18-jug summer camp
2015 09-18-jug summer camp2015 09-18-jug summer camp
2015 09-18-jug summer campSebastien Gioria
 
42 minutes to secure your code....
42 minutes to secure your code....42 minutes to secure your code....
42 minutes to secure your code....Sebastien Gioria
 
Introduction to Android Development and Security
Introduction to Android Development and SecurityIntroduction to Android Development and Security
Introduction to Android Development and SecurityKelwin Yang
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Stephan Chenette
 
AllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensorAllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensorjtmelton
 
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
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
 
Platform Security IRL: Busting Buzzwords & Building Better
Platform Security IRL:  Busting Buzzwords & Building BetterPlatform Security IRL:  Busting Buzzwords & Building Better
Platform Security IRL: Busting Buzzwords & Building BetterEqual Experts
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad WoodOrtus Solutions, Corp
 
Pentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and ManipulationPentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and ManipulationAndreas Kurtz
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksDimitry Polivaev
 
Scaling security in a cloud environment v0.5 (Sep 2017)
Scaling security in a cloud environment  v0.5 (Sep 2017)Scaling security in a cloud environment  v0.5 (Sep 2017)
Scaling security in a cloud environment v0.5 (Sep 2017)Dinis Cruz
 
Introduction to Aspect Oriented Software Development
Introduction to Aspect Oriented Software DevelopmentIntroduction to Aspect Oriented Software Development
Introduction to Aspect Oriented Software Developmentmukhtarhudaya
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Jim Manico
 

Similar to Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Policies (20)

Phu appsec13
Phu appsec13Phu appsec13
Phu appsec13
 
Lightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScriptLightweight Self-Protecting JavaScript
Lightweight Self-Protecting JavaScript
 
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh  - Some new vulnerabilities in modern web applicationNguyen Phuong Truong Anh  - Some new vulnerabilities in modern web application
Nguyen Phuong Truong Anh - Some new vulnerabilities in modern web application
 
ASP.NET MVC Best Practices malisa ncube
ASP.NET MVC Best Practices   malisa ncubeASP.NET MVC Best Practices   malisa ncube
ASP.NET MVC Best Practices malisa ncube
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePoint
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
2015 09-18-jug summer camp
2015 09-18-jug summer camp2015 09-18-jug summer camp
2015 09-18-jug summer camp
 
42 minutes to secure your code....
42 minutes to secure your code....42 minutes to secure your code....
42 minutes to secure your code....
 
Introduction to Android Development and Security
Introduction to Android Development and SecurityIntroduction to Android Development and Security
Introduction to Android Development and Security
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007
 
AllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensorAllDayDevOps 2019 AppSensor
AllDayDevOps 2019 AppSensor
 
WWW/Internet 2011 - A Framework for Web 2.0 Secure Widgets
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
 
Platform Security IRL: Busting Buzzwords & Building Better
Platform Security IRL:  Busting Buzzwords & Building BetterPlatform Security IRL:  Busting Buzzwords & Building Better
Platform Security IRL: Busting Buzzwords & Building Better
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Wood
 
Pentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and ManipulationPentesting iOS Apps - Runtime Analysis and Manipulation
Pentesting iOS Apps - Runtime Analysis and Manipulation
 
Strategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source FrameworksStrategy-driven Test Generation with Open Source Frameworks
Strategy-driven Test Generation with Open Source Frameworks
 
Scaling security in a cloud environment v0.5 (Sep 2017)
Scaling security in a cloud environment  v0.5 (Sep 2017)Scaling security in a cloud environment  v0.5 (Sep 2017)
Scaling security in a cloud environment v0.5 (Sep 2017)
 
Introduction to Aspect Oriented Software Development
Introduction to Aspect Oriented Software DevelopmentIntroduction to Aspect Oriented Software Development
Introduction to Aspect Oriented Software Development
 
Design For Testability
Design For TestabilityDesign For Testability
Design For Testability
 
Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2Top Ten Java Defense for Web Applications v2
Top Ten Java Defense for Web Applications v2
 

Recently uploaded

Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTSérgio Sacani
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxAleenaTreesaSaji
 
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdfNAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdfWadeK3
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​kaibalyasahoo82800
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhousejana861314
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )aarthirajkumar25
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.aasikanpl
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bSérgio Sacani
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Sérgio Sacani
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 sciencefloriejanemacaya1
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxyaramohamed343013
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfnehabiju2046
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...RohitNehra6
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfSELF-EXPLANATORY
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxSwapnil Therkar
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...Sérgio Sacani
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PPRINCE C P
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real timeSatoshi NAKAHIRA
 

Recently uploaded (20)

Disentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOSTDisentangling the origin of chemical differences using GHOST
Disentangling the origin of chemical differences using GHOST
 
Luciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptxLuciferase in rDNA technology (biotechnology).pptx
Luciferase in rDNA technology (biotechnology).pptx
 
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdfNAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
NAVSEA PEO USC - Unmanned & Small Combatants 26Oct23.pdf
 
Nanoparticles synthesis and characterization​ ​
Nanoparticles synthesis and characterization​  ​Nanoparticles synthesis and characterization​  ​
Nanoparticles synthesis and characterization​ ​
 
Orientation, design and principles of polyhouse
Orientation, design and principles of polyhouseOrientation, design and principles of polyhouse
Orientation, design and principles of polyhouse
 
Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )Recombination DNA Technology (Nucleic Acid Hybridization )
Recombination DNA Technology (Nucleic Acid Hybridization )
 
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
Call Girls in Mayapuri Delhi 💯Call Us 🔝9953322196🔝 💯Escort.
 
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43bNightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
Nightside clouds and disequilibrium chemistry on the hot Jupiter WASP-43b
 
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
Discovery of an Accretion Streamer and a Slow Wide-angle Outflow around FUOri...
 
Boyles law module in the grade 10 science
Boyles law module in the grade 10 scienceBoyles law module in the grade 10 science
Boyles law module in the grade 10 science
 
Scheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docxScheme-of-Work-Science-Stage-4 cambridge science.docx
Scheme-of-Work-Science-Stage-4 cambridge science.docx
 
Engler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomyEngler and Prantl system of classification in plant taxonomy
Engler and Prantl system of classification in plant taxonomy
 
A relative description on Sonoporation.pdf
A relative description on Sonoporation.pdfA relative description on Sonoporation.pdf
A relative description on Sonoporation.pdf
 
Biopesticide (2).pptx .This slides helps to know the different types of biop...
Biopesticide (2).pptx  .This slides helps to know the different types of biop...Biopesticide (2).pptx  .This slides helps to know the different types of biop...
Biopesticide (2).pptx .This slides helps to know the different types of biop...
 
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdfBehavioral Disorder: Schizophrenia & it's Case Study.pdf
Behavioral Disorder: Schizophrenia & it's Case Study.pdf
 
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Munirka Delhi 💯Call Us 🔝8264348440🔝
 
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptxAnalytical Profile of Coleus Forskohlii | Forskolin .pptx
Analytical Profile of Coleus Forskohlii | Forskolin .pptx
 
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
All-domain Anomaly Resolution Office U.S. Department of Defense (U) Case: “Eg...
 
VIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C PVIRUSES structure and classification ppt by Dr.Prince C P
VIRUSES structure and classification ppt by Dr.Prince C P
 
Grafana in space: Monitoring Japan's SLIM moon lander in real time
Grafana in space: Monitoring Japan's SLIM moon lander  in real timeGrafana in space: Monitoring Japan's SLIM moon lander  in real time
Grafana in space: Monitoring Japan's SLIM moon lander in real time
 

Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Policies

  • 1. Stanford Security Seminar July 12, 2010 Self-Protecting JavaScript: A Lightweight Approach to Enforcing Security Policies* Phu H. Phung Chalmers, Sweden * This talk is based 2 joint papers with David Sands, Andrey Chudnov, Jonas Magazinius appeared on ASIACCS’09 & OWASP AppSec’10
  • 2. The concern 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. Difficult issues • Parser mismatch problem: – 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>
  • 4. 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
  • 5. Our approach: Use an Inlined Reference Monitor • “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 – its implementation is a small and simple adaptation of an aspect-oriented programming library
  • 6. 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
  • 7. Enforcement method • Intercept JavaScript built-in method calls by inlining policy into the call – control or modify the bad behaviour • Monitor access to sensitive properties
  • 8. 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
  • 9. Implementation • Use aspect-oriented programming (AOP) style to intercept JavaScript API method calls var wrapper = function(object, method, Policy) { //... var original = object[method]; var aspect = function() { //... return Policy.apply(..., proceed : function(){ return original.apply(...) }); }; object[method] = aspect; return aspect; };
  • 10. Monitoring Property access • Use the setter and getter object.prototype.__defineGetter__(...), object.prototype.__defineSetter__(...) • Property: even can redefine setter/getter, original wrapped properties are still protected
  • 11. 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 in any sides: server side, proxy or plug-in Dagstuhl 09141, 2 April 2009
  • 12. Secure the wrapper • There are several issues that an attacker can exploit the wrapper – Function and Object Subversion • Modifying the Function/ Object –prototype – Global setter subversion – Recover the wrapped built-in using aliases • Static aliases • Dynamic aliases
  • 13. Function and Object Subversion Object • prototype • valueOf( ) Function • constructor • prototype • apply( ) • call( ) {function instance} • constructor Modifying subverts expected behavior Wrapper: original.apply(this,args) Attack code: var org; Function.prototype.apply = function(){ org = this} Fixing : original.apply= $virgin_apply
  • 14. Global Setter subversion Wrapper code policy({args: arguments, proceed: original}) Subversion var org; Object.prototype. __defineSetter__(‘proceed’, function(o) { org = o }); Fixing the wrapper: • No temporary objects? • Use “safe” objects… • Change JavaScript: Don’t execute setters upon instantiation (IE, Firefox)
  • 15. Static aliases window.alert alert Window.prototype.alert window.window.alert window.__proto__.alert constructor.prototype.alert
  • 16. Dynamic aliases alert alert wrapper alert We provide pre-defined policies which enforce methods that possible return a window object with the same policies as the current window
  • 17. Sane Policies • Object and Function Subversion in Policies • Non Declarative Arguments
  • 18. Function and Object Subversion in Policies Policy code var whitelist = {"good.com":true, "good2.org":true} if(whitelist[ address.substr(...))]) Fixing subversion • hasLocalProperty() • 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… Credit: Meyerovich at el, WWW’10
  • 19. “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
  • 20. 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’; } }
  • 21. Types for Declarative Arguments argument array cloning by type: policy.toString(b) === ’xyz’ inspection type ? ‘string’ a b c ? ‘xyz’ original argument array Computation by policy code leading to call to invocation.proceed() inspection argument array policy’s modified argument array ? ‘xy’ 42 Recombine with original argument and pass to original built-in a ‘xy’ 42 policy function proceed function Example policy computation for some built-in called with (a,b,c). In this example the policy inspects b at type string and removes the last character, and sets the third parameter to 42 before calling proceed() in order to access the original built-in function. In the diagram ? is an abbreviation for undefined, and array objects are depicted as boxes.
  • 22. Summary • Our approach is to control and modify the behaviour of JavaScript by transforming the code to make it self-protecting – no browser modifications – non-invasive • 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 Dagstuhl 09141, 2 April 2009
  • 23. References • Jonas Magazinius, Phu H. Phung, and David Sands (2010). Safe Wrappers and Sane Policies for Self Protecting JavaScript. OWASP AppSec Research 2010, June 2010. • Phu H. Phung, David Sands, and Andrey Chudnov (2009). Lightweight Self-Protecting Javascript (ASIACCS 2009) The papers are available at: http://www.cse.chalmers.se/~phung/projects/jss
  • 24. 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.

Editor's Notes

  1. www paper?? Safe function! (detach) recursively copies fields and sets proto to null
  2. Limitations Sometimes inheritance is required
  3. References: Sergio Maffeis (S&P 2010) Simple solution in previous paper The problem is still being exploited Solution is a typelanguage