Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Mustache XSS-proof?

Tags:

xss

mustache

I was thinking about my app's XSS vulnerability. On the server side I don't sanitize either input or output, so

<script>alert(document.cookies)</script>

is stored in database exactly so. To view this value on the client side I use Mustache. If this script was executed by an admin, it is of course easy to hijack his session. However I've noticed that Mustache by default escapes these values & \ " < > when you use the {{}} syntax. Do I need to worry about XSS, when the value from the database would be inserted into

<p>{{value}}</p>

or even

<p data-id='{{value}}'>something</p>

? Should I perhaps review my Mustache templates to look for any vulnerable code, or unless I'd use

<script>{{value}}</script>

I am safe?

like image 365
Ziarno Avatar asked Apr 15 '13 12:04

Ziarno


People also ask

Does client side validation prevent XSS attacks?

Client-side validation isn't enough to prevent an XSS attack It isn't uncommon for client-side validation to be implemented as a sole line of defence. However, client-side validation can be bypassed trivially by attackers and is not enough to protect web applications and their users.

What are the two primary defenses against XSS attacks?

You may have been realizing that the main reason for having an XSS vulnerability is the lack of data validation. So, you guessed that the primary defense against XSS attacks is distrusting user input.

What encoding should be used to protect from XSS?

Cross site scripting, or XSS, is a form of attack on a web application which involves executing code on a user's browser. Output encoding is a defense against XSS attacks.


1 Answers

Well, you should always worry :) But yes, Mustache accomplishes the goal you are talking about here, protecting your examples from XSS (except where you're outputting the value directly into a <script> tag).

Note: check that the Mustache implementation you're using escapes single quotes. It's apparently not in the spec to do so (https://github.com/mustache/spec/issues/69) but the major implementations thankfully escape it anyway.

like image 145
Ben Regenspan Avatar answered Dec 11 '22 09:12

Ben Regenspan