Redact webhook response body from returned errors#5191
Open
Conversation
3 tasks
doHTTPCall previously embedded the first 256 bytes of any non-2xx webhook response body into the returned error. That error then propagated into slog.Error in the validating and mutating middlewares, so a tenant who pointed MCPWebhookConfig.url at an internal service could read up to 256 bytes of any error response straight into the cluster's logs. Move the body preview to slog.Debug inside the webhook package so operators can still troubleshoot, and shape the returned error as status-code-only. The webhook name is still attached by NewNetworkError / NewInvalidResponseError, and the status code is still preserved on InvalidResponseError so IsAlwaysDenyError continues to detect HTTP 422. A new TestClientErrorDoesNotLeakResponseBody test pins the contract: the returned err.Error() must contain the status code but must not contain sentinel bytes from the response body. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
bde4ae2 to
195ec7d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5191 +/- ##
=======================================
Coverage 67.64% 67.64%
=======================================
Files 606 606
Lines 61797 61809 +12
=======================================
+ Hits 41801 41813 +12
+ Misses 16839 16838 -1
- Partials 3157 3158 +1 ☔ 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.
Summary
Follow-up to the round-2 review of #4564 (item #8).
pkg/webhook/client.godoHTTPCallpreviously embedded the first 256 bytes of any non-2xx webhook response body into the returned error. That error then propagated intoslog.Errorin the validating and mutating middlewares, so a tenant who pointedMCPWebhookConfig.urlat an internal service could read up to 256 bytes of any error response straight into the cluster's logs.This PR moves the body preview to
slog.Debuginside the webhook package so operators can still troubleshoot, and shapes the returned error as status-code-only. The webhook name is still attached byNewNetworkError/NewInvalidResponseError, and the status code is still preserved onInvalidResponseErrorsoIsAlwaysDenyErrorcontinues to detect HTTP 422.Type of change
Test plan
task test—pkg/webhook/...passes with-race)golangci-lintreports 0 issues)TestClientErrorDoesNotLeakResponseBodyis table-driven across HTTP 500, 503, 422, and 418, and pins the contract:err.Error()must contain the status code but must not contain a sentinel string from the response body.Special notes for reviewers
client.go.🤖 Generated with Claude Code