Skip to content

fix(security): Reject DSN hosts that requests would send elsewhere - #164

Merged
armenzg merged 1 commit into
mainfrom
fix/dsn-host-backslash-bypass
Nov 9, 2026
Merged

armenzg merged 1 commit into
mainfrom
fix/dsn-host-backslash-bypass

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Category: application security (SSRF / unsafe outbound requests).

#153 made GithubClient only post envelopes to sentry.io hosts over HTTPS. That check can be bypassed with a backslash in the DSN host, so an org can still point the app's envelope requests at any HTTPS host.

The vulnerability

The check reads the host with urlsplit (through sentry_sdk.utils.Dsn), which keeps a \ in the host. requests (urllib3) treats \ as the start of the path. With a DSN like https://key@evil.example\.sentry.io/1:

  • Dsn(...).host is evil.example\.sentry.io, which ends in .sentry.io, so the check passes.
  • sentry_project_url is https://evil.example\.sentry.io/api/1/envelope/. requests prepares it as https://evil.example/%5C.sentry.io/api/1/envelope/ and connects to evil.example.

I reproduced this on main with the locked requests 2.34.2 and urllib3 2.8.0. The DSN comes from sentry_config.ini in the org's .sentry repo, and any org that installs the GitHub App controls that file.

Severity

Medium. This is a bypass of an existing control, and it gives a blind SSRF: any org that installs the app can make the Cloud Run service POST gzipped envelopes to a host or IP of its choice on port 443. That includes internal addresses the service can reach and third-party hosts, with the app's egress IP as the source. The request carries the org's own CI data and its own DSN public key. GitHub tokens never go to this URL, so no tokens or other orgs' data leak.

Production evidence

  • Orgs do configure non-Sentry DSN hosts. Event f950db04e5d44c739338508b09c01e09 (revision github-actions-app-00044-kpl, Nov 5) is a ConnectTimeout from _send_envelope posting to a non-Sentry host. That was before fix(security): Only send envelopes to Sentry DSN hosts over HTTPS #153.
  • The current revision (github-actions-app-00047-rz8) runs the fix(security): Only send envelopes to Sentry DSN hosts over HTTPS #153 check. In event 52a56be16cf84efc910ae4afcba26b41, the send_trace/_send_envelope line numbers match main. This bypass gets around that check.
  • I found no issue in the last 90 days with a backslash host. A request that succeeds would not raise, though, so its absence doesn't rule out use. Project data scrubbing is on with defaults, which doesn't apply here: this is an outbound-request problem, not a leak into Sentry.

Fix

The host now has to fully match (?:[a-z0-9-]+\.)*sentry\.io: sentry.io or a subdomain whose labels only hold letters, digits, and hyphens. urlsplit lowercases the host, so there's no case to handle. Valid DSNs (o1.ingest.us.sentry.io, sentry.io:8443) are still accepted. Rejected DSNs raise BadDsn, which the handler already reports as an invalid org config (200, invalid_dsn metric).

Verification

  • I added two cases to test_initialize_with_invalid_dsn, with and without a port. They fail on main ("DID NOT RAISE BadDsn") and pass with this change.
  • uv run pytest (95 passed), uv run mypy, and uv run pre-commit run --all-files all pass.

Draft #89 also touches DSN validation, but it's based on the code from before #153 and doesn't handle this case.

via automation sched_2663accc24a4cb8adfb43de4543ec71e · Run ID sched_2663accc24a4cb8adfb43de4543ec71e:1794227400000.

--

View Session [Sentry]

Co-Authored-By: Armen Zambrano Gasparnian <44410+armenzg@users.noreply.github.com>
@sentry-junior
sentry-junior Bot force-pushed the fix/dsn-host-backslash-bypass branch from 34f220e to 1c86995 Compare November 9, 2026 14:52
@armenzg
armenzg merged commit 8ea0fad into main Nov 9, 2026
18 checks passed
@armenzg
armenzg deleted the fix/dsn-host-backslash-bypass branch November 9, 2026 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant