Skip to content

[wrangler, workers-utils, containers-shared] Add custom Cloudflare API headers - #16739

Merged
petebacondarwin merged 2 commits into
mainfrom
custom-api-headers
Nov 9, 2026
Merged

petebacondarwin merged 2 commits into
mainfrom
custom-api-headers

Conversation

@GregBrimble

@GregBrimble GregBrimble commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Allow Wrangler to send additional API headers through CLOUDFLARE_API_HEADERS, for example CLOUDFLARE_API_HEADERS='{"X-Custom-Header":"value"}' npx wrangler deploy. Configured values override existing unprotected names case-insensitively.

Custom-header diagnostics use the existing WRANGLER_LOG_SANITIZE setting: values are hidden by default and included when it is false.


@changeset-bot

changeset-bot Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b55be5a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
wrangler Minor
@cloudflare/workers-utils Minor
@cloudflare/workers-auth Minor
@cloudflare/containers-shared Minor
@cloudflare/vitest-plugin Patch
@cloudflare/autoconfig Patch
@cloudflare/cli-shared-helpers Patch
@cloudflare/deploy-helpers Patch
@cloudflare/remote-bindings Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@16739

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@16739

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@16739

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@16739

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@16739

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@16739

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@16739

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@16739

miniflare

npm i https://pkg.pr.new/miniflare@16739

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@16739

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@16739

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@16739

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@16739

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@16739

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@16739

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@16739

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@16739

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@16739

wrangler

npm i https://pkg.pr.new/wrangler@16739

commit: b55be5a

ask-bonk[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

I'm Bonk, and I've done a quick review of your PR.

PR #16739 adds configurable, redacted Cloudflare API headers across Wrangler and container API clients.

  1. P2 packages/workers-utils/src/custom-api-headers.ts:180 Empty Location headers incorrectly stop redirect handling and return a raw 302 only when custom headers are enabled. Posted one inline suggestion.

github run

@GregBrimble
GregBrimble force-pushed the custom-api-headers branch 5 times, most recently from 165a322 to f028834 Compare November 5, 2026 19:18
@GregBrimble
GregBrimble marked this pull request as ready for review November 5, 2026 20:32
@workers-devprod
workers-devprod requested review from a team and edmundhung and removed request for a team November 5, 2026 20:32
@workers-devprod

workers-devprod commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/cloudchamber
  • ✅ @cloudflare/wrangler
Show detailed file reviewers

devin-ai-integration[bot]

This comment was marked as resolved.

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Superseded by the review of c216ea35.

This review, of f028834b

💬 Approved with comments — The implementation is sound and well tested. There are two non-blocking notes: an exported helper that nothing uses, and container debug logs that now print real header values.

Findings: 1 info · 1 suggestion (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info · 1 suggestion

Two minor notes: an exported helper nothing uses, and container debug logs that now print header values.

Recommendation: 💬 Optional Nits

  • [INFO] Container debug logs now print real header values, including X-Auth-Key, when sanitization is off (packages/containers-shared/src/client/core/request.ts:510)
  • [SUGGESTION] createNativeCustomApiFetch is exported but nothing uses or tests it (packages/workers-utils/src/custom-api-headers.ts:23)
View full review
  • createNativeCustomApiFetch (packages/workers-utils/src/custom-api-headers.ts:23) is not called anywhere and has no tests. It is still exported as public API, and it reads process.env on its own instead of going through getCustomApiHeaders.
  • Container request debug logging used to call JSON.stringify(<Headers>), which prints {}. It now prints real header values, so X-Auth-Key and X-Auth-Email appear when WRANGLER_LOG_SANITIZE=false.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md concerns.


⚡ Performance: ✅ LGTM

When the variable is unset, getCustomApiHeaders returns early. When it is set, the JSON parse on each request costs little next to the network call.


📝 Documentation: ✅ LGTM

The changeset and the linked docs PR describe the feature.


Reviewed commit: f028834b

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Superseded by the review of b55be5a2.

This review, of c216ea35

💬 Approved with comments — The implementation is sound and well tested. Two earlier non-blocking notes are still open: an exported helper that nothing uses, and container debug logs that can print X-Auth-Key and X-Auth-Email when sanitization is off.

Findings: 1 info · 1 suggestion (2 are inline comments on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info · 1 suggestion

Two earlier non-blocking notes are still open, and nothing new was found.

Recommendation: 💬 Optional Nits

  • [INFO] Container debug logs now print X-Auth-Key and X-Auth-Email when sanitization is off (packages/containers-shared/src/client/core/request.ts:508)
  • [SUGGESTION] createNativeCustomApiFetch is exported but never called or tested (packages/workers-utils/src/custom-api-headers.ts:24)
View full review
  • Unused export: createNativeCustomApiFetch (packages/workers-utils/src/custom-api-headers.ts:24) has no callers and no tests. It also checks process.env.CLOUDFLARE_API_HEADERS itself instead of going through getCustomApiHeaders.
  • Container header logging: packages/containers-shared/src/client/core/request.ts:508 deletes only Authorization before logging. When WRANGLER_LOG_SANITIZE=false, X-Auth-Key and X-Auth-Email are printed in the debug output. Before this change these logs printed {}.

✅ All other checks passed

🔒 Security: ✅ LGTM

No security issues found.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md concerns.


⚡ Performance: ✅ LGTM

getCustomApiHeaders returns early when CLOUDFLARE_API_HEADERS is unset. When it is set, the JSON parse on each request costs little next to the network call.


📝 Documentation: ✅ LGTM

The changeset and the linked docs PR describe the feature.


Reviewed commit: c216ea35

@petebacondarwin petebacondarwin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we avoid adding the public API that we cannot remove outside of a major bump, where we can keep it simpler.

@github-project-automation github-project-automation Bot moved this from Untriaged to In Review in workers-sdk Nov 6, 2026

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💬 Approved with comments — The implementation is sound and well tested, and the unused export has been removed. One non-blocking INFO is still open: debug header logs can print X-Auth-Key and X-Auth-Email when sanitization is turned off.

Findings: 1 info (1 is an inline comment on the diff)

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


📋 Code Quality: 💬 1 info

Sound implementation. One earlier INFO on debug header logging is still open.

Recommendation: 💬 Optional Nits

  • [INFO] Debug header logs can print X-Auth-Key and X-Auth-Email when WRANGLER_LOG_SANITIZE=false (also in wrangler/src/cfetch/internal.ts logRequest) (packages/containers-shared/src/client/core/request.ts:510)
View full review
  • Header logging: packages/containers-shared/src/client/core/request.ts:507-510 and packages/wrangler/src/cfetch/internal.ts logRequest delete only Authorization before logging headers. Before this change these sites ran JSON.stringify on a Headers object, which prints {}. They now print real entries, so with WRANGLER_LOG_SANITIZE=false the legacy X-Auth-Key and X-Auth-Email credentials show up in debug output. With the default setting the whole HEADERS: payload is hidden.
  • createNativeCustomApiFetch has been removed since the last review, so that earlier note is resolved.

✅ All other checks passed

🔒 Security: ✅ LGTM

Header names and values are validated with validateHeaderName and validateHeaderValue. Protected headers and duplicate names are rejected, and keys are defined so that __proto__ cannot pollute the object. CLOUDFLARE_API_HEADERS is local input at the same trust level as the API token.


📖 AGENTS.md: ✅ LGTM

No AGENTS.md concerns.


⚡ Performance: ✅ LGTM

No performance concerns.


📝 Documentation: ✅ LGTM

The changeset and the linked docs PR describe the feature.


Reviewed commit: b55be5a2

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

@petebacondarwin
petebacondarwin merged commit 6af492e into main Nov 9, 2026
122 of 124 checks passed
@petebacondarwin
petebacondarwin deleted the custom-api-headers branch November 9, 2026 15:39
@github-project-automation github-project-automation Bot moved this from In Review to Done in workers-sdk Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants