-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autoescaping doesen't work in <script> tag context #322
Comments
@Hurtak this isn't actually a problem Marko can solve since putting dynamic values inside a <script>var x = $!{JSON.stringify(data)}</script> In this case, HTML escaping is disabled because encoded HTML entities are not decoded if they are inside However, if the stringified data contains an ending <script>var x = $!{JSON.stringify(data).replace(/<\//g, '<\\u002F')}</script> With that said, using <div data-foo=JSON.stringify(data)> The data can then be extracted from the DOM using code similar to the following:
I'm going to close this issue because it doesn't require any changes to Marko, but we should probably put together a more complete security guide. |
@Hurtak also, if you have any thoughts or suggestions on how we might be able to avoid the security problems associated with |
@patrick-steele-idem thanks for the detailed reply, Is it really inherently unsafe to put user data in script tag? Even if you escape all characters like Some provide escapejs filter - https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#escapejs But you seem to be much more knowledgeable about this topic than me, so I am not sure if these filters catch 100% of XSS attackers inputs |
@Hurtak The For example, given the following template: <script>
var foo = ${JSON.stringify(data.foo)};
</script> And the given data: {
foo: {
name: 'Evil </script>'
}
} The output is currently the following: <script>
var foo = {"name":"Evil </script>"};
</script> (browsers do not decode HTML entities inside The output should be the following: <script>
var foo = {"name":"Evil \u003C/script>"};
</script> I'm going to reopen this issue and investigate a proper fix. Thanks for opening this issue and thank you for your persistence :) |
Fixes #322 - Autoescaping doesen't work in <script> tag context
New version published: See CHANGELOG.MD for a longer description of what exactly changed: |
@patrick-steele-idem With this fix in place, is there still any reason to avoid putting data in inline scripts? The strategy of using empty dom elements with data-attributes always seemed strange to me. |
This was done in preparation for support CSP. However, as long as we put a CSP |
Hello,
while trying out Marko I tested how it's autoescaping works in different contexts.
The contexts I tested it in:
In first two Marko correctly detected context and chose proper escaping functions (I saw escapeXml and escapeXmlAttr in compiled templates), but in the last one I was able to do XSS.
You can replicate it on http://markojs.com/try-online/
marko template
data
"\"; alert('xss');\""
HTML output
The text was updated successfully, but these errors were encountered: