Skip to content

Commit f5c9fad

Browse files
committed
fix: Destination URLs are no longer URL decoded _unless_ a malicious payload was stripped from them ([#330](#330))
1 parent 9a13038 commit f5c9fad

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/helpers/UrlHelper.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ public static function mergeUrlWithPath($url, $path): string
138138
*/
139139
public static function sanitizeUrl(string $url): string
140140
{
141+
$originalUrl = $url;
141142
// HTML decode the entities, then strip out any tags
142143
$url = html_entity_decode($url, ENT_NOQUOTES, 'UTF-8');
143144
$url = urldecode($url);
145+
$decodedUrl = $url;
144146
$url = strip_tags($url);
145147
// Remove any Twig tags that somehow are present in the incoming URL
146148
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
@@ -153,7 +155,10 @@ public static function sanitizeUrl(string $url): string
153155
]
154156
, '', $url
155157
);
156-
158+
// If the URL didn't have anything stripped from it, us the original encoded URL
159+
if ($url === $decodedUrl) {
160+
$url = $originalUrl;
161+
}
157162
return $url;
158163
}
159164
}

0 commit comments

Comments
 (0)