I do infosec things @Mapbox.
We build cool open-source things, like maps.
And we're always looking for awesome people!
an in-depth view of how XSS happens
best practices to prevent XSS from happening
how you can be more proactive in deploying safe code
And it's the lowest level of rendering for browsers.
Rendering happens through multiple elements, called nodes.
<html>
<body>
<div>
<h1> HI DCJS!!! 👋 </h1>
</div>
</body>
</html>
var user = window.location.search.substring(1).split('=')[1];
$node.html( '<h1>' + user + '</h1>' );
https://imawesome.site/index.html?user=oliikit
<h1> oliikit </h1>
Yay for no longer living in the internet stone age!
What if someone took advantage of our code and hijacked it with one of their own scripts?
https://imawesome.site/index.html?user=guest<script>alert('ATTACKED!')</script>
<h1>
guest
<script>alert('ATTACKED!')</script>
</h1>
The DOM just needed to know that user was text and only text.
const header = document.createElement('h1');
let user = document.createTextNode(username);
header.appendChild(user);
And that information can be accessed through the DOM.
Moral of the story:
The malicious code is your server now. And will execute anytime that page loads.
Anywhere you accept user input && store it in your server.
User input form.
API ingestion.
This was one of our first Hackerone reports.
The affected code?
<%= feature.properties.description %>
<%=
<%=
is great for customizing and dynamic input.
But, again, the DOM is a bad genie.
<%-
will automatically be HTML-escaped.
https://www.myawsomesite.com/login/?https://s3.amazonaws.com/westinhotel/mbt.txt
Here's the payload:
https://www.philips.nl/healthcare/<body%20alt=al%20lang=ert%20onmouseenter="top['al'+lang](/PoC%20XSS%20Bypass%20by%20Jonathan%20Bouman/)"?debug=layout
>
from the
<br>
tag in the client code will be used to close the
body
tag
* Jonathan Bouman reported this vulnerability and wrote a
great write-up.
Host a hackathon with the top 30 security researchers.
Have tons of map demos that are public facing.
Get 25 XSS reports within the first hour of the hackathon.
How can we make sure that we don't deploy XSS-vulnerable code to our customers?
OWASP has an XSS cheat-sheet with hundreds of code examples from the security community.
doc.innerHTML = '<div>' +
truncatedName + '</div>'
var href = generateURL(source);
function generateDownloadURL(source) {
return var href = 'https://mapbox.com/' + source
}
here comes eslint-plugin-xss!
🚨
Linters do NOT evaluate if the data is trusted or not.
🚨
Globally install eslint, eslint-plugin-html, and eslint-plugin-xss
Add the following to your .eslintrc.js file to the root of your repo:
module.exports = {
'env': {
'browser': true,
'es6': true
},
'plugins': [
'html',
'xss'
],
'rules': {
'xss/no-mixed-html': 1,
'xss/no-location-href-assign': 1
}
};
😰
Want more information? OWASP XSS article and OWASP Cheat Sheet has some good tips and resources.
@oliikit
olivia
olivia.brundage@mapbox.com