Serve the JavaScript SDK managed tunnel (`tunnel: true`) from ASP.NET Core
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 15/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- csharp, javascript
Direzione di ricerca
Start with SentryTunnelMiddleware and its tests, then read SentryStartupFilter and SentryAspNetCoreOptions/BindableSentryAspNetCoreOptions to see where an opt-in tunnel option and pre-routing IStartupFilter fit. Port the JS hash.ts FNV-1a and dsn.ts normalization from the linked files, checking the three DSN/path vectors, and model forwarding on tunnelForward.ts. Done means hashed paths are answered before routing, envelopes forwarded with the listed headers and Sentry status/rate-limit headers, and tests cover the vectors, DSN allow-list and streaming limit.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem Statement
Ad blockers drop browser requests to Sentry ingest, and block lists also pick up well-known tunnel paths. Our UseSentryTunneling() defaults to /tunnel, a static path that a filter list can target.
sentry-javascript 11.10.0 added a managed tunnel (getsentry/sentry-javascript#25199). The browser sets tunnel: true and posts to a same-origin path derived from its DSN. On the server, serveTunnelIntegration() answers that path and forwards the envelope to Sentry. Since 11.12.0 the server answers before the request reaches the app (getsentry/sentry-javascript#25997). Because the path is a hash of the DSN, browser and server agree on it without sharing build state, and it stays the same across deploys.
ASP.NET Core apps often serve a JavaScript frontend (an SPA, or Razor/MVC pages using the browser SDK), so the .NET server should be able to answer these paths.
How the path is computed
"/" + base36(FNV-1a-32(normalizedDsn)), where normalizedDsn is protocol://publicKey@host[:port]/[path/]projectId with the secret key dropped. The hash runs over UTF-16 code units (charCodeAt), so a C# loop over the string's chars matches.
hash.ts: the hash. The JS SDK treats it as fixed, since browser and server of different versions must agree.tunnel.ts:getTunnelPath,resolveTunnelPaths,resolveAllowedDsns.dsn.ts:dsnFromStringanddsnToString, which define the normalization.
Test vectors, all reproduced by a C# port:
| DSN | Path |
|---|---|
https://[email protected]/1337 |
/fdv680 |
https://public:[email protected]/1337 |
/fdv680 |
https://[email protected]/1337 |
/16bejtj |
Parse the DSN with the same regex as dsnFromString, not with Dsn.Parse or System.Uri. Uri lowercases the host and drops a default port, and either change gives a different path: https://[email protected]:443/1337 is /1fbdot5 in JS.
Solution Brainstorm
An opt-in, additive option on SentryAspNetCoreOptions. The shape below is only a sketch:
builder.WebHost.UseSentry(o =>
{
o.Dsn = "<server DSN>";
o.Tunnel.Enabled = true;
o.Tunnel.AllowedDsns.Add("<browser DSN>");
});
- Paths. One per allowed DSN (the server's own DSN plus
AllowedDsns), POST only. Most .NET backends report to a different Sentry project than their frontend, soAllowedDsnsis the usual case here rather than the exception. Optionally a fixedPathand aBasePath, like the JSServerTunnelOptions. ASP.NET Core already strips an IIS sub-app'sPathBase, soBasePathonly matters for aUsePathBaseinside the app's own pipeline. - Answer before the app. Register an
IStartupFilternext toSentryStartupFilter, so the tunnel runs before routing, authentication, CORS and antiforgery. This is the ASP.NET Core equivalent of the JS runtime-level interception. - Forwarder, following
tunnelForward.ts:- Read only the envelope header line, up to 64 KB. Answer 400 if it is missing or not JSON.
- Normalize the header's
dsnand require an exact match with an allowed DSN. Answer 403 otherwise. - Stream the rest of the body to that DSN's envelope endpoint, keeping its scheme, port and path prefix, with a 30-second timeout.
- Pass on
user-agent,sec-ch-ua*,origin,refererand the client IP headers (cf-connecting-ip,x-vercel-forwarded-for,x-forwarded-for), and setX-Sentry-Forwarded-For. Without Origin or Referer, Relay skips the project's allowed-domains check. - Return Sentry's status with
content-type,retry-afterandx-sentry-rate-limits, so the browser SDK still backs off. - Use a plain
HttpClient.SentryHttpMessageHandlerBuilderFilteraddsSentryHttpMessageHandlerto everyIHttpClientFactoryclient, which would add a breadcrumb, a span and trace headers to every forward.
- Tracing. Tunnel requests shouldn't produce transactions. Running before
SentryMiddlewarecovers the SDK's own tracing. The hosting layer starts the requestActivitybefore any middleware, though, so Sentry.OpenTelemetry needs to drop those server spans. JS usesignoreSpansfor this. - Configuration and AOT. Matching entries in
BindableSentryAspNetCoreOptions, so the tunnel can be configured fromappsettings.json. - Docs. The ASP.NET Core guide, including the browser side (
tunnel: true, sentry-javascript 11.10 or later).
The existing middleware
SentryTunnelMiddleware can keep its API and move onto the new forwarder, which fixes these without a breaking change:
- The ingest URL is hardcoded to
https://{host}/api/{id}/envelope/, so a self-hosted Sentry on http, on a non-default port or under a path prefix doesn't work. - It replaces the browser's User-Agent and doesn't pass on Origin or Referer.
- It doesn't return the rate-limit headers.
- A DSN that isn't allowed gets an empty 200.
- It reads the whole body into memory with no size limit.
Its allow rule accepts any *.sentry.io host plus the listed hosts, so anyone can use the server as a relay into any Sentry SaaS project. Requiring an exact DSN match is a breaking change, so it belongs in the next major. There, UseSentryTunneling(path) could become a fixed Path on the managed tunnel, which also gives the one-step setup asked for in #4377.
Migration path for users
- Deploy the server with the managed tunnel on and the browser DSN in
AllowedDsns, keepingUseSentryTunneling(). The two answer different paths. - Switch the browser to
tunnel: true. Doing the server first means the browser never posts to a path nothing answers, and tabs still running an old bundle keep posting to/tunnel. - Remove
AddSentryTunnelingandUseSentryTunnelingonce old bundles are gone.
When rotating a DSN, keep both DSNs in AllowedDsns until builds using the old one are gone.
- Lingua principale
- C#
- Stelle
- 775
- Fork
- 262
- Merge medio
- 1g 16h
- PR unite (30g)
- 118
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di getsentry/sentry-dotnet
-
chore: remove stale IL3050/IL3053 workaround from the iOS sampleForse già presa Una pull request collegata a questa issue è aperta o già unita. ApertaState: Needs Discussion
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
getsentry/sentry-dotnet#6071 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Heap dumps: every SDK shutdown logs "Error waiting for GarbageCollectionMonitor task to complete"Forse già presa @pcbeingused33 l’ha presa oggi. ApertaState: Needs Discussion
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
getsentry/sentry-dotnet#6039 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
.NET Platform: Android Task
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
getsentry/sentry-dotnet#6020 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Move the Blazor WebAssembly sample off the deprecated DevServerForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta.NET Framework: Blazor
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
getsentry/sentry-dotnet#5906 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Docs MSBuild Needs Docs Update
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
getsentry/sentry-dotnet#5691 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di getsentry/sentry-dotnet
Issue simili
-
In-car displays show 0 km/h and P while the AV drivesForse già presa @bazilinskyy l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
bazilinskyy/coupled-sim#366 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
BaryoDev/umbraco-pwa#196 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
microsoft/fluentui-blazor#5688 ·
I maintainer di solito rispondono entro 1 giorno
-
bug flaky lsp-transport small
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno