3 ms·
If the user says his name is "Bob'; drop tables students --", that is what you should store on your database. Unless, of course it's not a valid name for the re
by marcosdumay 5y ago
If the user says his name is "Bob'; drop tables students --", that is what you should store on your database. Unless, of course it's not a valid name for the rest of the system.
That's so old and obvious advice that I'm surprised people keep posting here and upvoting. And even more surprised when people keep disagreeing here.
- ehutch79 5y agoIf you're storing "Bob'; drop tables students --" in the database, you had to have sanitized your inputs, or there would be no students table. The article title says NOT to sanitize inputs. perhaps it's that nuance doesn't fit in a headline, but eh...
- wvenable 5y agoThe confusion is what is input and what is output. The string "Bob'; drop tables students --" should not be sanitized/encoded on *input* to the application. However, if you're not using parameterized queries, it should be encoded on *output* to the database. Data should only be sanitized in transit and not stored in an sanitized form. That's what the article is really saying.
- IshKebab 5y agoNo you don't. You use a parameterized query: execute("INSERT INTO foo VALUES (?)", user_input)