Re:Making Wrong Code Look Wrong
by yesbabyyes on Monday August 22, 2011 @04:41PM
(#2914035)
With eco templates, I output strings with <%=. To output unescaped strings such as templates, I must write <%-. This works for me.
Do you treat SQL queries as strings in your code, or do you build something like an abstract syntax tree?
Build them using a syntax builder framework, but it is possible to pass raw SQL strings in in exceptional circumstances. Obviously, the developer needs to be totally aware of the risks of this. Not ideal, but needed to solve a couple of problems.
I personally believe that all code that is sensitive to escaping issues, should be escaped on output (or storage / sending to the database / whatever) by default unless you explicitly opt it out.
In our framework, we maintain 'already escaped' strings as a separate class, forcing the developer to acknowledge this fact. The HTML output layer escapes all strings unless they are instances of this safe class. Similarly for the SQL layer, all code gets quoted unless it was explicitly marked as 'safe'.