Skip to content

Redact webhook response body from returned errors#5191

Open
JAORMX wants to merge 1 commit intomainfrom
pr/webhook-error-redaction
Open

Redact webhook response body from returned errors#5191
JAORMX wants to merge 1 commit intomainfrom
pr/webhook-error-redaction

Conversation

@JAORMX
Copy link
Copy Markdown
Collaborator

@JAORMX JAORMX commented May 5, 2026

Summary

Follow-up to the round-2 review of #4564 (item #8). pkg/webhook/client.go 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.

This PR moves the body preview to slog.Debug inside the webhook package so operators can still troubleshoot, and shapes 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.

Type of change

  • Bug fix

Test plan

  • Unit tests (task testpkg/webhook/... passes with -race)
  • Linting (scoped golangci-lint reports 0 issues)
  • New TestClientErrorDoesNotLeakResponseBody is 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

  • Pairs with #pr-webhook-ssrf-fix (item Implement secret injection #5). The two PRs are independently mergeable; whichever lands second will need a trivial rebase on client.go.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label May 5, 2026
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>
@JAORMX JAORMX force-pushed the pr/webhook-error-redaction branch from bde4ae2 to 195ec7d Compare May 5, 2026 10:17
@github-actions github-actions Bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels May 5, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.64%. Comparing base (1f138ee) to head (195ec7d).

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.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant