Thursday, June 8, 2017

security training - DOM XSS - Attack vector 1

DOM XSS (Cross side scripting)

1. Landing page URL :
2. Pseudocode for Landing JSP web page

   var name = document.location.hash.split('#')[1]; //
   document.write("Hello " + name + "! Please login or signup to access news stories");

Part 1 : Attacker sends email like this :

Hi Alice, Hope you are well ! Please find below a 20% discount code to join TradeNEWS.<script>window.location = '';</script> Kind Regards, Bob

Note the username is replaced with javascript code. Once user clicks on the link, he/she is redirected to a fake website. There credit card information can be stolen.

RemedyTo defend against Cross Site Scripting attacks within the application user's Browser Document Object Model (DOM) environment a defense-in-depth approach is required, combining a number of security best practices.

Note You should recall that for Stored XSS and Reflected XSS injection takes place server side, rather than client browser side. Whereas with DOM XSS, the attack is injected into the Browser DOM, this adds additional complexity and makes it very difficult to prevent and highly context specific, because an attacker can inject HTML, HTML Attributes, CSS as well as URLs.

As a general set of principles the application should first HTML encode and then Javascript encode any user supplied data that is returned to the client. For example using OWASP ESAPI:


Due to the very large attack surface this approach is no silver bullet, and as such developers are strongly encouraged to review areas of code that are potentially susceptible to DOM XSS, including but not limited to:

Note: OWASP ESAPI (The OWASP Enterprise Security API) is a free, open source, web application security control library that makes it easier for programmers to write lower-risk applications.

Let's apply a suitable Regex pattern to remediate this particular DOM XSS vulnerability.



   var name = document.location.hash.split('#')[1]; //

if (name.match(/^[a-zA-Z0-9]*$/))


   document.write("Hello " + name + "! Please login or signup to access news stories");




window.alert("Security error");



1 comment:

Blogger said...

BlueHost is one of the best hosting provider for any hosting services you might require.

Blog Archive