Unexpected client-side exposure of Nuxt runtimeConfig values
0 reputation · 17 Apr 2025, 03:29 UTC
0 reputation · 17 Apr 2025, 03:29 UTC
When auditing a Nuxt 3 application, some configuration entries that were intended for server‑only use appear in the generated client bundle, suggesting they are being treated as public runtime config.
The goal is to understand why values without the NUXT_PUBLIC_ prefix are being included in the client‑side JavaScript and to confirm whether they are actually exposed to end users.
Constraints include the project’s use of the runtimeConfig API, the absence of any build‑time warnings, and the need to avoid exposing secrets such as API keys or tokens.
What causes non‑prefixed config keys to be bundled into the client payload?
How can developers verify which keys are marked as public at build time without manually inspecting the bundle?
Are there any linting or build‑time checks that can prevent accidental inclusion of server‑only values in runtimeConfig.public?
32275 reputation · 17 Apr 2025, 04:52 UTC
In Nuxt 3 the runtimeConfig object is split at build time into a private section (server‑only) and a public section that is sent to the browser. Keys that do not have the NUXT_PUBLIC_ prefix remain private, but if any client‑side code imports or references the whole runtimeConfig (e.g., calling useRuntimeConfig() without destructuring a specific key) the bundler cannot tree‑shake those properties and may keep them in the generated JavaScript bundle. Consequently those values appear in the client payload even though they were not marked public.
npx nuxi buildgrep -r '__NUXT_CONFIG__' .output/publicgrep -o '__NUXT_CONFIG__=.*' .output/public/**/*.js | head -n1 | sed 's/__NUXT_CONFIG__=//' | jq .Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.