Secure code review

Auditing application error handling and safe failure behaviour

Trusted records: terminal, document, eye arranged to illustrate auditing application error handling and safe failure behaviour.

Security records and error handling should support investigation while preserving confidentiality and safe application state. Understanding application error handling and safe failure behaviour helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

Useful security records describe important actors, resources and state changes without becoming another source of secrets. Their value depends on reliable event coverage, correlation and access protection as well as the volume of information collected.

Why it matters

Consider a realistic failure: an error both exposes internal information and leaves too little trustworthy context to reconstruct the affected operation.

Missing or misleading records can delay detection and make an incident harder to reconstruct. Excessive capture can expose credentials or confidential content to people and systems that did not otherwise need it.

A code audit connects a stated requirement to the implementation responsible for enforcing it. Source review and targeted behavioural checks should explain the same boundary and any relevant exceptions.

How penetration testers check for it

Review the specific control expectations below against the code, deployment and observable application behaviour.

  • Confirm that a generic message is returned to the consumer when an unexpected or security-sensitive error occurs, ensuring no exposure of sensitive internal system data such as stack traces, queries, secret keys, and tokens.
  • Confirm that the application continues to operate securely when external resource access fails, for example, by using patterns such as circuit breakers or graceful degradation.
  • Confirm that the application fails gracefully and securely, including when an exception occurs, preventing fail-open conditions such as processing a transaction despite errors resulting from validation logic.
  • Confirm that a "last resort" error handler is defined which will catch all unhandled exceptions. This is both to avoid losing error details that must go to log files and to ensure that an error does not take down the entire application process, leading to a loss of availability.
  • Review redaction and resistance to misleading event content.
  • Assess access, integrity and retention.

How to fix it

Implement the required boundary in the component that actually performs the sensitive operation and retain focused regression coverage.

  • Define meaningful events and consistent fields.
  • Exclude unnecessary secrets and personal information.
  • Protect log access and important audit records.
  • Verify that monitoring and investigation workflows can use the retained evidence.

A complete request or response is rarely necessary for every event. Capture should be justified by an operational purpose and protected according to the information it contains.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss the security of your application code.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo