Commit 060ca9d
committed
fix(client-api): parse single-IP X-Forwarded-For values
`XForwardedFor::decode` required a comma in the header value via
`split_once(',').ok_or_else(headers::Error::invalid)?`, so any client
coming through a single-hop proxy — which emits `X-Forwarded-For: <ip>`
with no comma — failed to decode.
Previously this was silent: `Option<TypedHeader<XForwardedFor>>` in
`crates/client-api/src/routes/subscribe.rs` resolved to `None` on
decode error under axum 0.7. axum 0.8 (landed in #2713) changed the
behavior: the same decoder `Err` now surfaces as a 400 Bad Request,
which breaks all WebSocket subscribe requests from single-hop proxy
clients — reproducible with:
```
curl -v -H 'Connection: Upgrade' -H 'Upgrade: websocket' \
-H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' \
-H 'Sec-WebSocket-Protocol: v2.bsatn.spacetimedb' \
-H 'x-forwarded-for: 1.2.3.4' \
"http://127.0.0.1:3000/v1/database/test/subscribe?token=..."
# => HTTP/1.1 400 Bad Request
# => invalid HTTP header (x-forwarded-for)
```
Accept both comma-separated and single-IP forms: take the first
entry (trimmed) regardless of whether a comma is present. This
matches how Nginx, Apache, HAProxy, etc. read the same header.1 parent b1d5c59 commit 060ca9d
1 file changed
Lines changed: 42 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
0 commit comments