Hacker News new | ask | show | jobs
by colshrapnel 2461 days ago
"escaping input" is a notorious delusion. And a bad one.

- it is not "input" must be treated, but, so to say - output. It's the destination that matters, not the source. By the time you get the input, you have no idea how and where it will be used. You can tell it right before the output (or, rather, better to call it "use") only. Say, you've got some input that didn't pass the verification and you will have to display it back in the HTML form. And if you already "escaped" it for SQL, it will be malformed. And vice-versa. Moreover, any data must be formatted properly before use, not just something that you tagged as "input".

- the word treated above is for a reason. Because the term "escaping" suggests some certain routine in PHP, which is the actual reason for numerous SQL injections.

1 comments

You're right, my wording was inexact - we must always escape strings that can be controlled in some fashion by the user.

I'm working on comprehensive taint analysis for PHP[0], and I'm spending a bunch of time thinking about how to automatically detect those dirty strings.

[0] https://psalm.dev/articles/psalm-3-and-a-half#taint-analysis