Skip to content

Commit b00638b

Browse files
authored
fix: extract only origin (Kong#9657)
1 parent 5b6c59d commit b00638b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

packages/insomnia/src/root.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ const locationHistoryMiddleware: Route.ClientMiddlewareFunction = async ({ reque
7777
console.log('[locationHistoryMiddleware] Failed to store location history entry', err);
7878
}
7979
};
80-
80+
const sanitizeUrlAndExtractOrigin = (url: string) => {
81+
try {
82+
const parsed = new URL(url);
83+
return parsed.origin;
84+
} catch {
85+
return '';
86+
}
87+
};
8188
export const clientMiddleware: Route.ClientMiddlewareFunction[] = [locationHistoryMiddleware];
8289

8390
export const ErrorBoundary: FC<Route.ErrorBoundaryProps> = ({ error }) => {
@@ -344,18 +351,28 @@ const Root = () => {
344351

345352
return logoutSubmit();
346353
}
354+
// Supports params: uri, curl, origin
347355
if (urlWithoutParams === 'insomnia://app/import') {
348356
window.main.trackSegmentEvent({
349357
event: SegmentEvent.importStarted,
350358
properties: {
351359
source: 'import-url',
352360
},
353361
});
362+
354363
if (params.uri) {
355-
return setImportObject({ type: 'uri', defaultValue: params.uri, origin: params.origin });
364+
return setImportObject({
365+
type: 'uri',
366+
defaultValue: params.uri,
367+
origin: sanitizeUrlAndExtractOrigin(params.origin),
368+
});
356369
}
357370
if (params.curl) {
358-
return setImportObject({ type: 'curl', defaultValue: params.curl, origin: params.origin });
371+
return setImportObject({
372+
type: 'curl',
373+
defaultValue: params.curl,
374+
origin: sanitizeUrlAndExtractOrigin(params.origin),
375+
});
359376
}
360377
}
361378
if (urlWithoutParams === 'insomnia://plugins/install') {

0 commit comments

Comments
 (0)