Although it may not be feasible or desirable to prevent the disclosure of absolutely any information that an attacker may find useful, various relatively straightforward measures can be taken to reduce information leakage to a minimum and to withhold the mostsensitive data that can critically undermine an application's security if disclosed to an attacker.
The application should never return verbose error messages or debug information to the user'sbrowser. When an unexpected event occurs(such as an error in a databasequery, a failure to read a file from disk, or an exception in an external API call), the application should return the same generic message informing the user that an error occurred. If it is necessary torecord debug information for support or diagnostic purposes, this should be heldin a server-side log that is not publicly accessible. An index number to the relevant log entry may be returned to the user, enabling him or her to report this when contacting the help desk, if required.
Most application platforms and web servers can be configured to mask error information from being returned to the browser: