A3 - Cross-Site Scripting ("XSS") - DOM Based

DOM Based XSS (or as it is called in some texts, “type-0 XSS”) is an XSS attack wherein the attack payload is executed as a result of modifying the DOM “environment” in the victim’s browser used by the original client side script, so that the client side code runs in an “unexpected” manner. That is, the page itself (the HTTP response that is) does not change, but the client side code contained in the page executes differently due to the malicious modifications that have occurred in the DOM environment.

The following code was taken from app/views/sessions/new.html.erb:

				 <%= 
				%{ 
	  
				} 
				%>
			  

The code (above) takes user input (params), and renders it back on the page without any output encoding or escaping.

Stored Cross-Site Scripting ATTACK:

Ensure you are signed out of the application first. Make sure you are using something like Firefox as Safari/Chrome won't work for this exercise. Then, use the following link (substitute hostname for your actual hostname) to execute an alert box:

				<%= %{http://127.0.0.1:3000/#test=} %>
			 

Stored Cross-Site Scripting SOLUTION:

Leverage the Hogan function for escaping (found in the application.js file) to escape user input:

				<%= %{
	 
	 
				}	
				
				%>
			 

You should view the source of the login page, might be something interesting there.