fix(ip): use RFC 7239 for forwarded header#5409
Conversation
|
Merging to
|
blaine-arcjet
left a comment
There was a problem hiding this comment.
I think we should figure out what platforms support this. It may be better to just drop it.
| const forwarded = getHeader(request.headers, "forwarded"); | ||
| if (isGlobalIp(forwarded, proxies)) { | ||
| return forwarded; | ||
| const forwardedElements = forwarded ? parseForwarded(forwarded) : undefined; |
There was a problem hiding this comment.
What platforms support this? I found a Caddy issue from 5 years ago and they have indicated it is not a high priority.
|
I saw that |
|
Supposedly HAProxy supports the |
|
(see this at some point recommended nginx regex: https://redirect.github.com/golang/go/issues/30963#issuecomment-1085057745) 2 reasons not to do
|
|
These are great points (thanks for including links!). I still have to read about the header sabotage, but I'd like to know your opinion based on this information. Should we remove the |
|
I am quite okay with either but have a slight preference for being a good web citizen and supporting standards. On the other hand, it has no practical use yet (vercel also sets At some points in various conversations @davidmytton mentions that things can go in blog posts. |
💪 Is the parser currently implemented a left-to-right parser with the problems surfaced in the header sabotage blog? What is the effort level of a right-to-left parser? |
|
Currently left-to-right parsing, so the whole thing stops on a syntax error. |
|
I propose we make a new (breaking) PR to remove |
a37832d to
4648913
Compare
4648913 to
76ad948
Compare
`@arcjet/ip` reads from a `forwarded` header. That header is the standard alternative to `x-forwarded-for`, for passing several IPs from different services through to an application. However, `@arcjet/ip` does not support any valid values of that header. Values are a list of elements, each element consisting of key-value pairs. This PR implements RFC 7239 to support valid values. As this header is intended to include *several* IPs, of which the right-most IPs could be trusted IPs from proxies, this PR supports that too. While this adds a bit of code to parse things correctly, I believe it to be worth it, because finding the correct IP is tough, trusted proxies are a bottleneck, and standards are important. An alternative is to stop reading from `forwarded` altogether. I think standards are too important though.
c4003e9 to
aaebe19
Compare
|
I'm going to close this for now. We may come back to it if there is a customer request or we make a decision to do so and implement it across the sdks. |
@arcjet/ipreads from aforwardedheader. That header is the standard alternative tox-forwarded-for, for passing several IPs from different services through to an application. However,@arcjet/ipdoes not support any valid values of that header. Values are a list of elements, each element consisting of key-value pairs.This PR implements RFC 7239 to support valid values. As this header is intended to include several IPs, of which the right-most IPs could be trusted IPs from proxies, this PR supports that too.
While this adds a bit of code to parse things correctly, I believe it to be worth it, because finding the correct IP is tough, trusted proxies are a bottleneck, and standards are important.
An alternative is to stop reading from
forwardedaltogether. I think standards are too important though.