Sentry.AspNet reports the server's IP as the user's IP

Abierto
#5,985 2 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
csharp

Línea de trabajo

Start with Enricher.cs to see where {{auto}} is set, then SystemWebRequestEventProcessor.cs where IpAddress ??= context.Request.UserHostAddress never fires. SentryAspNetOptionsExtensions.cs shows the processor registration order. The test Process_PresetUserIP_NotOverwritten in SystemWebRequestEventProcessorTests.cs calls the processor directly, so it misses the enricher. Done means a System.Web event with user info on and no app-set IP carries a real client or chosen IP, with a test that runs both processors. The open question of which IP to use is still undecided.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

.NET Bug Framework: ASP.NET

When user info is on, events and transactions from classic ASP.NET apps never get the client's IP. They get {{auto}}, and Relay turns that into the address the server reaches Sentry from. This affects 5.15.1 and later. I found it while reviewing #5983.

What happens
  1. The enricher in MainSentryEventProcessor sets User.IpAddress to {{auto}} when user info is on.
  2. SystemWebRequestEventProcessor runs after it, because AddAspNet registers it with AddEventProcessor. Its IpAddress ??= context.Request.UserHostAddress never assigns anything, because the IP is already {{auto}}.
  3. Relay resolves {{auto}} to request.env.REMOTE_ADDR when the event has one, and otherwise to the address the envelope came from. System.Web events have no REMOTE_ADDR, so they get the server's address, or the address of a NAT gateway or proxy in front of it. Relay then looks up the location of that IP, so the user shows up wherever the server runs.

Transactions go through the same enricher, and System.Web has no transaction processor, so they carry {{auto}} too.

ASP.NET Core doesn't have this problem. It puts the client IP on the scope's user before the SDK captures anything, and it also sets request.env.REMOTE_ADDR.

I confirmed the processor order with a probe on .NET 10. A processor added with AddEventProcessor that does the same ??= always sees {{auto}} when user info is on. I haven't run it end to end on IIS.

Who it affects

User info is on when the app calls ConfigureDataCollection and leaves UserInfo at its default of true. It's also on when the app doesn't call ConfigureDataCollection and sets SendDefaultPii = true.

User info The app sets User.IpAddress user.ip_address in Sentry
On No The server's IP
On Yes The app's value
Off No None
How it got here

The enricher has set {{auto}} for apps with SendDefaultPii on since before 4.0.0. System.Web used to overwrite it with UserHostAddress, which also replaced IPs that apps set themselves, as #3337 reported. #4513 fixed that in 5.15.1 by switching to ??=, and since then {{auto}} wins.

Why the tests don't catch it

The SystemWebRequestEventProcessor tests call Process directly, so the enricher never runs. Process_PresetUserIP_NotOverwritten sets an IP before calling the processor, and the processor can't tell that apart from {{auto}}.

Open questions
  • Which IP should a System.Web event carry when user info is on and the app didn't set one? UserHostAddress is the address of the TCP connection, so behind a load balancer or a CDN it's the proxy's IP. #3337 asked for proxy handling too.
  • Should this wait for #4515, which wants System.Web to share ASP.NET Core's scope logic?

The same processor also replaces a username the app set on the scope, and the user ID when the principal has a name identifier claim. That's a separate bug, so it should get its own issue.

Lenguaje dominante
C#
Estrellas
775
Forks
262
Merge medio
1 d 16 h
PR fusionados (30 d)
118

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de getsentry/sentry-dotnet

Todos los issues de getsentry/sentry-dotnet

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.