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
> [`x-forwarded-proto`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto) and [`x-forwarded-host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host) are de facto standard headers that forward the original protocol and host if you're using a reverse proxy (think load balancers and CDNs). You should only set these variables if you trust the reverse proxy.
66
66
67
+
The [RequestEvent](https://kit.svelte.dev/docs/types#additional-types-requestevent) object passed to hooks and endpoints includes an `event.clientAddress` property representing the client's IP address. By default this is the connecting `remoteAddress`. If your server is behind one or more proxies (such as a load balancer), this value will contain the innermost proxy's IP address rather than the client's, so we need to specify an `ADDRESS_HEADER` to read the address from:
68
+
69
+
```
70
+
ADDRESS_HEADER=True-Client-IP node build
71
+
```
72
+
73
+
> Headers can easily be spoofed. As with `PROTOCOL_HEADER` and `HOST_HEADER`, you should [know what you're doing](https://adam-p.ca/blog/2022/03/x-forwarded-for/) before setting these.
74
+
67
75
All of these environment variables can be changed, if necessary, using the `env` option:
68
76
69
77
```js
@@ -72,6 +80,7 @@ env: {
72
80
port:'MY_PORT_VARIABLE',
73
81
origin:'MY_ORIGINURL',
74
82
headers: {
83
+
address:'MY_ADDRESS_HEADER',
75
84
protocol:'MY_PROTOCOL_HEADER',
76
85
host:'MY_HOST_HEADER'
77
86
}
@@ -85,9 +94,23 @@ MY_ORIGINURL=https://my.site \
85
94
node build
86
95
```
87
96
88
-
### trustProxy
97
+
### xForwardedForIndex
98
+
99
+
If the `ADDRESS_HEADER` is `X-Forwarded-For`, the header value will contain a comma-separated list of IP addresses. For example, if there are three proxies between your server and the client, proxy 3 will forward the addresses of the client and the first two proxies:
In order for `event.clientAddress` to show the client's IP address, `adapter-node` must read it from one of several possible request headers. Since these headers can be spoofed, it will only do this if `trustProxy` is `true`.
113
+
For that reason you should always use a negative number (depending on the number of proxies) if you need to trust `event.clientAddress`. In the above example, `0` would yield the spoofed address while `-3` would continue to work.
0 commit comments