A10—Mishandling of Exceptional Conditions
>Control Description
>Prevention & Mitigation Strategies
- 1.Plan for exceptional conditions proactively — expect the worst and design for it.
- 2.Catch every possible system error directly at the place where it occurs and handle it meaningfully to solve problems and ensure recovery.
- 3.Error handling should include throwing an error to inform the user in an understandable way, logging the event, and issuing an alert when justified.
- 4.Have a global exception handler in place as a safety net in case there is ever something that was missed.
- 5.Implement monitoring and observability tooling that watches for repeated errors or attack patterns and issues appropriate responses.
- 6.Roll back every part of a transaction upon error and start again, also known as failing closed. Do not attempt partial recovery.
- 7.Add rate limiting, resource quotas, throttling, and other limits wherever possible to prevent exceptional conditions from occurring in the first place.
- 8.Consider outputting identical repeated errors above certain rates as statistics rather than individual messages.
- 9.Implement strict input validation with sanitization or escaping for potentially hazardous characters.
- 10.Establish centralized error handling, logging, monitoring, and alerting across the application.
- 11.Conduct threat modeling and secure design review activities, code reviews or static analysis, and stress, performance, and penetration testing.
- 12.Ensure your entire organization handles exceptional conditions in the same way — standardize the approach.
>Attack Scenarios
Resource exhaustion via mishandling of exceptional conditions (Denial of Service) could be caused if the application catches exceptions when files are uploaded, but doesn’t properly release resources after. Each new exception leaves resources locked or otherwise unavailable, until all resources are used up.
Sensitive data exposure via improper handling or database errors that reveals the full system error to the user. The attacker continues to force errors in order to use the sensitive system information to create a better SQL injection attack. The sensitive data in the user error messages are reconnaissance.
State corruption in financial transactions could be caused by an attacker interrupting a multi-step transaction via network disruptions. Imagine the transaction order was: debit user account, credit destination account, log transaction. If the system doesn’t properly roll back the entire transaction (fail closed) when there is an error part way through, the attacker could potentially drain the user’s account, or possibly a race condition that allows the attacker to send money to the destination multiple times.
>Related CWEs
>References
- •OWASP Cheat Sheet: Logging
- •OWASP Cheat Sheet: Error Handling
- •OWASP Application Security Verification Standard (ASVS): V16.5 Error Handling
- •OWASP Testing Guide: 4.8.1 Testing for Error Handling
- •Best practices for exceptions (Microsoft, .Net)
- •Clean Code and the Art of Exception Handling (Toptal)
- •General error handling rules (Google for Developers)
- •Example of real-world mishandling of an exceptional condition
Ask AI
Configure your API key to use AI features.