Well, you have to sanitize for the transport medium, otherwise you can't sanitize at all afterwards. But if I'm sending user content in JSON and I didn't sanitize it for insertion into HTML, what man in the middle is going to be compromised? Furthermore, how can I possibly protect an unknown intermediary without knowing what it is going to do with it?
Maybe it is going to try to copy a value into a 20 char buffer, I don't know!
Maybe it is going to try to copy a value into a 20 char buffer, I don't know!