Fix for header IP with source port #8762

Closed
opened 2025-12-29 20:40:54 +01:00 by adam · 1 comment
Owner

Originally created by @AnythingOverIP on GitHub (Oct 19, 2023).

Originally assigned to: @abhi1693 on GitHub.

NetBox version

v3.6.4

Feature type

Change to existing functionality

Proposed functionality

Based on a Slack Discussion, I'm submitting what could be a half bug / half feature request/issue...

When NetBox is behind an IIS reverse proxy, it appears that the header information is different. We can use it without any issue, except if a user enter a wrong credential set, which results in an error message:
image

The user IP returned has source port, which breaks the get_client_ip function defined in netbox/utilities/request.py

I worked around the issue by adding a single line of code:
client_ip = client_ip.split(':')[0] just before try

Use case

To prevent error message, which lead the user to think that server is down instead of him entering a wrong password.

Database changes

none

External dependencies

none

Originally created by @AnythingOverIP on GitHub (Oct 19, 2023). Originally assigned to: @abhi1693 on GitHub. ### NetBox version v3.6.4 ### Feature type Change to existing functionality ### Proposed functionality Based on a [Slack Discussion](https://netdev-community.slack.com/archives/C01P0FRSXRV/p1697600102751449), I'm submitting what could be a half bug / half feature request/issue... When NetBox is behind an IIS reverse proxy, it appears that the header information is different. We can use it without any issue, except if a user enter a wrong credential set, which results in an error message: ![image](https://github.com/netbox-community/netbox/assets/25624251/647f9986-4214-4ea2-a572-4c5419eaa587) The user IP returned has source port, which breaks the `get_client_ip` function defined in [netbox/utilities/request.py ](https://github.com/netbox-community/netbox/blob/5b2f29480a42e9c815ca1f50403c115cc89b6538/netbox/utilities/request.py) I worked around the issue by adding a single line of code: `client_ip = client_ip.split(':')[0]` just before `try` ### Use case To prevent error message, which lead the user to think that server is down instead of him entering a wrong password. ### Database changes none ### External dependencies none
adam added the status: acceptedtype: feature labels 2025-12-29 20:40:54 +01:00
adam closed this issue 2025-12-29 20:40:54 +01:00
Author
Owner

@candlerb commented on GitHub (Dec 1, 2023):

Unfortunately this breaks when given an IPv6 address, including an IPv4 mapped one like ::ffff:192.168.6.2 - see discussion #14307.

Proposal:

  • if the IP address contains only a single colon, then it can't possibly be an IPv6 address, so you can do the IIS workaround (urgh).
  • if the address looks like [addr] or [addr]:nnn then strip the port and the brackets. This is on the assumption that if IIS were ever to add a port to an IPv6 address, it would have to wrap it this way
  • otherwise, leave it alone
@candlerb commented on GitHub (Dec 1, 2023): Unfortunately this breaks when given an IPv6 address, including an IPv4 mapped one like `::ffff:192.168.6.2` - see discussion #14307. Proposal: * if the IP address contains only a single colon, then it can't possibly be an IPv6 address, so you can do the IIS workaround (urgh). * if the address looks like `[addr]` or `[addr]:nnn` then strip the port and the brackets. This is on the assumption that if IIS were ever to add a port to an IPv6 address, it would have to wrap it this way * otherwise, leave it alone
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8762