Skip to content

Commit

Permalink
rename var
Browse files Browse the repository at this point in the history
rename var
  • Loading branch information
nguyenhoaidanh committed Oct 16, 2023
1 parent 86346f8 commit c9532be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/theme/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export function ExternalLink({
<StyledLink
target={target}
rel={rel}
href={validateRedirectURL(href, { whitelistKyberSwap: false, allowRelativePath: true })}
href={validateRedirectURL(href, { _dangerousCheckWhitelist: false, allowRelativePath: true })}
onClick={handleClick}
{...rest}
/>
Expand All @@ -227,7 +227,7 @@ export function ExternalLinkIcon({
console.debug('Fired outbound link event', href)
} else {
event.preventDefault()
navigateToUrl(href, { whitelistKyberSwap: false, allowRelativePath: true })
navigateToUrl(href, { _dangerousCheckWhitelist: false, allowRelativePath: true })
}
},
[href, target],
Expand All @@ -236,7 +236,7 @@ export function ExternalLinkIcon({
<LinkIconWrapper
target={target}
rel={rel}
href={validateRedirectURL(href, { whitelistKyberSwap: false, allowRelativePath: true })}
href={validateRedirectURL(href, { _dangerousCheckWhitelist: false, allowRelativePath: true })}
onClick={handleClick}
{...rest}
>
Expand Down
8 changes: 4 additions & 4 deletions src/utils/redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import { useChangeNetwork } from 'hooks/web3/useChangeNetwork'

const whiteListDomains = [/https:\/\/(.+?\.)?kyberswap\.com$/, /https:\/\/(.+)\.kyberengineering\.io$/]

type Options = { whitelistKyberSwap?: boolean; allowRelativePath?: boolean }
type Options = { _dangerousCheckWhitelist?: boolean; allowRelativePath?: boolean }
export const validateRedirectURL = (
url: string | undefined,
{ whitelistKyberSwap = true, allowRelativePath = false }: Options = {},
{ _dangerousCheckWhitelist = true, allowRelativePath = false }: Options = {},
) => {
try {
if (!url || url.endsWith('.js')) throw new Error()
const newUrl = allowRelativePath && url.startsWith('/') ? new URL(`${window.location.origin}${url}`) : new URL(url)
if (
newUrl.pathname.endsWith('.js') ||
!['https:', 'http:'].includes(newUrl.protocol) ||
(whitelistKyberSwap && !whiteListDomains.some(regex => newUrl.origin.match(regex)))
(_dangerousCheckWhitelist && !whiteListDomains.some(regex => newUrl.origin.match(regex)))
) {
throw new Error()
}
Expand Down Expand Up @@ -50,7 +50,7 @@ export const useNavigateToUrl = () => {
return
}
const { pathname, host, search } = new URL(actionURL)
if (!validateRedirectURL(actionURL, { whitelistKyberSwap: false })) return
if (!validateRedirectURL(actionURL, { _dangerousCheckWhitelist: false })) return
if (window.location.host === host) {
navigate(`${pathname}${search}`)
} else {
Expand Down

0 comments on commit c9532be

Please sign in to comment.