Skip to content

Potential fix for code scanning alert no. 117: Information exposure through a stack trace#10

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

Potential fix for code scanning alert no. 117: Information exposure through a stack trace#10
davewichers wants to merge 1 commit intomainfrom
alert-autofix-117

Conversation

@davewichers
Copy link
Member

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

In general, to fix information exposure through stack traces, avoid writing e.printStackTrace(...) to any stream that is visible to external users (like response.getWriter()). Instead, log the exception using the server’s logging facility and return a generic error message or HTTP error code to the client. The client should not see the stack trace, while the server log retains enough information for debugging.

For this specific file, the best minimal fix is to remove the calls to e.printStackTrace(response.getWriter()) in each catch block (lines 113, 119, 125, 131, 137, 143) and replace them with server‑side logging. We can use the log(String, Throwable) method inherited from HttpServlet, which requires no new imports. The user will still see the existing generic message printed just above each printStackTrace call and the subsequent ServletException will propagate appropriately. Concretely:

  • In each catch block (NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, InvalidAlgorithmParameterException), replace e.printStackTrace(response.getWriter()); with log("Problem executing crypto", e); (or similar).
  • Do not otherwise change the flow or error messages already sent to the client.
  • No additional imports or helper methods are needed.

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

…hrough a stack trace

Fix INFO LEAK in Benchmark00684.java

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