Skip to content

fix(confidential-http): sanitize response headers to valid UTF-8#18

Merged
vreff merged 1 commit into
mainfrom
fix/confidential-http-header-utf8-sanitize
Jul 23, 2026
Merged

fix(confidential-http): sanitize response headers to valid UTF-8#18
vreff merged 1 commit into
mainfrom
fix/confidential-http-header-utf8-sanitize

Conversation

@prashantkumar1982

Copy link
Copy Markdown
Collaborator

Problem

The confidential-http StandardCapability failed to return responses whenever an upstream server sent an HTTP header containing non-UTF-8 bytes. The gRPC marshaler (which validates that proto string fields are valid UTF-8) rejected the response, surfacing as:

rpc error: code = Internal desc = grpc: error while marshaling: string field contains invalid UTF-8

Response headers are populated directly from Go's http.Header, whose names and values may contain arbitrary bytes. These land in the proto string fields of HeaderValues (enclave/apps/confidential-http/app/app.go), so any invalid UTF-8 broke marshaling of the entire capability response. (The response body is bytes and was unaffected.)

Fix

convertHeaders now sanitizes header names and values via a new sanitizeUTF8 helper, which replaces invalid bytes with the Unicode replacement character (U+FFFD) and returns already-valid strings unchanged (zero-cost in the common case).

Tests

  • TestConvertHeaders_PreservesValidUTF8 — valid names/values (incl. multi-byte UTF-8) pass through untouched.
  • TestConvertHeaders_SanitizesInvalidUTF8 — invalid bytes in names/values are sanitized, valid siblings untouched, and the resulting Response now proto.Marshals without error.
  • TestSanitizeUTF8_ReturnsValidStringUnchanged — helper returns valid inputs identically.

All pass locally.

Note

The same bug exists in the mirror confidential-compute repo; this PR fixes only chainlink-confidential-compute per request.

🤖 Generated with Claude Code

HTTP header names and values may contain arbitrary bytes, but the proto
HeaderValues fields are strings and must be valid UTF-8 to be marshaled
over gRPC. When an upstream server returned a header with invalid UTF-8,
the StandardCapabilities client failed to marshal the response with:

  grpc: error while marshaling: string field contains invalid UTF-8

convertHeaders now sanitizes header names and values, replacing invalid
bytes with U+FFFD while leaving already-valid strings untouched. Adds
unit tests covering preservation of valid UTF-8, sanitization of invalid
bytes, and that the resulting Response marshals successfully.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@prashantkumar1982
prashantkumar1982 requested a review from a team as a code owner July 23, 2026 18:58
@github-actions

Copy link
Copy Markdown

👋 prashantkumar1982, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@vreff
vreff merged commit a46e0e4 into main Jul 23, 2026
46 of 48 checks passed
@vreff
vreff deleted the fix/confidential-http-header-utf8-sanitize branch July 23, 2026 22:26
vreff added a commit that referenced this pull request Jul 23, 2026
…ader-utf8-sanitize

fix(confidential-http): sanitize response headers to valid UTF-8
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.

3 participants