Skip to content

Commit 2371c1c

Browse files
committed
Filter environmet variables to prevent unintended leakage of environment variables.
1 parent 9e4a7f8 commit 2371c1c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

vite.config.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ import autoprefixer from 'autoprefixer'
55

66
export default defineConfig(({ mode }) => {
77
// Load .env
8-
const env = loadEnv(mode, process.cwd(), '')
9-
process.env = { ...process.env, ...env }
8+
const viteEnv = loadEnv(mode, process.cwd(), '')
9+
const env = {}
10+
11+
// Filter env to variables starting with VITE_APP or VUE_APP
12+
Object.keys({...process.env, ...viteEnv}).forEach(key => {
13+
if (key.startsWith('VITE_APP') || key.startsWith('VUE_APP')) {
14+
env[key] = viteEnv[key]
15+
}
16+
})
1017

1118
return {
1219
plugins: [vue()],
@@ -53,7 +60,7 @@ export default defineConfig(({ mode }) => {
5360
},
5461
define: {
5562
// vitejs does not support process.env so we have to redefine it
56-
'process.env': process.env,
63+
'process.env': env,
5764
},
5865
}
5966
})

0 commit comments

Comments
 (0)