We'll get there. This is a much more straightforward problem to solve than XSS, which is the real bitch.
We'll get there. This is a much more straightforward problem to solve than XSS, which is the real bitch.
I always wondered if it'd be possible to use the type system of a language to do something similar - make a "safe to output" type, and a "not safe to output" type, which are not mutually convertible, and then write a function that converts between UnsafeStr and SafeStr. Then, you can write all your code to only work on and only print a SafeStr.
>>> foo = u'I <3 you.'
>>> bar = Markup(u'<h1>') + foo + Markup(u'</h1>')
>>> print bar
<h1>I <3 you.</h1>1. What is "safe content"? That entirely depends on the context in which you're using a particular string. (See https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%... for a summary of the kinds of things you have to think about)
2. The system you're describing is somewhat similar to http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/. People still find plenty of XSS vulnerabilities in Rails applications.