nitrojs / nitrojs/nitro

Security improvement: Static $HOST and $PORT in production build

Open
#1,400 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug nuxt preset:node-cluster preset:node-server security v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Environment

Node Version: v18.12.0
Nuxt Version: 3.6.1
Nitro Version: 2.5.2

Reproduction

All reproduction on nuxt3 app:

Reproduction 1:

Write into file .env content HOST=127.0.0.1
yarn build
node .output/server/index.mjs gives output Listening http://[::]:3000
Expected result: Listening 127.0.0.1
Actual result: nuxt webapp listening on all public interfaces, circumventing reverse proxy (nginx)

Reproduction 2:

Write into nuxt.config.js: runtimeConfig: { NITRO_HOST: "1.2.3.4", HOST: "5.5.5.5" }
yarn build
node .output/server/index.mjs gives output Listening http://[::]:3000
Expected result: Listening 1.2.3.4 or Listening 5.5.5.5
Actual result: nuxt webapp listening on all public interfaces, circumventing reverse proxy (nginx)

Describe the bug

When run without any environment variables node .output/server/index.mjs will listen on all available interfaces.

This is a security concern, because in production environment webapps will be run behind a reverse proxy such as nginx (caching, ssl stripping) and/or behind a web application firewall such as cloudflare.

Sysadmins easily forget to use HOST=127.0.0.1 node .output/server/index.mjs in order to start a service.

I think production builds should have a fail-safe default configuration, e.g. limiting exposure of the web application.
At a minimum, there should be an option for nuxt3 users to hard-code the $HOST and $PORT in the production build, so that the environment variables $NITRO_HOST and $HOST can be set to a reasonable default value (e.g. localhost).

Additional context

This issue has been previously raised in https://github.com/unjs/nitro/issues/1028 but it was not discussed.
I pointed out security implications for nuxt3 in https://github.com/nuxt/nuxt/issues/21961#issue-1790027475 where it was recommended to come here.

Logs

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with .env and nuxt.config.js, then inspect the generated .output/server/index.mjs and the HOST, PORT, and NITRO_HOST entry points. Compare the built server's binding with the requested localhost or configured address, and clarify which fail-safe or build-time configuration is intended before defining done.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, nuxtjs, typescript
Domain
backend, security
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.