From 9bb48cda5bb74a1552d615ba57e0a4f29b96224b Mon Sep 17 00:00:00 2001 From: Hamza Mahjoubi Date: Fri, 30 Aug 2024 13:42:48 +0200 Subject: [PATCH] fix: link checking missing scheme Signed-off-by: Hamza Mahjoubi --- lib/Service/PhishingDetection/LinkCheck.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Service/PhishingDetection/LinkCheck.php b/lib/Service/PhishingDetection/LinkCheck.php index cc510f14a5..888188c4a7 100644 --- a/lib/Service/PhishingDetection/LinkCheck.php +++ b/lib/Service/PhishingDetection/LinkCheck.php @@ -40,6 +40,13 @@ private function getInnerText(\DOMElement $node) : string { return $innerText; } + private function parse(string $url): string { + if(!str_contains($url, '://')) { + return 'http://'.$url; + } + return $url; + } + public function run(string $htmlMessage) : PhishingDetectionResult { $results = []; @@ -62,7 +69,7 @@ public function run(string $htmlMessage) : PhishingDetectionResult { $un = new Normalizer($zipped['href']); $url = $un->normalize(); if($this->textLooksLikeALink($zipped['linkText'])) { - if(parse_url($url, PHP_URL_HOST) !== parse_url($zipped['linkText'], PHP_URL_HOST)) { + if(parse_url($this->parse($url), PHP_URL_HOST) !== parse_url($this->parse($zipped['linkText']), PHP_URL_HOST)) { $results[] = [ 'href' => $url, 'linkText' => $zipped['linkText'],