diff --git a/web/src/components/console/utils/link.tsx b/web/src/components/console/utils/link.tsx index b9e47eeaa..055d7f402 100644 --- a/web/src/components/console/utils/link.tsx +++ b/web/src/components/console/utils/link.tsx @@ -10,27 +10,33 @@ export const ExternalLink: React.FC = ({ additionalClassName = '', dataTestID, stopPropagation, -}) => ( - -); +}) => { + if (!isSafeExternalURL(href)) { + return <>{children || text}; + } + + return ( + + ); +}; // Open links in a new window and set noopener/noreferrer. export const LinkifyExternal: React.FC<{ children: React.ReactNode }> = ({ children }) => ( @@ -45,3 +51,12 @@ type ExternalLinkProps = { dataTestID?: string; stopPropagation?: boolean; }; + +const isSafeExternalURL = (value: string): value is string => { + if (!URL.canParse(value)) { + return false; + } + + const { protocol } = new URL(value); + return protocol === 'http:' || protocol === 'https:'; +};