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

X-Forwarded-For not working in SaaS #2450

Closed
jjbayer opened this issue Aug 31, 2023 · 14 comments
Closed

X-Forwarded-For not working in SaaS #2450

jjbayer opened this issue Aug 31, 2023 · 14 comments
Assignees
Labels
maintenance Tasks with this label generally have a lower priority and due date question Further information is requested

Comments

@jjbayer
Copy link
Member

jjbayer commented Aug 31, 2023

Steps to reproduce:

Sending the following in my local dev environment:

curl -v http://localhost:8000/api/2/envelope/ \
     -H X-forwarded-for:4.4.4.4 \
    --data-binary '{"dsn":"$SENTRY_DSN"}\n{"type": "event"}\n{"user": {"ip_address": "{{auto}}"}}'

Results in
image

However, the same does not work for SaaS (ignores the X-Forwarded-For header):

curl -v https://o123.ingest.sentry.io/api/2/envelope/ \
     -H X-forwarded-for:4.4.4.4 \
    --data-binary '{"dsn":"$SENTRY_DSN"}\n{"type": "event"}\n{"user": {"ip_address": "{{auto}}"}}'

image

@jjbayer
Copy link
Member Author

jjbayer commented Aug 31, 2023

This was an attempt to emulate a tunnel setup, as discussed here: getsentry/sentry-javascript#5798 (reply in thread)

@jan-auer
Copy link
Member

jan-auer commented Sep 4, 2023

@beezz could we get some help on this one, please? I vaguely remember that we do not pass this header through for a reason, but I cannot find documentation on that.

Note: We need to apply the same policy to x-vercel-forwarded-for

@jan-auer jan-auer added question Further information is requested maintenance Tasks with this label generally have a lower priority and due date labels Sep 4, 2023
@AbhiPrasad
Copy link
Member

Synced offline - created an OPs ticket here for the SRE folks to investigate further. https://getsentry.atlassian.net/browse/OPS-3823

@iker-barriocanal
Copy link
Contributor

We'll track this in the OPS ticket above.

@AaronFriel
Copy link

@iker-barriocanal sorry, can you keep this open until your internal tracker resolves the issue?

I am unable to subscribe to notifications on your internal tracker, and it appears this is closed as resolved.

@IanVS
Copy link

IanVS commented Sep 26, 2023

Does that mean this hasn't been fixed yet? I was just about to test it out.

@AbhiPrasad
Copy link
Member

Let's re-open - I'll take care of updating with the OPs tickets.

@AbhiPrasad
Copy link
Member

Hey, thanks for your patience everyone. We've made the changes in our SaaS infrastructure to now support X-Forwarded-For header. It should correctly forward the ip_address now.

We've also added support for using a proprietary header X-Sentry-Forwarded-For in cases where you do not want to set X-Forwarded-For. I will update our docs to reflect this.

@szwabodev
Copy link

Hello, sorry for bringing back an old issue, but I am having trouble with getting real user IP to save in my tunneled Sentry errors/messages while using Cloudflare as a proxy for my NextJS application. The problem is that Cloudflare replaces the "X-Forwarded-For" header with its own server IP and the real user IP is under "CF-Connecting-IP" header. I have tried using a middleware for my Sentry tunnel endpoint to replace the request's and response's "X-Forwarded-For" and "X-Vercel-Forwarder-For" as well as "X-Sentry-Forwarded-For" with the value of real user IP, however Sentry still keeps storing the cloudflare IP instead. Would it be possible to add this "CF-Connecting-IP" as a priority header so that Sentry can automatically grab its value instead of the others if it exists? I will keep trying to replace it somehow in the middleware in the meantime, but it would be much easier if Sentry did it automatically.

@AbhiPrasad
Copy link
Member

@szwabodev please open a new GH issue - we can take a look!

@Niaro
Copy link

Niaro commented May 20, 2024

@szwabodev have u opened a GH issue? could u please share the link? Im also experiencing proxy IP instead of client IP in sentry

@szwabodev
Copy link

szwabodev commented May 20, 2024

@szwabodev have u opened a GH issue? could u please share the link? Im also experiencing proxy IP instead of client IP in sentry

Hey, yes it was reported here: #3493

Looks like it should be handled already, but I just checked 2 of my latest errors from 7.113.0 SDK version and it still has cloudflare IP in user context instead of real one. I will comment on the linked issue about it.

@reyoucat
Copy link

reyoucat commented Dec 11, 2024

This still looks the same.
I guess I should just put it in as a custom tag. or useX-Sentry-Forwarded-For

@AbhiPrasad
Copy link
Member

@reyoucat A lot has changed since we made this fix, there could be a different root cause here. Could you open a new GitHub issue in the Sentry repo that describes your setup and why the forwarded for header is not working? https://github.com/getsentry/sentry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Tasks with this label generally have a lower priority and due date question Further information is requested
Projects
None yet
Development

No branches or pull requests

9 participants