From 18a9744f9676fad945662649681c7aa8b9a203ca Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 16 Jan 2025 19:19:34 +0100 Subject: [PATCH] fix(download): scan link detection Fix #164 --- src/pages/mod/index.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pages/mod/index.tsx b/src/pages/mod/index.tsx index 0e93253..e01dca9 100644 --- a/src/pages/mod/index.tsx +++ b/src/pages/mod/index.tsx @@ -29,7 +29,9 @@ import { checkUrlForFile, copyTextToClipboard, downloadFile, - getFilenameFromUrl + getFilenameFromUrl, + isReachable, + isValidUrl } from '../../utils' import { Comments } from '../../components/comment' import { PublishDetails } from 'components/Internal/PublishDetails' @@ -615,11 +617,25 @@ const Download = ({ }: DownloadUrl) => { const [showAuthDetails, setShowAuthDetails] = useState(false) const [showNotice, setShowNotice] = useState(false) - const showScanNotice = !malwareScanLink + const [showScanNotice, setShowCanNotice] = useState(false) useDidMount(async () => { const isFile = await checkUrlForFile(url) setShowNotice(!isFile) + + // Check the malware scan url + // if it's valid URL + // if it's reachable + // if it contains sha256 + const regex = /\b[a-fA-F0-9]{64}\b/ + setShowCanNotice( + !( + malwareScanLink && + isValidUrl(malwareScanLink) && + (await isReachable(malwareScanLink)) && + regex.test(url) + ) + ) }) const handleDownload = () => {