[ACM-30430] Sanitize error messages to prevent information disclosure#1991
[ACM-30430] Sanitize error messages to prevent information disclosure#1991dislbenn wants to merge 1 commit intostolostron:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dislbenn The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
📝 WalkthroughWalkthroughThis PR updates auto-generated deepcopy methods to properly deep-copy slice fields, refactors error handling across OCM modules to use structured logging with generic error messages, and simplifies build constraints by removing deprecated directives. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/ocm/subscription/provider.go (1)
118-136:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPopulate
StatusCodeandResponseon every subscription error path.The non-JSON branch returns
StatusCode == 0, and the parsed-error branch dropsResponsewheneverReasonis present.pkg/ocm/subscription/service.goswitches onerr.StatusCode, so a 401/404/429/5xx with a plain-text or HTML body will now miss the empty-list fallback and bubble an error instead.Suggested fix
if response.StatusCode > 299 { var errResponse SubscriptionError if err := json.Unmarshal(bytes, &errResponse); err != nil { logf.V(1).Info("Subscription API error response", "status", response.StatusCode, "body", string(bytes)) return nil, &SubscriptionError{ Error: fmt.Errorf("failed to retrieve subscription information"), Response: bytes, + StatusCode: response.StatusCode, } } logf.V(1).Info("Subscription API error", "status", response.StatusCode, "reason", errResponse.Reason) + errResponse.Response = bytes if errResponse.Reason == "" { errResponse.Error = fmt.Errorf("failed to retrieve subscription information") - errResponse.Response = bytes - } else { - errResponse.Error = fmt.Errorf("failed to retrieve subscription information") } + errResponse.Error = fmt.Errorf("failed to retrieve subscription information") errResponse.StatusCode = response.StatusCode return nil, &errResponse }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/ocm/subscription/provider.go` around lines 118 - 136, The code paths for subscription API errors don't always populate StatusCode and Response: when json.Unmarshal fails the SubscriptionError returned lacks StatusCode, and when parsing succeeds but errResponse.Reason != "" the parsed errResponse drops Response; update the error handling so the SubscriptionError literal (constructed when json.Unmarshal fails) includes StatusCode: response.StatusCode, and always set errResponse.Response = bytes (in the parsed-error branch regardless of Reason) before returning; keep setting errResponse.StatusCode = response.StatusCode and return &errResponse as before.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@pkg/ocm/auth/provider.go`:
- Around line 105-116: The parsed auth error handling currently only sets
errResponse.Response when ErrorMessage or Description is empty, losing the raw
response for other parsed failures; modify the logic in the auth error handling
(where errResponse.Code is set and logf.V(1).Info is called) to assign
errResponse.Response = bytes unconditionally for non-2xx responses before the
subsequent branch that checks errResponse.ErrorMessage and
errResponse.Description so every parsed auth error retains the raw payload
(leave the existing Error/ErrInvalidToken assignments intact).
---
Outside diff comments:
In `@pkg/ocm/subscription/provider.go`:
- Around line 118-136: The code paths for subscription API errors don't always
populate StatusCode and Response: when json.Unmarshal fails the
SubscriptionError returned lacks StatusCode, and when parsing succeeds but
errResponse.Reason != "" the parsed errResponse drops Response; update the error
handling so the SubscriptionError literal (constructed when json.Unmarshal
fails) includes StatusCode: response.StatusCode, and always set
errResponse.Response = bytes (in the parsed-error branch regardless of Reason)
before returning; keep setting errResponse.StatusCode = response.StatusCode and
return &errResponse as before.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Enterprise
Run ID: 42a4c1ca-d509-4700-b0d7-eb561aced9ad
📒 Files selected for processing (8)
api/v1/zz_generated.deepcopy.goapi/v1alpha1/zz_generated.deepcopy.gocontrollers/discoveredcluster_controller.gopkg/ocm/auth/provider.gopkg/ocm/cluster/client.gopkg/ocm/subscription/provider.gopkg/ocm/subscription/service.gopkg/ocm/tls_util.go
💤 Files with no reviewable changes (1)
- api/v1alpha1/zz_generated.deepcopy.go
Fixes ACM-30430 by removing internal API details (status codes, response bodies, error codes) from user-facing error messages. All sensitive details now logged at V(1) level for debugging while returning generic error messages to users. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com> Signed-off-by: dislbenn <dbennett@redhat.com>
ba363d9 to
d81ecdd
Compare
Summary
Fixes ACM-30430 by sanitizing error messages that expose internal API structure and implementation details.
Changes
Removed sensitive information from user-facing error messages across OCM API clients and controllers:
All internal details now logged at V(1) debug level for troubleshooting while returning generic error messages to users.
Files Modified
pkg/ocm/cluster/client.go- Generic "failed to retrieve cluster information"pkg/ocm/auth/provider.go- Generic "authentication failed"pkg/ocm/subscription/provider.go- Generic "failed to retrieve subscription information"pkg/ocm/subscription/service.go- Sanitized status code logspkg/ocm/tls_util.go- Generic "failed to retrieve TLS configuration"controllers/discoveredcluster_controller.go- Generic "invalid authentication configuration"Testing
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores