Skip to content

Add G118 SSA analyzer for context propagation failures that can cause goroutine/resource leaks#1516

Merged
ccojocar merged 2 commits intosecurego:masterfrom
ccojocar:rule_context_propagation_failuer
Feb 15, 2026
Merged

Add G118 SSA analyzer for context propagation failures that can cause goroutine/resource leaks#1516
ccojocar merged 2 commits intosecurego:masterfrom
ccojocar:rule_context_propagation_failuer

Conversation

@ccojocar
Copy link
Copy Markdown
Member

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.

… 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
Copy link
Copy Markdown

codecov bot commented Feb 15, 2026

Codecov Report

❌ Patch coverage is 68.20175% with 145 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.91%. Comparing base (a7666f3) to head (f286c40).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
analyzers/context_propagation.go 68.20% 95 Missing and 50 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ccojocar ccojocar merged commit 2b2077e into securego:master Feb 15, 2026
6 of 8 checks passed
@ccojocar ccojocar deleted the rule_context_propagation_failuer branch February 15, 2026 20:44
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