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

feat: Add support for X-Sentry-forwarded-for header #2572

Merged
merged 4 commits into from
Oct 18, 2023

Conversation

AbhiPrasad
Copy link
Member

@AbhiPrasad AbhiPrasad commented Oct 5, 2023

ref https://getsentry.atlassian.net/browse/OPS-3823
ref #2450

For users who use a SDK tunnel or proxy to route SDK events to Sentry, they often use the x-forwarded-for or x-vercel-forwarded-for to pass along the real client IP address to Sentry (so it can be stored with the Sentry event).

Current this doesn't work for SaaS Sentry because of restrictions we've placed on the infrastructure side.

This PR adds support for reading from X-Sentry-Forwarded-For header. It is slightly worse that this is a proprietary header, but it unblocks this for our customers without having to suffer the same challenges x-forwarded-for does.

With https://github.com/getsentry/ops/pull/8175 we're making changes to the infra to map the value in X-Forwarded-For to X-Sentry-Forwarded-For when the request gets forwarded from nginix to relay. This helps reduce the security concerns from blindly forwarding X-Forwarded-For, and preserves existing usage of X-Forwarded-For. In addition, self-hosted and local relay usage can still use X-Forwarded-For as usual.

@AbhiPrasad AbhiPrasad requested a review from jan-auer October 5, 2023 15:26
@AbhiPrasad AbhiPrasad marked this pull request as ready for review October 5, 2023 15:27
@AbhiPrasad AbhiPrasad requested a review from a team October 5, 2023 15:27
Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is slightly worse that this is a proprietary header

Agree with this statement, but the code change LGTM.

Copy link
Member

@jan-auer jan-auer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code change looks good. I would just like this question addressed before moving ahead.

@AbhiPrasad
Copy link
Member Author

Alright I think we're going to move forward as was outlined by Anton in the JIRA ticket, implemented here https://github.com/getsentry/ops/pull/8175.

@jan-auer sounds good to you?

@AbhiPrasad AbhiPrasad force-pushed the abhi-sentry-forwarded-header branch from 0d3b4df to c2a1d51 Compare October 11, 2023 16:40

/// We prefer the Vercel header because the normal one could get overwritten as explained here.
/// `https://vercel.com/docs/concepts/edge-network/headers#x-vercel-forwarded-for`
fn get_forwarded_for_ip(header_map: &HeaderMap) -> &str {
header_map
.get(Self::VERCEL_FORWARDED_HEADER)
.or_else(|| header_map.get(Self::SENTRY_FORWARDED_HEADER))
Copy link
Member

@Dav1dde Dav1dde Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question came up if we should value our own header over the vercel header, the conclusion was:

  1. our infrastructure requires the "standard" x-forwarded-for to be trusted, so it puts the contents of just that header into the sentry version.
  2. at the same time, x-vercel-forwarded-for is the more accurate header overall if it is there. so it should be preferred over the other two.

Can you add an explanation to comment, so somebody in the future knows why the sentry header is not the highest priority (like there is already an explanation why the vercel header is preferred over the standard X-Forwarded-For header)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with 3a97475

@AbhiPrasad AbhiPrasad merged commit 5008573 into master Oct 18, 2023
@AbhiPrasad AbhiPrasad deleted the abhi-sentry-forwarded-header branch October 18, 2023 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants