Skip to content

Potential fix for code scanning alert no. 76: Information exposure through an error message#11

Draft
davewichers wants to merge 1 commit intomainfrom
alert-autofix-76
Draft

Potential fix for code scanning alert no. 76: Information exposure through an error message#11
davewichers wants to merge 1 commit intomainfrom
alert-autofix-76

Conversation

@davewichers
Copy link
Member

Potential fix for https://github.com/aspectsecurity/TestCodeQL/security/code-scanning/76

In general, to fix this type of issue you should avoid sending raw exception messages (or stack traces) back to the client. Instead, log the detailed error on the server side for diagnostics, and respond to the client with a generic, non-sensitive error message (for example, “An internal error occurred while processing your request”).

For this specific file, the best fix is to change the catch (IOException e) block so that it no longer writes e.getMessage() to the HTTP response. Instead, it should log the exception using a server-side logging mechanism (for example, System.err.println in this constrained context) and send a simple, generic message to the client. This preserves existing functionality (the servlet still reports that an error occurred) while preventing leakage of internal information.

Concretely:

  • In src/main/java/org/owasp/benchmark/testcode/Benchmark00825.java, lines 83–87, replace the body of the catch block.
  • Keep the existing console logging line or slightly improve it by including e so stack trace is available on the server.
  • Change response.getWriter().println(org.owasp.esapi.ESAPI.encoder().encodeForHTML(e.getMessage())); to a generic string like "Problem executing cmdi - Case" or "An unexpected error occurred while processing your request.", without using e.getMessage().

No new imports are strictly required; we can rely on System.err or the existing System.out without changing imports.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…rough an error message

Bad INFO LEAK fix for Benchmark00825.java:85

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant