[security-fix] Fix unhandled error in mcp_inspect.go waitForServerReady function #7823
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.
Security Fix: Unhandled Error in Response Body Close
Alert Number: #409
Severity: LOW
Rule: G104 - Errors unhandled
File: pkg/cli/mcp_inspect.go:462
Vulnerability Description
The security scanner detected an unhandled error when calling
resp.Body.Close()in thewaitForServerReadyfunction at line 462. According to Go best practices and security guidelines, errors fromClose()operations should always be checked, as they can indicate resource leaks or I/O failures.Fix Applied
Added proper error handling for
resp.Body.Close():resp.Body.Close()This ensures that any failures in closing the response body are properly logged for debugging purposes, while not affecting the main logic flow since this is a non-critical cleanup operation during server readiness polling.
Security Best Practices
Close(), error checking prevents silent failures and potential resource leaksTesting Considerations
truewhen the server responds successfully