Skip to content

fix(utils): accept DSN URLs with empty password #5902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/utils/src/dsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { DsnComponents, DsnLike, DsnProtocol } from '@sentry/types';
import { SentryError } from './error';

/** Regular expression used to parse a Dsn. */
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+))?@)([\w.-]+)(?::(\d+))?\/(.+)/;
const DSN_REGEX = /^(?:(\w+):)\/\/(?:(\w+)(?::(\w+)?)?@)([\w.-]+)(?::(\d+))?\/(.+)/;

function isValidProtocol(protocol?: string): protocol is DsnProtocol {
return protocol === 'http' || protocol === 'https';
Expand Down
11 changes: 11 additions & 0 deletions packages/utils/test/dsn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ describe('Dsn', () => {
expect(dsn.projectId).toBe('321');
});

test('parses a Dsn with empty password', () => {
const dsn = makeDsn('https://abc:@sentry.io/123/321');
expect(dsn.protocol).toBe('https');
expect(dsn.publicKey).toBe('abc');
expect(dsn.pass).toBe('');
expect(dsn.host).toBe('sentry.io');
expect(dsn.port).toBe('');
expect(dsn.path).toBe('123');
expect(dsn.projectId).toBe('321');
});

test('with a long path', () => {
const dsn = makeDsn('https://[email protected]/sentry/custom/installation/321');
expect(dsn.protocol).toBe('https');
Expand Down