Repository navigation
[wrangler] Reject non-UTF-8 .dev.vars and .env files instead of loading no variables - #16719
Conversation
… of loading no variables
🦋 Changeset detectedLatest commit: 6583573 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 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 |
|
Hi @jaeminbird. Thanks for taking the time to contribute to Workers SDK. This PR has been automatically closed because you are not currently a registered (vouched) collaborator for this repository. AI tools now let our team generate proposed code changes quickly. Reviewing changes, checking that they solve the right problem, and maintaining code quality over time still take substantial care and effort. We therefore limit PRs to registered collaborators so we can focus that effort where it is most useful. For the majority of external contributors, the most effective way to help is through issues: describing a problem or use case, providing a minimal reproduction, investigating its cause, or helping us verify a fix. Those contributions help us understand what needs to change and are very welcome. We will take an initial look at this PR and decide whether it is something we want to invest time in reviewing and maintaining. We may reopen it if we decide to proceed, but we cannot guarantee that it will be reopened or receive a full review. |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
|
This pull request's reviews are posted as pull request reviews: see the review of |
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
@clanky-the-clanker review |
There was a problem hiding this comment.
Superseded by the review of
65835736.
This review, of 7459bf43
💬 Approved with comments — The fix is correct and well tested. The only note is an optional readability point about the try/catch layout in tryLoadDotDevDotVars.
Findings: 1 suggestion (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 suggestion
The change is correct. One optional readability point in dev-vars.ts.
Recommendation: 💬 Optional Nits
- [SUGGESTION]
tryLoadDotDevDotVarsnow reads the file outside its try/catch, so the "Failed to load local dev variables file" wrapper no longer covers the read. (packages/wrangler/src/dev/dev-vars.ts:158)
View full review
packages/wrangler/src/dev/dev-vars.ts:158:readEnvFile(basePath)now runs before thetry. That is intentional: wrapping it would hide the "save as UTF-8"UserErrorbehind a genericError. Thetrynow only guardsdotenv.parse, though, and the layout still reads as if the read were protected.
No problems found in the rest of the change:
- The
loadDotEnvrewrite keeps the override semantics. - UTF-8 BOM handling is the same on both paths.
logger.once.warnprevents repeated warnings for the same file.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
No issues found.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
The changeset accurately describes the change.
Reviewed commit: 7459bf43
dario-piotrowicz
left a comment
There was a problem hiding this comment.
Thanks for the PR @jaeminbird 🙏
Generally looks good to me, with a few suggestions 🙂
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
|
Pushed af969c1: removed the try/catch in |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
|
Merged current main in (6583573); the |
|
@clanky-the-clanker review |
There was a problem hiding this comment.
✅ Approved — No issues found. The earlier note about the try/catch layout is fixed, and the encoding check is correct and covered by tests.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
The new messages contain only the file path, never variable values. The change adds no injection or secret-exposure risk.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The try/catch in tryLoadDotDevDotVars was removed, so the encoding UserError reaches the user unwrapped. The code no longer looks as if the read were guarded.
readEnvFile returns undefined on ENOENT and on ENOTDIR. loadDotEnv merges files with Object.assign, which keeps the override behaviour. A bad .env produces a single logger.once.warn. The tests cover:
- UTF-16LE
.dev.varswith and without a BOM - UTF-16LE
.env - a UTF-8 file with a BOM, as a control
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
The changeset accurately describes the new behaviour.
Reviewed commit: 65835736
Fixes #16718.
"API_KEY=abc" > .dev.varsin Windows PowerShell 5.1 writes UTF-16LE. Wrangler read the file as UTF-8, dotenv found no variables, andwrangler devstill printedUsing secrets defined in .dev.varswhile the Worker sawenv.API_KEYasundefined.This follows #16521, which made the same check for
.assetsignore: the newreadEnvFiledecodes withTextDecoder("utf-8", { fatal: true })and rejects null characters (BOM-less UTF-16). A bad.dev.varsstopswrangler devwith aUserErrorthat says to save the file as UTF-8. A bad.envis skipped with one warning, because.envfiles are also loaded by every wrangler command, not justdev. UTF-8 files, with or without a BOM, load as before.Testing
dev.test.ts: 3 new tests (UTF-16LE.dev.varswith and without a BOM, and a UTF-16LE.envwith a BOM) fail on main and pass with the fix on Windows 11 and on Linux (node:24). A control test, a UTF-8.dev.varswith a BOM and CRLF, passes on both..dev.varsnow gives the error; a UTF-8 file still shows both bindings.dev,loadDotEnv,case-insensitive-env,print-bindings,secretandtype-generationtests pass (378). oxlint, oxfmt and tsc are clean.pnpm checkand remote E2E tests were not run.