From a79c920654966c4dc6102d8d84e52a342b3b6527 Mon Sep 17 00:00:00 2001 From: Razvan Stoenescu Date: Mon, 13 Jan 2025 10:10:37 +0200 Subject: [PATCH] fix(app-vite): filter env files keys (a-zA-Z0-9 chars only) #17744 --- app-vite/lib/utils/env.js | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/app-vite/lib/utils/env.js b/app-vite/lib/utils/env.js index 25ab0b00563..715c0123bd4 100644 --- a/app-vite/lib/utils/env.js +++ b/app-vite/lib/utils/env.js @@ -24,8 +24,9 @@ export function readFileEnv ({ ctx, quasarConf }) { const cache = cacheProxy.getRuntime(readFileEnvCacheKey, () => ({})) if (cache.configHash !== configHash) { - const result = getFileEnvResult(ctx.appPaths, { + const result = getFileEnvResult({ ...opts, + appPaths: ctx.appPaths, quasarMode: ctx.modeName, buildType: ctx.dev ? 'dev' : 'prod' }) @@ -48,15 +49,13 @@ export function readFileEnv ({ ctx, quasarConf }) { return cache.result } -function getFileEnvResult ( +function getFileEnvResult ({ appPaths, - { - quasarMode, - buildType, - envFolder = appPaths.appDir, - envFiles = [] - } -) { + quasarMode, + buildType, + envFolder = appPaths.appDir, + envFiles = [] +}) { const fileList = [ // .env // loaded in all cases @@ -120,15 +119,25 @@ function getFileEnvResult ( return {} } - const { parsed: fileEnv } = dotEnvExpand({ parsed: env }) + const rawFileEnv = {} + dotEnvExpand({ processEnv: rawFileEnv, parsed: env }) return { - fileEnv, + fileEnv: getFileEnv(rawFileEnv), usedEnvFiles, envFromCache: false } } +const validKeyRE = /^[a-zA-Z][a-zA-Z0-9_]+/ +function getFileEnv (env) { + const validKeys = Object.keys(env).filter(key => validKeyRE.test(key)) + return validKeys.reduce((acc, key) => { + acc[ key ] = env[ key ] + return acc + }, {}) +} + /** * Get the final env definitions to supply to * the build system (Vite or Esbuild).