Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP_X_FORWARDED_FOR does not exist when using custom script #7887

Closed
davama opened this issue Nov 19, 2021 · 4 comments · Fixed by #8153
Closed

HTTP_X_FORWARDED_FOR does not exist when using custom script #7887

davama opened this issue Nov 19, 2021 · 4 comments · Fixed by #8153
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@davama
Copy link
Contributor

davama commented Nov 19, 2021

NetBox version

v3.0.10

Python version

3.8

Steps to Reproduce

Background: #7876

python snippet:

        remote_ip_address = self.request.META.get('HTTP_X_FORWARDED_FOR') or self.request.META.get('REMOTE_ADDR')
        self.log_info(f"Running as user {remote_username} (IP: {remote_ip_address})...")
        self.log_info(repr(self.request.META))

my nginx snippet:

    location / {
        proxy_pass http://127.0.0.1:8001;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
	proxy_set_header X-Forwarded-For $remote_addr;
    }

Expected Behavior

{'CONTENT_LENGTH': '503', 'CONTENT_TYPE': 'multipart/form-data; boundary=----WebKitFormBoundaryw66ayIoNmlX9BFq7', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, br', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.9', 'HTTP_HOST': '127.0.0.1:8001', 'HTTP_REFERER': 'https://netbox-lab.nwk.jwm2.net/extras/scripts/netbox.AddDevice/', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'POST', 'SERVER_NAME': '127.0.0.1', 'SERVER_PORT': '8001', 'HTTP_X_FORWARDED_FOR': 'x.x.x.48'}

HTTP_X_FORWARDED_FOR should be present as nginx set it.

Observed Behavior

The above would give me the below output:

{'CONTENT_LENGTH': '503', 'CONTENT_TYPE': 'multipart/form-data; boundary=----WebKitFormBoundaryPrHAvPRqa4n0y5Bn', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, br', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.9', 'HTTP_HOST': '127.0.0.1:8001', 'HTTP_REFERER': 'https://netbox.domain.com/extras/scripts/netbox.AddDevice/', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'QUERY_STRING': '', 'REMOTE_ADDR': '127.0.0.1', 'REQUEST_METHOD': 'POST', 'SERVER_NAME': '127.0.0.1', 'SERVER_PORT': '8001'}
@davama davama added the type: bug A confirmed report of unexpected behavior in the application label Nov 19, 2021
@davama
Copy link
Contributor Author

davama commented Nov 19, 2021

I have a PR ready to go.
But it mentions i need to create a bug first.
so here it is.

let me know how to proceed.
First PR with netbox 😄

Thank you!

@jeremystretch jeremystretch added the status: accepted This issue has been accepted for implementation label Dec 8, 2021
@jeremystretch
Copy link
Member

@davama I've assigned this to you for a PR. Thanks!

@jeremystretch
Copy link
Member

@davama are you still able to work on this?

@davama
Copy link
Contributor Author

davama commented Dec 22, 2021

Thank you for the reminder.
I’ll submit shortly

jeremystretch added a commit that referenced this issue Dec 22, 2021
larsks pushed a commit to larsks/netbox that referenced this issue Mar 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants