Add G118 SSA analyzer for context propagation failures that can cause goroutine/resource leaks#1516
Merged
ccojocar merged 2 commits intosecurego:masterfrom Feb 15, 2026
Conversation
… goroutine/resource leaks This PR introduces G118, a new SSA-based gosec rule that detects high-risk context misuse patterns: goroutines using context.Background/TODO when request context exists, missing cancel() calls from WithCancel/WithTimeout/WithDeadline, and unbounded blocking loop regions without ctx.Done() guards. These patterns can leak goroutines and I/O resources, leading to resource exhaustion/DoS in production services. The rule is mapped to CWE-400, integrated into analyzer registration and docs, and includes positive/negative samples (including complex loop CFG cases) to reduce false positives while preserving detection quality. Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1516 +/- ##
==========================================
- Coverage 77.43% 76.91% -0.52%
==========================================
Files 96 97 +1
Lines 7750 8206 +456
==========================================
+ Hits 6001 6312 +311
- Misses 1472 1567 +95
- Partials 277 327 +50 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
This PR introduces G118, a new SSA-based gosec rule that detects high-risk context misuse patterns: goroutines using context.Background/TODO when request context exists, missing cancel() calls from WithCancel/WithTimeout/WithDeadline, and unbounded blocking loop regions without ctx.Done() guards.These patterns can leak goroutines and I/O resources, leading to resource exhaustion/DoS in production services.The rule is mapped to CWE-400, integrated into analyzer registration and docs, and includes positive/negative samples (including complex loop CFG cases) to reduce false positives while preserving detection quality.