Skip to content

Comments

fix: Trim DSN string before URI parsing#5113

Open
adinauer wants to merge 2 commits intomainfrom
fix/trim-dsn-whitespace
Open

fix: Trim DSN string before URI parsing#5113
adinauer wants to merge 2 commits intomainfrom
fix/trim-dsn-whitespace

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Feb 23, 2026

Trailing or leading whitespace in the DSN string (commonly introduced by copy-paste from dashboards, wikis, or config tools) causes a URISyntaxException that crashes the application on startup.

This trims the DSN before passing it to the URI constructor in Dsn.java.

Fixes #5087

Trailing or leading whitespace in the DSN string (commonly introduced
by copy-paste) causes a URISyntaxException that crashes the application
on startup. Trim the DSN before passing it to the URI constructor.

Fixes GH-5087
Co-Authored-By: Claude <noreply@anthropic.com>
@adinauer adinauer changed the title fix(options): Trim DSN string before URI parsing fix: Trim DSN string before URI parsing Feb 23, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Feb 23, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • Trim DSN string before URI parsing by adinauer in #5113

🤖 This preview updates automatically when you update the PR.

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

try {
Objects.requireNonNull(dsn, "The DSN is required.");
final URI uri = new URI(dsn).normalize();
final String dsnString = Objects.requireNonNull(dsn, "The DSN is required.").trim();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DSN hash calculated before trim causes cache fragmentation

Medium Severity

The DSN is trimmed in the constructor for parsing, but SentryOptions.setDsn calculates the hash from the untrimmed string. This means "dsn" and "dsn " parse identically but create different cache directories, fragmenting cached envelopes, sessions, breadcrumbs, and scope data. Users switching between whitespace variants (config changes, programmatic vs manifest) lose access to previously cached data.

Fix in Cursor Fix in Web

Objects.requireNonNull(dsn, "The DSN is required.");
final URI uri = new URI(dsn).normalize();
final String dsnString = Objects.requireNonNull(dsn, "The DSN is required.").trim();
final URI uri = new URI(dsnString).normalize();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing empty-string validation after trim causes confusing error

Low Severity

After trimming, there's no check if dsnString is empty before URI parsing. A whitespace-only DSN like " " trims to "", which creates a valid URI with null scheme, causing error message "Invalid DSN scheme: null". This is confusing because it suggests a scheme problem rather than an empty DSN. Before this change, whitespace-only DSNs threw URISyntaxException about illegal characters, which was clearer.

Fix in Cursor Fix in Web

@github-actions
Copy link
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 308.28 ms 359.77 ms 51.49 ms
Size 1.58 MiB 2.29 MiB 719.80 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
d15471f 315.61 ms 360.22 ms 44.61 ms
6edfca2 314.02 ms 383.20 ms 69.18 ms
d217708 375.27 ms 415.68 ms 40.41 ms
a5ab36f 320.47 ms 389.77 ms 69.30 ms
d217708 355.34 ms 381.39 ms 26.05 ms
319f256 317.53 ms 370.83 ms 53.29 ms
6405ec5 310.88 ms 354.56 ms 43.69 ms
ce0a49e 532.00 ms 609.96 ms 77.96 ms
dba088c 365.46 ms 366.31 ms 0.85 ms
889ecea 367.58 ms 437.52 ms 69.94 ms

App size

Revision Plain With Sentry Diff
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
6edfca2 1.58 MiB 2.13 MiB 559.07 KiB
d217708 1.58 MiB 2.10 MiB 532.97 KiB
a5ab36f 1.58 MiB 2.12 MiB 555.26 KiB
d217708 1.58 MiB 2.10 MiB 532.97 KiB
319f256 1.58 MiB 2.19 MiB 619.79 KiB
6405ec5 1.58 MiB 2.12 MiB 552.23 KiB
ce0a49e 1.58 MiB 2.10 MiB 532.94 KiB
dba088c 1.58 MiB 2.13 MiB 558.99 KiB
889ecea 1.58 MiB 2.11 MiB 539.75 KiB

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.

Dsn parsing fails with trailing whitespace - should trim input before URI parsing

1 participant