Our application had a few vulnerabilities detected by AppScan and we had to add server-side validation to catch SQL injection attempts.
But my question is, how far do you go in server-side validation? In theory there's no end to how complicated you can make it.
Suppose I'm just validating there are no special chars in my model, which is the bare minimum
public boolean validateModel(Model model) {
// Email address has no special chars
try {
InternetAdress emailAddr = model.getEmailAddr();
emailAddr.validate();
} catch (Exception e) {
return false;
}
// FirstName has no special chars
if (!StringUtils.isAlphanumeric(model.getFirstName())
return false;
// LastName has no special chars
if (!StringUtils.isAlphanumeric(model.getLastName())
return false;
}
// ...
return true;
}
But why stop there? In any CRUD operation, we also have to protect against invalid IDs or numbers, so any Insert can check that the ID doesn't exist yet; that you belong or don't belong to whatever area you claim to be affiliated with (e.g. the ID is a valid ID for you); or any Update/Delete can check that the ID must exist first. To be really secure, we can really parse user input because hackers can substitute invalid data even without invalid chars.
My point is, to achieve a proper level of server-side security, there's a tremendous of checking you can do on the server-side. Where do you stop? What are the best practices?