Valid input can still be dangerous in another context, such as the name
O'Brien in SQL or a comment containing HTML, so defences belong where data is usedValid input can still be dangerous in another context. So defences belong where the data is used. Many real values contain characters that are special in SQL, HTML or shell commands. For example, the name O'Brien contains a quote, which is special in SQL. Validation can't reject these values without breaking real users.
Validation is a first layer that narrows the input. Parameterised queries and encoding for each output context are what make data safe where it is used.
"Nothing; schema validation fully prevents injection" is wrong, because a valid value like O'Brien can still break a SQL query that is built from strings.
Read more