Skip to content

Commit 9715627

Browse files
committed
chore: fix incomplete URL substring sanitization
1 parent e1b2a79 commit 9715627

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/ui/views/RepoDetails/RepoDetails.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ import { usePushesQuery } from '../../query/usePushesQuery';
4747
import { useMutation, useQueryClient } from '@tanstack/react-query';
4848
import { repoQueryKeys } from '../../query/repoQueryKeys';
4949

50+
const isGitHubUrl = (url: string | undefined): boolean => {
51+
try {
52+
const { hostname } = new URL(url ?? '');
53+
return hostname === 'github.com' || hostname.endsWith('.github.com');
54+
} catch {
55+
return false;
56+
}
57+
};
58+
5059
const RepoDetails = () => {
5160
const navigate = useNavigate();
5261
const [searchParams, setSearchParams] = useSearchParams();
@@ -140,8 +149,8 @@ const RepoDetails = () => {
140149
const parsedUrl = new URL(remoteUrl);
141150
const cloneURL = `${proxyURL}/${parsedUrl.host}${parsedUrl.port ? `:${parsedUrl.port}` : ''}${parsedUrl.pathname}`;
142151
const orgHref = remoteRepoData?.profileUrl;
143-
const repoHref = remoteRepoData?.htmlUrl?.includes('github.com')
144-
? remoteRepoData.htmlUrl
152+
const repoHref = isGitHubUrl(remoteRepoData?.htmlUrl)
153+
? remoteRepoData?.htmlUrl
145154
: trimTrailingDotGit(repo.url);
146155

147156
return (

0 commit comments

Comments
 (0)