studio icon indicating copy to clipboard operation
studio copied to clipboard

STUDIO_GITHUB_CLIENT_SECRET becomes public when the project is compiled

Open melishev opened this issue 1 year ago • 14 comments

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


melishev avatar Nov 27 '25 18:11 melishev

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,

BenjaminOddou avatar Nov 28 '25 09:11 BenjaminOddou

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.

melishev avatar Nov 28 '25 09:11 melishev

@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 avatar Nov 28 '25 09:11 melishev

@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 avatar Nov 28 '25 09:11 BenjaminOddou

@BenjaminOddou Yes, but Nuxt already supports variables in the runtime environment...

melishev avatar Nov 28 '25 09:11 melishev

@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 avatar Nov 28 '25 09:11 BenjaminOddou

@BenjaminOddou Okay, is it possible to fix this so that variables are not hardcoded in the Docker Image?

melishev avatar Nov 28 '25 10:11 melishev

@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 avatar Nov 28 '25 12:11 farnabaz

@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.

melishev avatar Nov 28 '25 13:11 melishev

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:

  1. The Nuxt app is build in a GitHub action (no env variables exist here)
  2. The GitHub action calls our deployment provider, uploads the .output folder and starts the application
  3. The deployment provider injects the STUDIO_GITHUB_CLIENT_ID and STUDIO_GITHUB_CLIENT_SECRET env variables (among a few other app-specific NUXT_* variables)
  4. 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()?

larsrickert avatar Jan 14 '26 12:01 larsrickert

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?

kaziller avatar Jan 19 '26 05:01 kaziller

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?

melishev avatar Jan 19 '26 08:01 melishev

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?

kaziller avatar Jan 19 '26 08:01 kaziller

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 ?

anthonylorendeaux avatar Jan 20 '26 09:01 anthonylorendeaux