
Input validation verifies or cleans up inputs to the application. Essentially trust no data from any source until it has been proven to be safe based on some established format verification process. Input validation is a critical part of a web service's reliability and security (or any software application for that matter). By failing to validate input data an application may do very unexpected things given a garbled (accidentally or intentionally) input leading to a security violation or a vulnerable state.
Input Validation:
To validate input:
Output validation ensures that all output data has been normalized and is in expected format before being given to other components of the system.
Most Script-Injection/Cross-site scripting issues could be mitigated with output validation techniques.
There are times when it makes sense that input validation is held to a minimum and a system to depend entirely on output validation. For example when data may be sent to more then one possible destination where different rules on valid display apply. In that case the input validation logic could not be aware of how the data will be processed by other components and cannot validate data accordingly.
For security purposes, data sometimes needs to be output differently than it is stored. This is due to the fact that data can have different meanings depending on the application processing it, e.g.: text vs. executable instructions.
Depending on the component that will process the output, all output should be validated in a way that is relevant to the target i.e. SQL-specific characters should be filtered before data is included in a database query, etc.
Output validation provides an extra layer of security should input validation fail or not be possible to implement. It should be coupled with input validation to provide defense in depth
Exceptions are abnormal activity in a system. But any application needs to be constructed to prevent errors or unexpected conditions from disclosing too much information. Revealing information, especially due to improper error handling can give an attacker major insight into the system.
Error messages are best left in non-technical terms. But still useful. For example if authentication fails instead of saying user name is incorrect or password is incorrect put out a message that says that the login id or password were incorrect. That would be specific enough to trouble shoot but general enough to provide no useful information to an attacker.
Need to have global exception handlers to clean up the output. Catch ALL exceptions and output a reasonably clean error message.
Use the finally clause to make sure output is cleaned up and that the system is not in an insecure state. If some part of a method uses heightened permissions then make sure that any extra privileges are dropped.
Layer all security so that there are reasonable boundaries and each one has its own layer of security. Don't go overboard but the redundancy helps to ensure the safety of the systems and data. The concept is to have a number of high strong walls between an attacker and any critical data.
Redundancy is not meant to be simple copy paste (one exploit in the main defenses should not be usable at all other services). By having different code written at different times and explicitly for the given application you increase the chances that an attacker will not be able to penetrate all services and defenses with the same attack.
Really the idea here is to make your application more expensive and harder to break so that it is just too risky or expensive for the potential return.
Examine a bank's security for the principles:
The bank's defenses are not perfect they still get robbed. But it takes considerable more effort then to rob convenience stores where the defenses are:
Use Secure String resources, proper encryption and try to isolate the exposure surface for sensitive data.
Object oriented programming deals with trying to let each part do its own work. Try to keep things in their own space.
Separation of Resources:
If there is account management policies use them, enforce them.
Log files are not for the users. Keep them safe and try to limit access especially for deleting or changing.
From time to time audit the logs. If they are not checked for exceptions, security errors and suspicious activity then they are useless.
Get familiar with:
And use them.
Complex code injects chances for errors and exploits.
Keep the attack exposure as small as possible. Only allow inputs and outputs through specific points and then examine the API or services closely.
If there is a solid known good solution use it. Software engineers love to reinvent components over and over again.
In many cases reinventing the wheel makes sense when:
This falls back on the issues of giving away the keys to the kingdom. Given enough time attackers can discover enough about the layout of your application in order exploit a vulnerability.
Comments
Post new comment