Skip to content

fix(core): Only consider ingest endpoint requests when checking isSentryRequestUrl #17393

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion packages/core/src/utils/isSentryRequestUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ 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
return dsn ? url.includes(dsn.host) && !!url.match(/sentry_key/) : false;
Copy link

Choose a reason for hiding this comment

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

Bug: Regex Overmatches Sentry Key in URLs

The regex /sentry_key/ is too broad, matching "sentry_key" anywhere in the URL (path, fragment, parameter values) instead of specifically as a query parameter in the query string. This leads to false positives. A more precise regex, such as /[?&]sentry_key[=&]/, is needed to correctly identify Sentry ingest endpoints.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, you're right. Will fix

Copy link
Member

Choose a reason for hiding this comment

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

not sure if this is better, but we could also use parseStringToUrlObject here and compare the parts directly?

}

function removeTrailingSlash(str: string): string {
Expand Down
11 changes: 8 additions & 3 deletions packages/core/test/lib/utils/isSentryRequestUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Loading