Skip to content

[wrangler] Warn when compliance region environment variable overrides config - #15058

Open
edmundhung wants to merge 2 commits into
mainfrom
edmundhung/warn-compliance-region-conflict
Open

[wrangler] Warn when compliance region environment variable overrides config#15058
edmundhung wants to merge 2 commits into
mainfrom
edmundhung/warn-compliance-region-conflict

Conversation

@edmundhung

@edmundhung edmundhung commented Aug 6, 2026

Copy link
Copy Markdown
Member

Warn when CLOUDFLARE_COMPLIANCE_REGION conflicts with the configured compliance region. The environment variable now takes precedence and Wrangler continues instead of rejecting the command, while explaining how the region was resolved.

This aligns Wrangler's behavior with cf's compliance-region resolution.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: This changes conflict handling and warning text without adding or changing configuration options.

A picture of a cute animal (not mandatory, but encouraged)


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2b629b5

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

This PR includes changesets to release 9 packages
Name Type
@cloudflare/workers-utils Patch
wrangler Patch
@cloudflare/autoconfig Patch
@cloudflare/cli-shared-helpers Patch
@cloudflare/deploy-helpers Patch
@cloudflare/remote-bindings Patch
@cloudflare/vite-plugin Patch
@cloudflare/vitest-pool-workers Patch
@cloudflare/workers-auth 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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Aug 6, 2026
@workers-devprod
workers-devprod requested review from a team and emily-shen and removed request for a team August 6, 2026 12:54
@workers-devprod

workers-devprod commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@ask-bonk ask-bonk 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.

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

Summary: replaces the hard error on a CLOUDFLARE_COMPLIANCE_REGION vs compliance_region conflict with a warning, letting the env var take precedence.

One thing worth calling out (design/safety), plus a minor note. The code itself is functionally correct.

Comment thread packages/workers-utils/src/environment-variables/misc-variables.ts
const resolvedRegion = getCloudflareComplianceRegion(config);
if (resolvedRegion === configuredRegion) {
return;
}

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.

Minor: readConfig is invoked multiple times within some commands (e.g. ConfigController re-reads on file changes during wrangler dev), so this warning may be emitted repeatedly in a single session. This matches the existing behaviour of logWarningsWithUpgradeHint, so it may be acceptable, but if you want it shown once, consider de-duplicating.

@ask-bonk

ask-bonk Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review posted successfully to PR #15058.

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

Summary: the PR replaces the hard error on a CLOUDFLARE_COMPLIANCE_REGION vs compliance_region conflict with a warning, letting the env var take precedence. The code is functionally correct.

Issues raised (ranked):

  1. Compliance-safety consideration — silently downgrading a stricter configured region (fedramp_high) to public via a stray env var is security-sensitive. Worth confirming with compliance owners that env-precedence should apply in the downgrade direction.
  2. Minor — the warning may be emitted repeatedly since readConfig is called multiple times in some commands (e.g. wrangler dev file-change reloads).

github run

@devin-ai-integration devin-ai-integration 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.

Devin Review found 2 potential issues.

View 1 additional finding in Devin Review.

Open in Devin Review

Comment on lines 102 to 104
return (
complianceRegionFromEnv || complianceConfig?.compliance_region || "public"
);

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.

🔴 Commands that only work in the public region can now silently talk to the FedRAMP endpoint

Commands that declare they only support the public region now have that declaration silently overridden by the environment variable (complianceRegionFromEnv || complianceConfig?.compliance_region at packages/workers-utils/src/environment-variables/misc-variables.ts:102-104) with no error or warning, so those commands quietly send their requests to the FedRAMP High servers instead.
Impact: Users with the FedRAMP environment variable set will see Pages, tail and similar commands fail or behave unexpectedly against the wrong servers, with no message explaining why.

Why the public-only marker is no longer honoured

Many call sites pass the COMPLIANCE_REGION_CONFIG_PUBLIC sentinel (packages/workers-utils/src/environment-variables/misc-variables.ts:75-79), documented as "Used for commands that explicitly do not support compliance regions other than 'public'" — e.g. packages/wrangler/src/tail/createTail.ts:86, packages/wrangler/src/pages/upload.ts:116, packages/wrangler/src/api/pages/deploy.ts:158.

Previously, when CLOUDFLARE_COMPLIANCE_REGION=fedramp_high was set, the removed conflict check threw a UserError, so the user was told the command could not run in that region. After this PR the env value simply wins, and getComplianceRegionSubdomain returns .fed, so requests go to api.fed.cloudflare.com for commands that explicitly do not support it.

The new warning added in packages/wrangler/src/config/index.ts:72-89 only fires when config.compliance_region is set in the user's config file during readConfig/readPagesConfig; it never covers the sentinel path, so the override is completely silent here.

Prompt for agents
Removing the conflict check in getCloudflareComplianceRegion means the CLOUDFLARE_COMPLIANCE_REGION environment variable now silently overrides COMPLIANCE_REGION_CONFIG_PUBLIC, the sentinel used by commands (Pages commands, tail, etc.) that explicitly do not support any region other than "public". Those commands will now issue requests against api.fed.cloudflare.com with no error or warning. Consider distinguishing the explicit "public-only" sentinel from a user-configured compliance_region: either keep erroring (or at least warn) when the env var conflicts with the public-only sentinel, or have those call sites bypass env resolution entirely so they always resolve to "public".
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment thread packages/workers-utils/src/environment-variables/misc-variables.ts
@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown
@cloudflare/autoconfig

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

@cloudflare/build-output-utils

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

@cloudflare/config

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

create-cloudflare

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

@cloudflare/deploy-helpers

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-functions

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@15058

@cloudflare/workers-auth

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: 2b629b5

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

@devin-ai-integration devin-ai-integration 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.

Devin Review found 2 new potential issues.

View 2 additional findings in Devin Review.

Open in Devin Review

Comment on lines 100 to 104
) => {
const complianceRegionFromEnv = getCloudflareComplianceRegionFromEnv();
if (
complianceRegionFromEnv !== undefined &&
complianceConfig?.compliance_region !== undefined &&
complianceRegionFromEnv !== complianceConfig.compliance_region
) {
throw new UserError(
dedent`
The compliance region has been set to different values in two places:
- \`CLOUDFLARE_COMPLIANCE_REGION\` environment variable: \`${complianceRegionFromEnv}\`
- \`compliance_region\` configuration property: \`${complianceConfig.compliance_region}\`
`,
{ telemetryMessage: false }
);
}
return (
complianceRegionFromEnv || complianceConfig?.compliance_region || "public"
);

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.

🟡 Account info command reports the wrong source for the compliance region

The compliance region source shown by the account info output is chosen purely from the configured value (complianceConfig?.compliance_region at packages/wrangler/src/user/whoami.ts:98) even though the environment variable now wins, so users are told the region came from their configuration file when it actually came from the environment.
Impact: Someone checking which compliance region they are operating in sees a misleading explanation of where that region came from, making a misconfigured environment variable hard to spot.

How removing the conflict error exposes the mislabelling in printComplianceRegion

Before this PR, getCloudflareComplianceRegion threw a UserError whenever CLOUDFLARE_COMPLIANCE_REGION and compliance_region disagreed, so printComplianceRegion (packages/wrangler/src/user/whoami.ts:95-105) could never be reached with conflicting values. Now the env var silently wins (packages/workers-utils/src/environment-variables/misc-variables.ts:100-105). With compliance_region: "public" in config and CLOUDFLARE_COMPLIANCE_REGION=fedramp_high, complianceRegion resolves to fedramp_high, but since complianceConfig.compliance_region is truthy the message says the region is set "via the Wrangler configuration".

A fix would be to compare the resolved region against the configured one (as logWarningsIfComplianceRegionIsOverridden in packages/wrangler/src/config/index.ts:72-89 does) and attribute the source to the environment variable when they differ.

(Refers to lines 100-105)

Prompt for agents
In packages/wrangler/src/user/whoami.ts, printComplianceRegion determines the "source" of the compliance region by checking whether complianceConfig.compliance_region is set. Previously a conflict between CLOUDFLARE_COMPLIANCE_REGION and the configured compliance_region threw a UserError, so a conflicting state was unreachable. After this PR the environment variable silently takes precedence, so when the config sets one region and the env var another, whoami reports the resolved (env-var) region but attributes it to the Wrangler configuration. Update the source attribution so it reflects which value actually won — e.g. attribute to the environment variable whenever the resolved region differs from the configured one, or when the env var is set.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines 100 to 104
) => {
const complianceRegionFromEnv = getCloudflareComplianceRegionFromEnv();
if (
complianceRegionFromEnv !== undefined &&
complianceConfig?.compliance_region !== undefined &&
complianceRegionFromEnv !== complianceConfig.compliance_region
) {
throw new UserError(
dedent`
The compliance region has been set to different values in two places:
- \`CLOUDFLARE_COMPLIANCE_REGION\` environment variable: \`${complianceRegionFromEnv}\`
- \`compliance_region\` configuration property: \`${complianceConfig.compliance_region}\`
`,
{ telemetryMessage: false }
);
}
return (
complianceRegionFromEnv || complianceConfig?.compliance_region || "public"
);

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.

🟨 Conflicting compliance region settings no longer block the command, allowing FedRAMP-configured projects to target the public region

The hard error that previously stopped Wrangler when CLOUDFLARE_COMPLIANCE_REGION disagreed with the configured compliance_region was removed (packages/workers-utils/src/environment-variables/misc-variables.ts:100-105), so a project explicitly configured for fedramp_high will now silently deploy against the public API endpoints whenever a stray or attacker-influenced environment variable sets public, downgraded to only a warning emitted at config-read time (packages/wrangler/src/config/index.ts:72-89).

(Refers to lines 100-105)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@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

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved

Development

Successfully merging this pull request may close these issues.

3 participants