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

Aperta
#5,985 2 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
observability

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

.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.

Lingua principale
C#
Stelle
775
Fork
262
Merge medio
1g 16h
PR unite (30g)
118

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/sentry-dotnet

Tutte le issue di getsentry/sentry-dotnet

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.