tl;dr
- Dom clobbering to clobber isDevelopmet
- Throwing an error using RPO to prevent Dompurify from loading
- Using base tag’s to import our evil.js
š Initial analysis
We are given a memo sharing application , and its seems like we html injection using the memo parameter. Looking at the client-side code for the application.
|
|
as you can see our input HTML goes into an innerHTML sink in the beginning itself, however there is no easy XSS as there is a CSP.
|
|
The csp doesnt seem too strict , the first thing that i thought of was that default src is * and there is no base uri directive in the csp .
So we can inject a base tag with our server as the href value which will make all the scripts with relative paths in the page load resources from our server.
However there is only one script being used in the page which is dompurify.js and it is being loaded way before our injection happens so we cant make it load from our server using base tags.
However there is another script (logger.js) that is being loaded dynamically if certain conditions are satisfied. We can control the location from where logger.js is loaded using base tags as it is being loaded after our injection happens .
|
|
So to make logger.js load from our external server we have somehow reach the catch block. So for that to happen we need isDevelopment to be true, so that we can get inside the if block.
isDeveloment is only set to true if the origin is localhost.At the first glance it seems impossible to set isDevelopment as true.
However there are certain stuff you could to with just HTML injection!!
š„· Attack plan
So the attack plan is to use DOM clobbering here as we have HTML injection to define the isDevelopment variable. As isDevelopment is a global variable a simple tag with id attribute as isDevelopment will define that variable. Eg
|
|
Causing an Error to reach the catch block š
So now we are inside the if block , and to get to our logger.js script to load we have to get to the catch block . For that we have to cause an error somehow in these lines of code
|
|
If you look at the source code closely you can see that Dompurify is being loaded as a relative path. so if we access the page like /index.html/blah dompurify will try to get loaded from /blah .
So now that we are in the catch block we can use a base tag to load logger.js from our server.
š Final Payloads
|
|