Repository navigation
chore: refuse settings read at build through import.meta.env - #230
Merged
Merged
Conversation
Vite replaces import.meta.env.X in server code with X's value at build, and the release publishes the server bundle. A secret read that way would ship in a public release, and any setting read that way would make the tarball depend on the machine that built it. Measured: a variable set only for the build and read as import.meta.env.X in a route came out as its value in dist/server, while the same read through process.env stayed a read. Every setting already comes from process.env, so nothing changes in the code. ESLint now refuses any import.meta.env read but Astro's own flags (PROD, DEV, MODE, SSR, BASE_URL, SITE, ASSETS_PREFIX), which are the same on every machine, and refuses reading the object whole. CLAUDE.md states the rule beside the one on Astro's key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J3VdAGPsVYY55a4BDjPKRT
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.
Vite replaces
import.meta.env.Xin server code with X's value at build, and the release publishes the server bundle. So a secret read that way would ship in a public release, and any setting read that way would make the tarball depend on the machine that built it. Every setting already comes fromprocess.env, read when the server runs, but nothing held that. Reading throughimport.meta.envis how Astro's guide reads a setting, so it's the easy way to break it.What changes
import.meta.envread other than Astro's own flags:PROD,DEV,MODE,SSR,BASE_URL,SITEandASSETS_PREFIX. Those come from the config and the command, the same on every machine. Reading the object whole (const env = import.meta.env, destructuring, spreading) is refused too.The code doesn't change: its one read is
import.meta.env.PROD.Measured
import.meta.env.PROBE_SECRET_Aandprocess.env.PROBE_SECRET_B, built with both set. The first came out as its literal value indist/server, and the second stayedprocess.env.PROBE_SECRET_B..SMTP_PASS,?.SECRET,["SECRET"],.PUBLIC_X), the bare object, destructuring and spreading. It does so in a.tsmodule, in.astrofrontmatter and in an.astroscript.PROD,DEVandSITE, plain and with?., andimport.meta.dirname.Checks. The pre-push gate passed: lint, typecheck, format, 629 tests, build, page budgets and the forms check.
🤖 Generated with Claude Code
https://claude.ai/code/session_01J3VdAGPsVYY55a4BDjPKRT