Sentry.AspNet overwrites the username and user ID the app set

オープン
#5,986 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
csharp
領域
backend

調査の方向性

Start in src/Sentry.AspNet/Internal/SystemWebRequestEventProcessor.cs around lines 81-92, where the username and user-ID claim are assigned without checking the existing event user. Read src/Sentry/SentryClient.cs around line 360 to see that scope user data is applied before processors run, and compare with the ASP.NET Core check in src/Sentry.AspNetCore/ScopeExtensions.cs. Existing Sentry.AspNet tests set no user, so the first step is a test that sets scope.User and confirms the processor leaves it intact; the open questions about partial user fields need a maintainer decision before the fix is settled.

索引モデルが issue の本文から書いたものです。

説明

.NET Bug Framework: ASP.NET

When user info is on, SystemWebRequestEventProcessor overwrites the username and user ID that the app set on the scope. It's in the block of code that #5985 covers, and I found both while reviewing #5983.

What happens

SentryClient applies the scope before it runs the event processors, so a user the app set with SentrySdk.ConfigureScope(scope => scope.User = ...) is already on the event. The System.Web processor then sets the username and the user ID. The username comes from HttpContext.User.Identity.Name, and the user ID comes from the name identifier claim when the principal has one. Neither assignment checks whether the event already has a user.

For anonymous requests, ASP.NET attaches an identity with an empty name. The default authentication module does it unless Windows authentication already has. The processor copies that empty name, and the SDK drops blank usernames when it serializes the event. So the username the app set disappears.

For signed-in requests, the identity's name replaces the app's username. The name identifier claim, when the principal has one, replaces the app's user ID.

This only affects events. Transactions don't go through the processor, so they keep the app's user.

ASP.NET Core only fills in the user when the scope doesn't have one. System.Web can't copy that check as is. By the time the processor runs, the SDK has already filled in defaults such as the OS username, {{auto}} and the installation ID, so the event always has a user.

The Data Collection spec says the SDK must always attach data the app sets on the scope, and must not modify it.

No test sets a username or user ID before calling the processor. I traced this through the code and haven't run it end to end on IIS.

Who it affects

It affects apps that set a user on the scope and have user info on. Today that's apps with SendDefaultPii = true. Once #5983 merges, it's also apps that call ConfigureDataCollection and leave UserInfo at its default of true.

Open questions
  • When the app sets only some user fields, should System.Web fill in the rest from the request, or add nothing, as ASP.NET Core does?
  • Should this be part of #4515, which wants System.Web to share ASP.NET Core's scope logic?
主要言語
C#
スター
775
フォーク
262
平均マージ
1日 16時間
マージ済み PR(30日)
118

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

getsentry/sentry-dotnet のほかの issue

getsentry/sentry-dotnet の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。