Safeguard
Security Guides•

Do you need a reverse proxy in front of a Node.js app in production?

Fastify calls exposing Node directly an anti pattern, and Node's docs tie DoS protection to a proxy. What a proxy handles and what your app must still do

Safeguard Security Team
3 min read

For internet facing apps, yes, in nearly every case. The Fastify documentation calls exposing Node directly to the internet an anti pattern, and Node's own HTTP docs say that timeouts must be set when there is no reverse proxy, to protect against denial of service. A proxy or load balancer takes on the network edge jobs.

What the docs say

The Fastify recommendations page says the temptation is to write applications that handle multiple domains and ports and expose them directly, and that the team strongly considers this an anti pattern. Its reasons are added complexity in the application and blocked horizontal scalability. Its example needs are multiple instances, TLS termination, HTTP to HTTPS redirects, multiple domains and static files.

The Node.js http documentation says headersTimeout and requestTimeout should be non zero, for example 120 seconds, to protect against potential denial of service in case the server is deployed without a reverse proxy in front.

Express's own security guide recommends handling TLS with a dedicated server such as Nginx.

Who does what

JobProxy or balancerYour Node app
TLS certificates and terminationYesOptional
HTTP to HTTPS redirectYesNo
Slow client and header timeoutsYes, first lineYes, second line
Request size capYesYes
Static files and compressionOftenRarely
Authentication and authorizationSometimes coarseYes, always
Input validationNoYes
Rate limits by accountNoYes

The right column never goes away. A proxy reduces exposure. It does not understand your business rules.

New risks the proxy brings

Putting a proxy in front changes what your app sees. Client addresses arrive in forwarded headers, so you must configure trust carefully. See Express trust proxy and Fastify trustProxy and rate limit keys. Make sure the app is only reachable through the proxy, otherwise a client can skip the proxy and send forged headers directly.

Steps

  1. Run the app on a private interface or network, reachable only from the proxy.
  2. Terminate TLS at the proxy and redirect HTTP to HTTPS there.
  3. Set client header and body timeouts and a body size cap on the proxy.
  4. Keep timeouts and limits in the app too. See Node.js HTTP server timeouts.
  5. Configure trust proxy to match your chain, and test with forged headers.
  6. Keep health checks and graceful shutdown aligned between proxy and app.

When you might not need one

Platform services that already put a managed edge in front of your code count as a reverse proxy for this purpose. What matters is that something other than your Node process faces the open internet.

Safeguard's asset discovery can help find services that are exposed without an edge in front, and a free scan is available at gold.safeguard.sh/scan.

Quick check

Is Node.js production ready without a proxy?

Node can serve HTTP directly, but the Fastify docs advise against exposing it, and Node's docs rely on timeouts to compensate when no proxy exists.

Does a proxy remove the need for body limits in my app?

No. Keep both, since internal traffic or misconfiguration can reach the app without the proxy.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.