3 ms·
It seems like this depends on your types? If you are storing user input to a database using a text field, it's best to assume the field can contain arbitrary te
by skybrian 7y ago
It seems like this depends on your types? If you are storing user input to a database using a text field, it's best to assume the field can contain arbitrary text, since the database allows that. But if you're storing the input into a number field then it must be parsed as a number and you can assume it's a number. If you constrained the number field to a certain range then you can assume the number is in that range.
Storing arbitrary text is common, so we usually need to know how to render it correctly. There are fancier types and constraints, though.
- choeger 7y agoYou should still sanitize the output, IMO. The code in question has no ties to the DB schema (usually) and if that changes for some reason you have no means (usually) to figure out where you have to change the code.
- dTal 7y agoEach piece of code should enforce its own contracts explicitly across communication boundaries. If your backend relies on x input being parseable as a number, it shouldn't assume that it is just because you know that it ultimately came from a number picker in an HTML form - it should check for itself. This is defensive not just for security, but so that when you change something later and screw it up you get actual error messages instead of silent breakage.