Serve the JavaScript SDK managed tunnel (`tunnel: true`) from ASP.NET Core
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 15/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- csharp, javascript
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- C#
- Stars
- 775
- Forks
- 262
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 118
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from getsentry/sentry-dotnet
-
chore: remove stale IL3050/IL3053 workaround from the iOS samplePossibly taken A pull request linked to this issue is open or already merged. OpenState: Needs Discussion
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-dotnet#6071 · 1 comment ·
Maintainers usually reply within 1 day
-
Heap dumps: every SDK shutdown logs "Error waiting for GarbageCollectionMonitor task to complete"Possibly taken @pcbeingused33 claimed this today. OpenState: Needs Discussion
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
getsentry/sentry-dotnet#6039 · 3 comments ·
Maintainers usually reply within 1 day
-
.NET Platform: Android Task
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
getsentry/sentry-dotnet#6020 · 3 comments ·
Maintainers usually reply within 1 day
-
Move the Blazor WebAssembly sample off the deprecated DevServerPossibly taken A pull request linked to this issue is open or already merged. Open.NET Framework: Blazor
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
getsentry/sentry-dotnet#5906 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Docs MSBuild Needs Docs Update
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
getsentry/sentry-dotnet#5691 · 1 comment ·
Maintainers usually reply within 1 day
All issues in getsentry/sentry-dotnet
Similar issues
-
In-car displays show 0 km/h and P while the AV drivesPossibly taken @bazilinskyy claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
bazilinskyy/coupled-sim#366 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
BaryoDev/umbraco-pwa#196 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
microsoft/fluentui-blazor#5688 ·
Maintainers usually reply within 1 day
-
bug flaky lsp-transport small
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day