Skip to content

feat(node): Check for invalid url in node transport #6623

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 3 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions packages/nextjs/src/index.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ export function init(options: NextjsOptions): void {
const activeDomain = domain.active;
domain.active = null;

if (typeof options.tunnel !== 'undefined') {
try {
new URL(options.tunnel);
} catch (error) {
__DEBUG_BUILD__ &&
logger.error('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
throw new Error('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
}
}
nodeInit(options);

const filterTransactions: EventProcessor = event => {
Expand Down
18 changes: 18 additions & 0 deletions packages/nextjs/test/index.server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ describe('Server init()', () => {
});
});

it('should not fail on valid tunnel option', () => {
expect(() =>
init({
dsn: 'https://[email protected]/12312012',
tunnel: 'https://example.com/api',
}),
).not.toThrowError();
});

it('should fail on invalid tunnel option', () => {
expect(() =>
init({
dsn: 'https://[email protected]/12312012',
tunnel: '/invalid',
}),
).toThrowError('The tunnel option is not a valid URL. It must be a full URL including the protocol.');
});

describe('integrations', () => {
// Options passed by `@sentry/nextjs`'s `init` to `@sentry/node`'s `init` after modifying them
type ModifiedInitOptions = { integrations: Integration[] };
Expand Down