Check environment variables and source maps
Public build configuration is public information
Vite replaces exposed environment constants during the client build. Values with the default VITE_ prefix are available to browser code, so treat them as public. A build mode selects mode-specific configuration; it is not identical to NODE_ENV. Public configuration values normally arrive as strings. Never expose a database password, signing key or privileged API token. A custom exposure prefix or an explicit replacement in config can also leak values; the absence of the default prefix is not a proof of secrecy.
// Validate public configuration at the application boundary.export function parsePublicConfig(raw) { if (typeof raw.VITE_APP_TITLE !== 'string' || !raw.VITE_APP_TITLE.trim()) throw new Error('Missing title'); if (!['true','false'].includes(raw.VITE_REPORT_ENABLED)) throw new Error('Expected true or false'); return {title:raw.VITE_APP_TITLE.trim(), reportEnabled:raw.VITE_REPORT_ENABLED === 'true'};}For a synthetic .env.production, use VITE_APP_TITLE=Workbench and VITE_REPORT_ENABLED=false. The parser returns {title: "Workbench", reportEnabled: false}. The string "false" is truthy in JavaScript, so Boolean(raw.VITE_REPORT_ENABLED) would be wrong. Invalid input fails with a clear error before a feature makes assumptions. Type declarations for import.meta.env improve editor feedback but do not validate actual build inputs.
import React from 'react';import {parsePublicConfig} from './env.mjs';export function PublicSettings() { const config = parsePublicConfig({ VITE_APP_TITLE: import.meta.env.VITE_APP_TITLE, VITE_REPORT_ENABLED: import.meta.env.VITE_REPORT_ENABLED }); return <section><h2>{config.title}</h2><p>{config.reportEnabled ? 'Reports enabled' : 'Reports disabled'}</p></section>;}This component is an independent staged example. Feature availability is not authorization: even if a report button is hidden, the server must check whether a caller can request restricted data. Changing a static host environment variable after deploying an existing bundle generally will not change a value embedded at build time. For runtime configuration, load an explicitly public configuration document with a versioned schema and safe caching, not a secret store.
Source maps and release review
Source maps associate generated positions with original source for debugging. Public maps can expose source or embedded source text; a hidden map suppresses the normal map reference but may still write a map file. Choose an explicit policy: this fixture forbids public map files, including inline maps, while a production team might upload private maps to an approved error monitoring service and exclude them from public artifacts. Disabling maps is not a security boundary: delivered JavaScript is inspectable.
// A limited check of an inventoried release, not a general secret scanner.export function auditRelease(files, marker = 'SYNTHETIC_PRIVATE_MARKER_56') { if (typeof marker !== 'string' || marker.length === 0) throw new Error('Marker required'); const problems = []; for (const [name, text] of Object.entries(files)) { if (name.endsWith('.map')) problems.push('Public source map: ' + name); if (typeof text === 'string' && text.includes(marker)) problems.push('Private marker: ' + name); if (typeof text === 'string' && /sourceMappingURL\s*=\s*data:/i.test(text)) problems.push('Inline source map: ' + name); } return problems.sort();}Example: auditRelease({"assets/main.js":"SYNTHETIC_PRIVATE_MARKER_56","assets/main.js.map":"{}"}) returns two findings. This check is intentionally narrow: it checks a known fake marker and common source-map representations, not arbitrary obfuscated secrets, binary files or actual deployment contents. Review source, lockfiles, build config, public files and environment handling; use a suitable approved scanner and verify what the host serves.
Practice a release gate
Given a manifest and a public-file inventory, require all expected assets, no known private marker, and no public source map under the selected policy. Separately require semantic type checks and browser acceptance. Record which checks actually ran. A successful local model test is not a successful Vite build, and a successful build is not proof of correct deployment.