Add OWASP A10:2025 exception handling composite recipe#817
Draft
Add OWASP A10:2025 exception handling composite recipe#817
Conversation
…tStackTrace Add a new composite recipe org.openrewrite.staticanalysis.security.OwaspA10 that bundles existing exception-handling recipes addressing OWASP Top 10 2025 A10 (Mishandling of Exceptional Conditions). Also add a new RemovePrintStackTrace recipe that removes Throwable#printStackTrace() calls which can expose sensitive information. The composite recipe includes coverage for: - Empty catch blocks (EmptyBlock, RenameExceptionInEmptyCatch, CatchClauseOnlyRethrows) - Overly broad exception types (OnlyCatchDeclaredExceptions, UnnecessaryCatch, CombineSemanticallyEqualCatchBlocks) - Sensitive info in error output (RemoveSystemOutPrintln, RemovePrintStackTrace) - Null safety (EqualsAvoidsNull, AnnotateNullableMethods, AnnotateNullableParameters) - Resource leak prevention (BufferedWriterCreationRecipes) Fixes moderneinc/customer-requests#1839
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
org.openrewrite.staticanalysis.security.OwaspA10bundling 12 recipes for OWASP Top 10 2025 A10 (Mishandling of Exceptional Conditions)RemovePrintStackTracerecipe that removesThrowable#printStackTrace()callsRemovePrintStackTraceProblem
OWASP 2025 introduced A10 covering improper error handling, including empty catch blocks that swallow exceptions, overly broad exception types, sensitive info leaked via stack traces, and missing null checks. There was no composite recipe to address this category.
Solution
Created a declarative composite recipe that bundles existing exception-handling recipes (EmptyBlock, OnlyCatchDeclaredExceptions, CatchClauseOnlyRethrows, etc.) along with a new
RemovePrintStackTracerecipe. The new recipe usesMethodMatcher("java.lang.Throwable printStackTrace(..)")to detect and remove allprintStackTraceoverloads.Test plan
Existing tests pass
New tests added for RemovePrintStackTrace (basic removal, PrintStream overload, false positives, preserving other statements, no-op)
Full build passes including recipe CSV validation
Fixes moderneinc/customer-requests#1839