Skip to content

fix(core): Trim DSN whitespace before native initialization#6081

Merged
antonis merged 2 commits intomainfrom
antonis/trim-dsn-whitespace
May 4, 2026
Merged

fix(core): Trim DSN whitespace before native initialization#6081
antonis merged 2 commits intomainfrom
antonis/trim-dsn-whitespace

Conversation

@antonis
Copy link
Copy Markdown
Contributor

@antonis antonis commented May 4, 2026

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

Trims leading/trailing whitespace from the DSN before passing it to the native SDK during initialization. If whitespace is detected, a warning is logged to inform the user.

💡 Motivation and Context

A user reported a crash (EXC_BAD_ACCESS in SentrySDKInternal.startWithOptions) caused by a stray space in their DSN string (#6029). The whitespace caused a null pointer dereference in the native Cocoa SDK during initialization.

See #6029 (comment)

💚 How did you test it?

  • Added test verifying whitespace is trimmed, warning is logged, and the trimmed DSN is passed to native init
  • Updated existing test DSN values from 'test' to a valid DSN format (VALID_DSN constant)
  • All 197 wrapper tests pass

📝 Checklist

  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • All tests passing
  • No breaking changes

🔮 Next steps

#skip-changelog is this is a minor change

A stray space in the DSN string can cause a null pointer dereference
in the native Cocoa/Android SDK during initialization. This trims
whitespace and warns the user before passing the DSN to native code.

Closes #6029

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

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


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 4, 2026

Fails
🚫 Pull request is not ready for merge, please add the "ready-to-merge" label to the pull request

Generated by 🚫 dangerJS against 7def674

@antonis antonis marked this pull request as ready for review May 4, 2026 09:54
Copy link
Copy Markdown

@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 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0d6b485. Configure here.

Comment thread packages/core/src/js/wrapper.ts Outdated
Comment thread packages/core/src/js/wrapper.ts Outdated
Copy link
Copy Markdown
Contributor

@alwx alwx left a comment

Choose a reason for hiding this comment

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

Should we actually fix that? I mean it seems more like a configuration issue made by customer, not an issue on our side.

@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented May 4, 2026

Should we actually fix that? I mean it seems more like a configuration issue made by customer, not an issue on our side.

Good point @alwx 👍 The main issue is that the extra whitespace passes the core validation (and works for the most part) but causes the native side to crash as with the specific report.
An alternative would be to just add a warning log to avoid this getting unnoticed. Wdyt?

@antonis
Copy link
Copy Markdown
Contributor Author

antonis commented May 4, 2026

Regarding the bot feedback about whitespace-only DSNs (e.g. " "):

After trimming, a whitespace-only DSN becomes "" which is falsy in JS — so the existing !options.dsn check right below already catches it and disables the native SDK. No extra guard needed.

Ensures a whitespace-only DSN gets trimmed to empty string and is
caught by the existing !options.dsn guard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

alwx commented May 4, 2026

Probably it's fine for now — was just thinking that the fix is a bit redundant. But doesn't hurt much, I guess.

@antonis antonis merged commit 6ba8203 into main May 4, 2026
57 of 63 checks passed
@antonis antonis deleted the antonis/trim-dsn-whitespace branch May 4, 2026 12:13
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.

2 participants