You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+12-14Lines changed: 12 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -190,6 +190,18 @@ An updater function can also be passed to the `env` option to update the environ
190
190
}
191
191
```
192
192
193
+
### trustProxy
194
+
195
+
Set to `true` to trust proxy-related HTTP headers (`X-Forwarded-For`, `X-Forwarded-Proto`, and `Host`). This affects CGI environment variables such as:
196
+
197
+
-`REMOTE_ADDR` — will use the leftmost IP in `X-Forwarded-For`
198
+
-`HTTPS` — will be `"on"` if `X-Forwarded-Proto` is `"https"`
199
+
-`SERVER_NAME` and `SERVER_PORT` — will be parsed from the `Host` header
200
+
201
+
Default: `false`
202
+
203
+
> ⚠️ **Important:** Only enable this if you are **running behind a trusted reverse proxy** (like Nginx or a load balancer). Enabling `trustProxy` when exposed to the public internet can allow **header spoofing** by clients.
204
+
193
205
# Start a CGI Server from the Command Line
194
206
195
207
The command `cgi-server` can be used to run an HTTP server to serve CGI scripts.
@@ -303,20 +315,6 @@ http {
303
315
}
304
316
```
305
317
306
-
### ⚠️ Note on Proxy Headers and CGI Environment Variables
307
-
308
-
If you run `cgi-core` behind a reverse proxy (such as **Nginx**), certain CGI environment variables may be influenced by proxy headers, including:
309
-
310
-
-`REMOTE_ADDR` — may reflect the proxy's IP unless `X-Forwarded-For` is set
311
-
-`HTTPS` — determined by `X-Forwarded-Proto` if TLS is terminated at the proxy
312
-
-`SERVER_NAME` — usually derived from the `Host` header sent by the proxy
313
-
314
-
By default, `cgi-core`**does not validate proxy headers**. If untrusted clients can set headers like `X-Forwarded-For`, this could result in spoofed values being passed to your CGI scripts.
315
-
316
-
🔐 **Important**: Make sure your reverse proxy is properly configured and only accepts requests from trusted sources. If needed, filter or overwrite proxy headers before they reach your Node.js server.
317
-
318
-
_You may choose to implement your own logic for handling trusted proxies or wait for future support of a `trustProxy` option._
319
-
320
318
# License
321
319
322
320
`cgi-core` is released under the [MIT License](https://github.com/lfortin/node-cgi-core/blob/master/LICENSE).
0 commit comments