I was doing some reading on Cross-Site Scripting (XSS) attacks today. It seems that Backbone has model.escape('attr') built in and from what I can tell that should always be used instead of model.get('attr') to prevent these attacks.
I did some initial searching but didn’t find any recommendations of the sort. Should I always use model.escape('attr') when retrieving values from a model?
Using Underscore templates, I’ve generally seen/done it like this:
When you use
<%- someModelAttribute %>, Underscore knows to escape the given values (as opposed to<%= someModelAttribute %>which injects the attribute directly without escaping).