3 ms·
This article almost gets it right, then screws it up with the HTML example. Both SQLi and XSS have the same cause: concatenating strings when you are working w
by simonw 13y ago
This article almost gets it right, then screws it up with the HTML example.
Both SQLi and XSS have the same cause: concatenating strings when you are working with active code of some sort.
They both have the same solution: you need to know the escaping rules for the active code you are assembling.
You shouldn't be solving XSS by stripping tags (that's a great way to build a discussion forum where no-one can talk about how to use HTML) - you should be escaping user input before assembling it in to HTML.
To protect against dumb mistakes (because it's really easy to screw up just once and have a huge security hole) you should use abstractions that do this for you. If you're working with Django the ORM will do this for SQLi and auto-escaping in the template language will do this for XSS (watch out for variables you are outputting in a script tag context though).
Escaping, not sanitizing, should be the message.
- huxley 13y agoHate to disagree with you but you can have plenty of flexibility with element and attribute white-lists without abandoning sanitizing. Sanitize as much of your inputs as you are comfortable with and escape the outputs.
- marcosdumay 13y agoEscaping is a form of sanitizing.