Skip to content

Accept padded base64 in binary request headers - #3155

Open
rajputdivyanshu81 wants to merge 2 commits into
TraceMachina:mainfrom
rajputdivyanshu81:fix/accept-padded-binary-headers
Open

rajputdivyanshu81 wants to merge 2 commits into
TraceMachina:mainfrom
rajputdivyanshu81:fix/accept-padded-binary-headers

Conversation

@rajputdivyanshu81

Copy link
Copy Markdown
Contributor

What and why

The gRPC wire format says implementations "MUST accept padded and un-padded values" for -bin headers. The inbound decoder for build.bazel.remote.execution.v2.requestmetadata-bin used BASE64_STANDARD_NO_PAD, so a padded value failed to decode and the request metadata (tool name, invocation and correlation ids) was silently dropped. A new decode_binary_header() strips trailing = and is used both inbound and in the outbound forwarding path, which already did the same thing inline.

Refs #3117

How was this verified?

New tests decode the same RequestMetadata from a padded and an unpadded header and check both give the same result. The padded case fails without the change. The nativelink-util tests that cover telemetry pass locally (Windows, cargo, 18 tests). I haven't run the Bazel targets locally; CI covers them.

reference/protocol-api.mdx gets one sentence on the behavior.

Risk

Low. Values that decoded before decode the same way; only padded values, which were dropped, now decode. The outbound path's behavior is unchanged, it just shares the helper now.

AI assistance

Claude Code found this during a REAPI conformance audit, made the change, wrote the tests and ran them. I reviewed every line.

The gRPC wire format says implementations "MUST accept padded and
un-padded values" for -bin headers. The inbound decoder for
build.bazel.remote.execution.v2.requestmetadata-bin used
BASE64_STANDARD_NO_PAD, so a padded value failed to decode and the request
metadata was silently dropped. decode_binary_header() strips trailing '='
and is used both inbound and in the outbound forwarding path, which already
did the same inline.

Refs TraceMachina#3117

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nativelink Ready Ready Preview Nov 10, 2026 12:56pm UTC
nativelink-aidm Ready Ready Preview Nov 10, 2026 12:56pm UTC

Request Review


if let Some(bazel_header) = req.headers().get(BAZEL_REQUESTMETADATA_HEADER)
&& let Ok(decoded) = BASE64_STANDARD_NO_PAD.decode(bazel_header.as_bytes())
&& let Ok(decoded) = decode_binary_header(bazel_header.as_bytes())

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.

Why not just use BASE64_STANDARD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BASE64_STANDARD on its own requires padding in base64 0.22, so it would reject the unpadded values gRPC clients are told to send. The spec says implementations "MUST accept padded and un-padded values" and should send unpadded. Your comment did point at a cleaner fix, though: I've replaced the manual = stripping with a standard-alphabet engine using DecodePaddingMode::Indifferent, so one decoder accepts both forms. Pushed in 43de32c.

Review feedback: rather than stripping trailing `=` by hand, decode with a
standard-alphabet engine whose padding mode is Indifferent. BASE64_STANDARD
alone would reject the unpadded values gRPC clients are told to send.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

2 active deployments
Preview – nativelink — 43de32ce Deployed Nov 10, 2026 by vercel[bot]
Preview – nativelink-aidm — 43de32ce Deployed Nov 10, 2026 by vercel[bot]
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