STUDIO_GITHUB_CLIENT_SECRET becomes public when the project is compiled
Environment
Version
1.0.0-alpha.2
Reproduction
Description
The variable becomes publicly accessible, even though it is critically private. This is a serious security breach. Shouldn't this variable only be accessible in the node.js runtime environment?
Additional context
No response
Logs
Hey @melishev, are they public in the client bundle ? I think it's normal if the key is present on server side.
P10109:~/project/.output$ grep -r "STUDIO_GITHUB_CLIENT_SECRET"
server/chunks/nitro/nitro.mjs: clientSecret: process.env.STUDIO_GITHUB_CLIENT_SECRET,
I apologize, it seems I was mistaken. I thought variables were written during compilation, in the frontend part of the application, and were available in the browser.
@BenjaminOddou Can you help me? I am compiling my application in Docker Image, but I don't understand how to transfer variables only when starting the Image. Currently, if I don't specify the variables during compilation, they will not be available during execution.
@melishev I think these env varibles must be accessible during build otherwise it won't be compiled in server files. Here I found docker docs
@BenjaminOddou Yes, but Nuxt already supports variables in the runtime environment...
@melishev Yes but the module nuxt-studio doesn't know you runtimeConfig as it calls directly variables with process.env
https://github.com/nuxt-content/studio/blob/75d9494053dd8690a2e7ab4c831264dab437dd29/src/module/src/runtime/server/routes/auth/github.get.ts#L86
@BenjaminOddou Okay, is it possible to fix this so that variables are not hardcoded in the Docker Image?
@melishev You don't need to do anything in Docker image, all you need it to pass STUDIO_GITHUB_CLIENT_SECRET into your container. with docker run .., docker compose or where you run your image
@farnabaz The problem is that when I build an image according to your instructions, and if env was not specified during the build, it will not see them when subsequently launched via docker compose.
Hey! I'm just entering the discussion :) We are facing the same issue where the client ID and secret are not available in the deployed application because the env variables are added by our deployment provider, not during the build in our GitHub pipeline. So our deployment steps are:
- The Nuxt app is build in a GitHub action (no env variables exist here)
- The GitHub action calls our deployment provider, uploads the
.outputfolder and starts the application - The deployment provider injects the
STUDIO_GITHUB_CLIENT_IDandSTUDIO_GITHUB_CLIENT_SECRETenv variables (among a few other app-specificNUXT_*variables) - When trying to open Nuxt Studio on the deployed application, we get a "Missing GitHub client ID or secret" error
Is there any way to get this working? Nuxt itself supports such "runtime" env variables so it would be great if Nuxt Studio is not limited here. Is there any specific reason why Nuxt Studio currently uses process.env directly instead of e.g. using useRuntimeConfig()?
Hi!
I have spend some time to get this running on my VPS with dokploy and docker compose. I have decided to go with Netlify/Vercel for other reasons now. Still I would like to share my findings.
Since the env variables are needed at build time, you need to inject them into the build process. I have found out, that Netlify/Vercel inject env variables (which are added to project) at build time out of the box. Docker by design does not do that. You can though (as @BenjaminOddou mentioned) add secrets into the build stage and make the value for the secrets taken from env variables (https://docs.docker.com/compose/how-tos/use-secrets/#build-secrets). Let me show you my example:
Dockerfile
# Build stage
FROM node:24-alpine AS build
WORKDIR /app
RUN corepack enable
COPY package.json pnpm-lock.yaml ./
RUN pnpm install
COPY . ./
ENV NODE_ENV=production
ENV NODE_OPTIONS=--max-old-space-size=4096
RUN --mount=type=secret,id=studio_client_id \
--mount=type=secret,id=studio_client_secret \
sh -c "export STUDIO_GITHUB_CLIENT_ID=$(cat /run/secrets/studio_client_id) \
&& export STUDIO_GITHUB_CLIENT_SECRET=$(cat /run/secrets/studio_client_secret) \
&& pnpm run build"
# Production stage
FROM node:24-alpine
WORKDIR /app
COPY --from=build /app/.output/ ./
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
EXPOSE ${PORT}
CMD ["node", "/app/server/index.mjs"]
docker-compose.yml
services:
web:
build:
context: .
dockerfile: Dockerfile
secrets:
- studio_client_id
- studio_client_secret
ports:
- "3000:3000"
environment:
STUDIO_GITHUB_CLIENT_ID: ${STUDIO_GITHUB_CLIENT_ID}
STUDIO_GITHUB_CLIENT_SECRET: ${STUDIO_GITHUB_CLIENT_SECRET}
secrets:
studio_client_id:
environment: STUDIO_GITHUB_CLIENT_ID
studio_client_secret:
environment: STUDIO_GITHUB_CLIENT_SECRET
If you are using a similar deployment process like @larsrickert: You would need to add the required values as environment secrets in Github Settings -> Secrets and variables -> Actions -> Environment Secrets. Then adjust the build step in your workflow as follows:
...
steps:
...
- name: Build
run: pnpm run build
env:
STUDIO_GITHUB_CLIENT_ID: ${{ secrets.STUDIO_GITHUB_CLIENT_ID }}
STUDIO_GITHUB_CLIENT_SECRET: ${{ secrets.STUDIO_GITHUB_CLIENT_SECRET }}
...
...
Even though I have managed to make it work with my VPS/dokploy/Docker setup, I think having the env variables not required at build time would be a better approach. The real question, why are they required at build time? My guess has to be this here: https://github.com/nuxt-content/nuxt-studio/blob/48fca5bdf330a3a379a82d15961dff4ed14c1c60/src/module/src/module.ts#L252-L261
I would need to have a look deeper into this but since its labeled as discussion, do you think the sessionSecret can be computed during runtime?
That's all fine, but my Docker Image is public after compilation. I would prefer that the variables not be hardcoded into it; instead, I would prefer that they be passed on startup.
I haven't studied how Nuxt Studio works, but is it possible to transfer these variables to Node.js?
Yes, that's why I would currently not publish a Docker Image or a build artifact anywhere, especially when you have created it by passing secrets to it. Better to build where you run it (Vercel/Netlify/Docker compose + injecting secrets from envs).
If these are no options then I think you need to disable this until nuxt studio does not require these env variables during runtime. Or maybe someone else has an idea?
Hello, someone has tried to publish it to netlify already ? I wanted to use it on my portofolio but i encountered the same issue with secret used at build time. Do we know if it's intended or it will be fixed later ?