Skip to content

Commit 4c42bd5

Browse files
authored
fix(tracing-internal): Avoid classifying protocol-relative URLs as same-origin urls (#8114)
We need to adjust our `tracePropagationTargets` default regex to account for protocol-relative URLs. These were previously classified as same-origin, relative URLs, causing tracing headers to be attached which in turn potentially caused CORS errors for users.
1 parent 5440807 commit 4c42bd5

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/tracing-internal/src/browser/request.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
stringMatchesSomePattern,
1111
} from '@sentry/utils';
1212

13-
export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\//];
13+
export const DEFAULT_TRACE_PROPAGATION_TARGETS = ['localhost', /^\/(?!\/)/];
1414

1515
/** Options for Request Instrumentation */
1616
export interface RequestInstrumentationOptions {

packages/tracing-internal/test/browser/request.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,17 @@ describe('shouldAttachHeaders', () => {
400400
'http://localhost:3000/test',
401401
'http://somewhere.com/test/localhost/123',
402402
'http://somewhere.com/test?url=localhost:3000&test=123',
403+
'//localhost:3000/test',
404+
'/',
403405
])('return `true` for urls matching defaults (%s)', url => {
404406
expect(shouldAttachHeaders(url, undefined)).toBe(true);
405407
});
406408

407-
it.each(['notmydoman/api/test', 'example.com'])('return `false` for urls not matching defaults (%s)', url => {
408-
expect(shouldAttachHeaders(url, undefined)).toBe(false);
409-
});
409+
it.each(['notmydoman/api/test', 'example.com', '//example.com'])(
410+
'return `false` for urls not matching defaults (%s)',
411+
url => {
412+
expect(shouldAttachHeaders(url, undefined)).toBe(false);
413+
},
414+
);
410415
});
411416
});

0 commit comments

Comments
 (0)