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

sentry/remix appears to be incorrectly identifying users based on IP address headers #7323

Closed
3 tasks done
alexblack opened this issue Mar 2, 2023 · 5 comments · Fixed by #7329
Closed
3 tasks done

Comments

@alexblack
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g. bundle.tracing.min.js) in your SDK setup.

@sentry/remix

SDK Version

7.38.0

Framework Version

Remix 1.13.0

Link to Sentry event

https://syncwith.sentry.io/issues/3955446273/events/fef107a39ec64e20ad358cf5f26396d1/?project=5880196

SDK Setup

client:

  init({
    beforeSend,
    dsn: SENTRY_ADDON_DSN,
    tracesSampleRate: getApp() === 'syncwith' ? 1 : 0.05,
    sendDefaultPii: true,
    normalizeDepth: 6, // stringify deeper objects
    integrations: [
      new BrowserTracing({
        routingInstrumentation: remixRouterInstrumentation(
          useEffect,
          useLocation,
          useMatches
        ),
      }),
    ],
  });

server:

  init({
  beforeSend,
  sendDefaultPii: true,
  dsn: SENTRY_ADDON_DSN,
  tracesSampleRate: getApp() === 'syncwith' ? 1 : 0.05,
  normalizeDepth: 6, // stringify deeper objects
  integrations: [
    // enable HTTP calls tracing
    new Integrations.Http({ tracing: true }),
    new Integrations.RequestData({
      include: {
        ip: true,
      },
    }),
  ],
});

Steps to Reproduce

We're using a cloudflare worker in front of our website, and cloudflare cdn, and in this request:

https://syncwith.sentry.io/issues/3955446273/events/fef107a39ec64e20ad358cf5f26396d1/?project=5880196

It appears that the user was identified using IP address 141.101.69.35, which is a cloudflare IP. The correct IP to identify the user with is 2a01:cb19:8350:ed00:d0dd:fa5b:de31:8be5 found in header Cf-Connecting-Ip.

I wonder if the bug is that sentry should let Cf-Connecting-Ip take precendence over X-Forwarded-For, or, if its not properly parsing X-Forwarded-For and extracting the relevant IP (the first, not the last, in this case)

Screen Shot 2023-03-02 at 1 46 38 PM

Screen Shot 2023-03-02 at 1 46 34 PM

Screen Shot 2023-03-02 at 1 46 28 PM

Expected Result

The user should be identified by the IP address found in cf-connecting-ip, or maybe first in x-forwarded-for

Actual Result

The user was identified by the wrong IP

@Lms24
Copy link
Member

Lms24 commented Mar 3, 2023

Hi @alexblack, thanks for writing in! Can you confirm that this issue only concerns server-side errors? (we're handling IP addresses differently for browser and server SDKs, which is the reason I'm asking)

The reason why this is happening is that we're not looking at headers for determining the ip address. In fact, we take the IP we receive from the node request:

// client ip:
// node, nextjs: req.socket.remoteAddress
// express, koa: req.ip
if (include.ip) {
const ip = req.ip || (req.socket && req.socket.remoteAddress);
if (ip) {
event.user = {
...event.user,
ip_address: ip,
};
}
}

I'm not sure if we're going to start analyzing headers as well, given that there's probably quite a few headers out there we'd potentially need to check. I'm gonna raise this internally to see if and how we'll make changes here.

@alexblack
Copy link
Author

alexblack commented Mar 3, 2023 via email

@Lms24
Copy link
Member

Lms24 commented Mar 3, 2023

Oh, I just realized we actually extract the IP from Http headers in the Remix SDK already (#6263). Sorry for the confusion. We'll need to look into this.
Would you be able to provide a minmal reproduction for this example?

I might have an idea what's going wrong but it's hard to verify without a reproduction.

@Lms24
Copy link
Member

Lms24 commented Mar 3, 2023

I opened #7329 with a potential fix. Would you mind taking a look at this PR if the fix makes sense to you? As I said it's hard to actually verify that this actually works.

@alexblack
Copy link
Author

alexblack commented Mar 3, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants