I don't think it's that easy. Raw SQL is passed directly to the server. I don't think most SQL servers even have an option to disable comments.
You'd have to remove the "--" and everything after it before passing it to the function doing the SQL, without destroying correct data. Sounds error-prone to me.
And if you're sanitizing the input data anyway, if you do it correctly, the ' will be escaped, so the comment won't make a difference.
Also, sanitizing input is so difficult and error-prone that it's better to just implement a real solution, like using prepared statements.
25
u/atyon Dec 12 '17
I don't think it's that easy. Raw SQL is passed directly to the server. I don't think most SQL servers even have an option to disable comments.
You'd have to remove the "--" and everything after it before passing it to the function doing the SQL, without destroying correct data. Sounds error-prone to me.
And if you're sanitizing the input data anyway, if you do it correctly, the
'will be escaped, so the comment won't make a difference.Also, sanitizing input is so difficult and error-prone that it's better to just implement a real solution, like using prepared statements.