diff --git a/packages/cloudflare/test/integrations/fetch.test.ts b/packages/cloudflare/test/integrations/fetch.test.ts index 724ff39c7dde..2a8f9cf6e718 100644 --- a/packages/cloudflare/test/integrations/fetch.test.ts +++ b/packages/cloudflare/test/integrations/fetch.test.ts @@ -101,8 +101,8 @@ describe('WinterCGFetch instrumentation', () => { expect(fetchInstrumentationHandlerCallback).toBeDefined(); const startHandlerData: HandlerDataFetch = { - fetchData: { url: 'https://dsn.ingest.sentry.io/1337', method: 'POST' }, - args: ['https://dsn.ingest.sentry.io/1337'], + fetchData: { url: 'https://dsn.ingest.sentry.io/1337?sentry_key=123', method: 'POST' }, + args: ['https://dsn.ingest.sentry.io/1337?sentry_key=123'], startTimestamp: Date.now(), }; fetchInstrumentationHandlerCallback(startHandlerData); diff --git a/packages/core/src/utils/isSentryRequestUrl.ts b/packages/core/src/utils/isSentryRequestUrl.ts index e93f61a5919a..c2127cdfeb38 100644 --- a/packages/core/src/utils/isSentryRequestUrl.ts +++ b/packages/core/src/utils/isSentryRequestUrl.ts @@ -21,7 +21,12 @@ function checkTunnel(url: string, tunnel: string | undefined): boolean { } function checkDsn(url: string, dsn: DsnComponents | undefined): boolean { - return dsn ? url.includes(dsn.host) : false; + // Requests to Sentry's ingest endpoint must have a `sentry_key` in the query string + // This is equivalent to the public_key which is required in the DSN + // see https://develop.sentry.dev/sdk/overview/#parsing-the-dsn + // Therefore a request to the same host and with a `sentry_key` in the query string + // can be considered a request to the ingest endpoint + return dsn ? url.includes(dsn.host) && !!url.match(/sentry_key/) : false; } function removeTrailingSlash(str: string): string { diff --git a/packages/core/test/lib/utils/isSentryRequestUrl.test.ts b/packages/core/test/lib/utils/isSentryRequestUrl.test.ts index 195e93493e98..75e8826b2470 100644 --- a/packages/core/test/lib/utils/isSentryRequestUrl.test.ts +++ b/packages/core/test/lib/utils/isSentryRequestUrl.test.ts @@ -4,12 +4,17 @@ import type { Client } from '../../../src/client'; describe('isSentryRequestUrl', () => { it.each([ - ['', 'sentry-dsn.com', '', false], - ['http://sentry-dsn.com/my-url', 'sentry-dsn.com', '', true], - ['http://sentry-dsn.com', 'sentry-dsn.com', '', true], + ['http://sentry-dsn.com/my-url?sentry_key=123', 'sentry-dsn.com', '', true], ['http://tunnel:4200', 'sentry-dsn.com', 'http://tunnel:4200', true], ['http://tunnel:4200', 'sentry-dsn.com', 'http://tunnel:4200/', true], ['http://tunnel:4200/', 'sentry-dsn.com', 'http://tunnel:4200', true], + ['http://tunnel:4200/', 'another-dsn.com', 'http://tunnel:4200', true], + + ['http://tunnel:4200/?sentry_key=123', 'another-dsn.com', '', false], + ['http://sentry-dsn.com/my-url', 'sentry-dsn.com', '', false], + ['http://sentry-dsn.com', 'sentry-dsn.com', '', false], + ['http://tunnel:4200/', 'another-dsn.com', 'http://tunnel:4200/sentry-tunnel', false], + ['', 'sentry-dsn.com', '', false], ['http://tunnel:4200/a', 'sentry-dsn.com', 'http://tunnel:4200', false], ])('works with url=%s, dsn=%s, tunnel=%s', (url: string, dsn: string, tunnel: string, expected: boolean) => { const client = {