[wrangler] Fix case-insensitive-env leaking stale duplicate keys on override - #14999
Merged
petebacondarwin merged 3 commits intoAug 16, 2026
Merged
petebacondarwin merged 3 commits into
petebacondarwin merged 3 commits into
Conversation
🦋 Changeset detectedLatest commit: a3c5e60 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
workers-devprod
requested review from
a team and
emily-shen
and removed request for
a team
August 3, 2026 17:05
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
emily-shen
requested review from
petebacondarwin
and removed request for
emily-shen
August 5, 2026 16:36
petebacondarwin
approved these changes
Aug 10, 2026
Contributor
|
Codeowners approval required for this PR:
Show detailed file reviewers |
workers-devprod
approved these changes
Aug 10, 2026
workers-devprod
left a comment
Contributor
There was a problem hiding this comment.
Codeowners reviews satisfied
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/config
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
…verride The case-insensitive Proxy used for .env loading on Windows tracked the current casing for a key in a side Map, but its set/defineProperty/ deleteProperty traps never removed the old differently-cased property from the underlying target object. get/has still resolved correctly through the tracking map, but Object.keys/for...in/JSON.stringify/spread over the resulting object (which is assigned directly to process.env) exposed both the stale and current key. Fix set/defineProperty to delete the previous casing's property before writing the new one, and deleteProperty to remove the tracked casing rather than whatever casing the caller happened to pass.
Per review feedback: changesets should describe what changed for users, not implementation details like which Proxy traps were touched.
petebacondarwin
force-pushed
the
fix/case-insensitive-env-stale-keys
branch
from
August 10, 2026 10:15
0fc6313 to
3d5f0db
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
case-insensitive-env.tsleaking stale, differently-cased duplicate keys.On Windows,
wranglerloads.envvalues through a case-insensitiveProxywrapper (packages/wrangler/src/config/case-insensitive-env.ts) so lookups likeenv.PATHandenv.Pathresolve to the same value, and this object is assigned directly toprocess.env(packages/wrangler/src/config/dot-env.ts). When a key is set again under a different casing (e.g..env.localoverriding a value from.envwith different casing), the previous casing's property was never removed from the underlying target object.get/hasstill resolved correctly through the internal tracking map, but anything that enumeratesprocess.env—Object.keys,for...in,JSON.stringify, object spread, or a spawned subprocess inheriting the environment — saw both the stale and current key.The
set,defineProperty, anddeletePropertytraps now keep exactly one own-property per case-insensitive key, so enumeration always reflects only the current value. (deletePropertyhad the same class of bug in the other direction: it deleted from the internal tracking map by canonical key but issuedReflect.deletePropertyusing whatever casing the caller passed, sodelete env.pathafterenv.PATH = ...left an orphaned, untrackedPATHproperty on the target — fixed the same way, by resolving the tracked casing first.)Repro (before the fix):