Skip to content

Commit 7becd6c

Browse files
committed
fix(core): Only consider ingest endpoint requests when checking isSentryRequestUrl
1 parent 4abfe01 commit 7becd6c

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/core/src/utils/isSentryRequestUrl.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ function checkTunnel(url: string, tunnel: string | undefined): boolean {
2121
}
2222

2323
function checkDsn(url: string, dsn: DsnComponents | undefined): boolean {
24-
return dsn ? url.includes(dsn.host) : false;
24+
// Requests to Sentry's ingest endpoint must have a `sentry_key` in the query string
25+
// This is equivalent to the public_key which is required in the DSN
26+
// see https://develop.sentry.dev/sdk/overview/#parsing-the-dsn
27+
return dsn ? url.includes(dsn.host) && !!url.match(/sentry_key/) : false;
2528
}
2629

2730
function removeTrailingSlash(str: string): string {

packages/core/test/lib/utils/isSentryRequestUrl.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import type { Client } from '../../../src/client';
44

55
describe('isSentryRequestUrl', () => {
66
it.each([
7-
['', 'sentry-dsn.com', '', false],
8-
['http://sentry-dsn.com/my-url', 'sentry-dsn.com', '', true],
9-
['http://sentry-dsn.com', 'sentry-dsn.com', '', true],
7+
['http://sentry-dsn.com/my-url?sentry_key=123', 'sentry-dsn.com', '', true],
108
['http://tunnel:4200', 'sentry-dsn.com', 'http://tunnel:4200', true],
119
['http://tunnel:4200', 'sentry-dsn.com', 'http://tunnel:4200/', true],
1210
['http://tunnel:4200/', 'sentry-dsn.com', 'http://tunnel:4200', true],
11+
['http://tunnel:4200/', 'another-dsn.com', 'http://tunnel:4200', true],
12+
13+
['http://tunnel:4200/?sentry_key=123', 'another-dsn.com', '', false],
14+
['http://sentry-dsn.com/my-url', 'sentry-dsn.com', '', false],
15+
['http://sentry-dsn.com', 'sentry-dsn.com', '', false],
16+
['http://tunnel:4200/', 'another-dsn.com', 'http://tunnel:4200/sentry-tunnel', false],
17+
['', 'sentry-dsn.com', '', false],
1318
['http://tunnel:4200/a', 'sentry-dsn.com', 'http://tunnel:4200', false],
1419
])('works with url=%s, dsn=%s, tunnel=%s', (url: string, dsn: string, tunnel: string, expected: boolean) => {
1520
const client = {

0 commit comments

Comments
 (0)