Skip to content

fix(common): make encryption key header output consistent with CreateHmacKeyResponse - #16725

Open
kalragauri wants to merge 2 commits into
googleapis:mainfrom
kalragauri:rest-encryption-key-header-output
Open

kalragauri wants to merge 2 commits into
googleapis:mainfrom
kalragauri:rest-encryption-key-header-output

Conversation

@kalragauri

@kalragauri kalragauri commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

MakeSpanHttp, TracingRestClient, HttpHeader::DebugString, and the curl debug formatters DebugSendHeader and DebugInfo now use [censored] for the values of the x-goog-encryption-key and x-goog-copy-source-encryption-key headers, the same placeholder CreateHmacKeyResponse uses. Sibling headers such as x-goog-encryption-key-sha256 and x-goog-encryption-algorithm, the existing authorization truncation, and the headers sent on the wire are unchanged.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces changes to censor sensitive customer-supplied encryption keys (x-goog-encryption-key and x-goog-copy-source-encryption-key) in both curl debug logs and OpenTelemetry span attributes. Specifically, it adds helper functions in curl_wrappers.cc and rest_opentelemetry.cc to identify and replace these header values with [censored], and includes comprehensive unit tests in curl_wrappers_test.cc and rest_opentelemetry_test.cc to verify correct behavior across various formats (such as HTTP/2 and HTTP/3 bracketed traces). The implementation is clean, conforms to the repository's C++17 style guidelines, and I have no further feedback or changes to suggest.

@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.42857% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.80%. Comparing base (fdcfe38) to head (615086c).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
google/cloud/internal/curl_wrappers.cc 97.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16725      +/-   ##
==========================================
+ Coverage   92.78%   92.80%   +0.01%     
==========================================
  Files        2279     2279              
  Lines      228396   228572     +176     
==========================================
+ Hits       211921   212117     +196     
+ Misses      16475    16455      -20     

☔ View full report in Codecov by Harness.
📢 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.

@kalragauri
kalragauri force-pushed the rest-encryption-key-header-output branch from f922d71 to fa847b4 Compare November 30, 2026 10:52
@kalragauri
kalragauri marked this pull request as ready for review November 30, 2026 10:56
@kalragauri
kalragauri requested a review from a team as a code owner November 30, 2026 10:56

@scotthart scotthart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in curl_wrappers.cc and rest_opentelemetry.cc look very clean, and the unit test coverage for line endings, bracketed HTTP/2 & HTTP/3 traces, sibling headers, and Bearer ordering is thorough.

One gap to address before merging:

  1. Missing redaction in EndResponseSpan (google/cloud/internal/tracing_rest_client.cc:72-89):
    WrappedRequest calls MakeSpanHttp(request, method) and then EndResponseSpan(std::move(span), context, ...), which also sets http.request.header.<name> attributes on the same span from context.headers(). EndResponseSpan already censors authorization and x-goog-api-key (tested in TracingRestClient.CensorsAuthFields), but does not redact x-goog-encryption-key or x-goog-copy-source-encryption-key. Any caller supplying these headers via RestContext::AddHeader or CustomHeadersOption (via rest_internal::SetMetadata) will still record the plaintext key on the span (and overwrite MakeSpanHttp's [censored] value if set in both). Could we share IsCensoredHeader (or a small helper in rest_opentelemetry.{h,cc}) between MakeSpanHttp and EndResponseSpan, and add a test case in google/cloud/internal/tracing_rest_client_test.cc?

  2. Optional nit (google/cloud/internal/http_header.cc:64-72):
    HttpHeader::DebugString() currently truncates all values to 10 characters. It's only called for duplicate authorization/content-length headers in CurlImpl::MergeAndWriteHeaders today so there's no active leak, but returning [censored] for encryption key headers there too could be nice defense-in-depth.

@kalragauri

Copy link
Copy Markdown
Contributor Author

The changes in curl_wrappers.cc and rest_opentelemetry.cc look very clean, and the unit test coverage for line endings, bracketed HTTP/2 & HTTP/3 traces, sibling headers, and Bearer ordering is thorough.

One gap to address before merging:

  1. Missing redaction in EndResponseSpan (google/cloud/internal/tracing_rest_client.cc:72-89):
    WrappedRequest calls MakeSpanHttp(request, method) and then EndResponseSpan(std::move(span), context, ...), which also sets http.request.header.<name> attributes on the same span from context.headers(). EndResponseSpan already censors authorization and x-goog-api-key (tested in TracingRestClient.CensorsAuthFields), but does not redact x-goog-encryption-key or x-goog-copy-source-encryption-key. Any caller supplying these headers via RestContext::AddHeader or CustomHeadersOption (via rest_internal::SetMetadata) will still record the plaintext key on the span (and overwrite MakeSpanHttp's [censored] value if set in both). Could we share IsCensoredHeader (or a small helper in rest_opentelemetry.{h,cc}) between MakeSpanHttp and EndResponseSpan, and add a test case in google/cloud/internal/tracing_rest_client_test.cc?
  2. Optional nit (google/cloud/internal/http_header.cc:64-72):
    HttpHeader::DebugString() currently truncates all values to 10 characters. It's only called for duplicate authorization/content-length headers in CurlImpl::MergeAndWriteHeaders today so there's no active leak, but returning [censored] for encryption key headers there too could be nice defense-in-depth.

Thanks - done. Shared IsCensoredHeader in http_header.{h,cc}, applied it in EndResponseSpan and HttpHeader::DebugString(), and added unit tests in tracing_rest_client_test.cc and http_header_test.cc.

@kalragauri
kalragauri requested a review from scotthart December 1, 2026 08:34

This branch has not been deployed

No deployments
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.

2 participants