Provide custom error pages that hide internal details, return the correct status code, and guide users without exposing stack traces or configuration. Ensure error handling is consistent across web servers, applications and APIs, including authentication and authorisation failures. Review default error responses regularly, because verbose defaults can reveal technologies, paths and implementation details.
What a custom error page should do beyond “show something friendly”
A custom error page is a control as much as a user interface. Its job is to acknowledge failure cleanly, preserve the correct HTTP semantics, and avoid turning an ordinary error into an information disclosure issue. The safest pattern is simple: present a neutral message, route users to a useful next step, and keep technical detail out of the response body unless the audience and context truly require it.
That distinction matters because error handling often spans multiple layers. A web server, application runtime, reverse proxy and API gateway can all emit different defaults, and a missing page in one layer can undo careful handling in another. When the response is consistent across the stack, users get the same outcome whether the failure comes from routing, authentication, authorisation or an application exception.
For a broader view of how software weaknesses surface in user-facing responses, the CWE Top 25 Guide is useful background because error disclosure, weak validation and related implementation flaws often show up together.
How error handling leaks information when defaults are left in place
The most common failure mode is not the absence of a page, but the presence of a verbose default. Frameworks and servers frequently return stack traces, module names, version strings, file paths, query fragments or configuration hints when no custom handler is defined. That output can help an attacker fingerprint the stack, confirm a route, or distinguish an application error from an authentication failure.
Custom error handling should therefore be treated as part of secure output design. The response should be accurate enough for the client to understand the condition, but not so detailed that it reveals implementation internals. In APIs, that usually means a concise machine-readable error code plus a short message. In browser flows, it usually means a human-friendly page that does not echo internal exceptions or debug data.
Error pages can also become a consistency problem. If one component returns a polished 404 but another returns a raw 500 with debug data, the attacker learns which layer failed and where to focus next. That is why the mitigation is not merely “build a page”, but “standardise the failure path” across all entry points.
The same principle is central to Cross-Site Scripting (XSS) Prevention Guide, because error messages become dangerous when they reflect untrusted input back into the page.
What to verify in web servers, apps and APIs before you trust the error path
Start by checking the actual responses, not the intended design. Trigger representative failures at each layer and confirm that the status code is correct, the body is neutral, and the content does not reveal stack traces, server banners, framework names or filesystem paths. Do this for not found, method not allowed, validation failures, authentication failures, authorisation failures and unexpected application exceptions.
Then verify that the behaviour is consistent across environments. Development settings, debug toggles, staging defaults and production overrides often drift apart, which is how verbose pages quietly reach production. The safest approach is to test the final deployed stack, including any CDN, load balancer, web server rewrite rule or API gateway that may replace the application’s own handler.
Reviewing the error path belongs in routine security checks because a custom page can fail as easily as any other control. If the page depends on templating, localisation, embedded assets or route logic, a broken dependency can cause a fallback to the very default response you were trying to avoid. A control that only works when everything else works is not enough.
The same verification mindset applies to API behaviour, which is why the OWASP API Security Top 10 is relevant whenever error handling needs to stay tight at the interface boundary.
Risk and Threat Considerations
Missing or inconsistent error pages create a disclosure path, not just a cosmetic defect. Attackers use verbose failures to identify technologies, map routes, infer permissions logic and validate whether a guessed endpoint, parameter or authentication state is meaningful. The risk increases when the same application emits different detail levels for different failure types, because that difference itself becomes an oracle.
Failure mechanism: The platform falls back to a framework default, debug mode or raw exception handler, and the response leaks internal detail or reveals which control failed.
Impact: An attacker gains reconnaissance value, can tune follow-on attacks more efficiently, and may learn enough about the environment to target authentication, authorisation or input-handling weaknesses with greater precision.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP API Security Top 10 addresses the attack and risk surface, while OWASP ASVS and CIS Controls v8 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP ASVS | V16 — Security Logging and Error Handling | Custom error pages and safe failure responses are part of secure error handling. |
| Recommendation — Return controlled error responses that avoid exposing internal implementation detail. | ||
| OWASP API Security Top 10 | API8 — Security Misconfiguration | Default error responses and debug leakage are common API misconfigurations. |
| Recommendation — Disable verbose defaults and standardize API error handling across environments. | ||
| CIS Controls v8 | CIS-16 — Application Software Security | Safe error handling is a secure application behaviour that reduces information disclosure. |
| Recommendation — Review application error responses to prevent stack traces and internal details from leaking. | ||
Practitioner Guidance
What to verify: Test the live error path for the exact responses users and clients receive, including edge cases where the web server, application and API layer disagree. Confirm that the status code is correct, the message is generic, and the response does not change in a way that reveals stack depth, route structure or privilege state.
Common mistake: Teams often fix the main 404 page but leave 500s, auth failures and API validation errors on defaults. That leaves the most useful reconnaissance channel untouched, because attackers usually learn more from exception handling than from the obvious “page not found” case.
Practitioner takeaway: Treat error handling as a security control, not a branding exercise, and verify every failure path that can surface in production before assuming the custom page is actually protecting you.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 19, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org