Re:Don’t try to sanitize input – escape output
by DelightOne on Thursday February 27, 2020 @05:59AM
(#22432258)
Defensive coding makes sense.
What is sql templating used for in the face of parameterized queries?
What I don't understand is the lack of using proper escaping functions when generating SQL. Templating SQL without escaping is the surest way to a SQL injection.
--- Bad
--- Good And to defensive coding:0. Sanitize input. Always, always.
1. Assert pre-condition invariants.*
2. Process.
3. Assert post-condition invariants.*
4. Generate correct output by understanding the output domain.
* Unit tests, smoke tests, integration tests and code-coverage alone are insufficient to cover complex code paths. Fuzzing with asserted invariants is a good way to shake the dust out of hairy code.