Skip to content

Commit da72f51

Browse files
committed
fix: check if href startsWith basepath to avoid malformed urls
1 parent cca0774 commit da72f51

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/nextjs/src/client/routing/appRouterRoutingInstrumentation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const globalWithInjectedBasePath = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
9292
export function appRouterInstrumentNavigation(client: Client): void {
9393
routerTransitionHandler = (href, navigationType) => {
9494
const basePath = process.env._sentryBasePath ?? globalWithInjectedBasePath._sentryBasePath;
95-
const normalizedHref = basePath ? `${basePath}${href}` : href;
95+
const normalizedHref = basePath && !href.startsWith(basePath) ? `${basePath}${href}` : href;
9696
const unparameterizedPathname = new URL(normalizedHref, WINDOW.location.href).pathname;
9797
const parameterizedPathname = maybeParameterizeRoute(unparameterizedPathname);
9898
const pathname = parameterizedPathname ?? unparameterizedPathname;
@@ -214,7 +214,8 @@ function patchRouter(client: Client, router: NextRouter, currentNavigationSpanRe
214214

215215
const href = argArray[0];
216216
const basePath = process.env._sentryBasePath ?? globalWithInjectedBasePath._sentryBasePath;
217-
const normalizedHref = basePath ? `${basePath}${href}` : href;
217+
const normalizedHref =
218+
basePath && typeof href === 'string' && !href.startsWith(basePath) ? `${basePath}${href}` : href;
218219
if (routerFunctionName === 'push') {
219220
transactionName = transactionNameifyRouterArgument(normalizedHref);
220221
transactionAttributes['navigation.type'] = 'router.push';

0 commit comments

Comments
 (0)