Skip to content

Using absolute rightmost doesn't work for many network configurations #2

@adam-p

Description

@adam-p

The code right now chooses the rightmost X-Forwarded-For or Forwarded value. This only works if there is only one reverse proxy.

Instead, AllowedNets could be used to check from the rightmost for the first (from the right) IP that is not in the AllowedNets ranges. This would allow for any number of trusted reverse proxies between the internet and the server using this library.

If you do change to searching from the right, make sure to include all matching headers rather than just the last one. Otherwise you might search through the whole last header without finding what you want, and miss other headers.

More details here: https://adam-p.ca/blog/2022/03/x-forwarded-for/#algorithms

(I applaud you for using a rightmost approach rather than leftmost. This library is better than the vast majority of similar libraries that I looked at.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions