mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-03 01:39:15 +02:00
Strengthen validation of URL in proxy services
This should definitively rule out any circumstances, where invalid URLs could cause problems. Both URL validity is checked before it is forwarded to the URL shortener proxy _and_ the host part is explicitly compared to make sure the domain is really the same one. TOOD: * [ ] some tests may be needed here (hmpff…)
This commit is contained in:
parent
a72545c994
commit
2c1a17a07f
1 changed files with 8 additions and 1 deletions
|
@ -49,7 +49,14 @@ abstract class AbstractProxy
|
|||
*/
|
||||
public function __construct(Configuration $conf, string $link)
|
||||
{
|
||||
if (!str_starts_with($link, $conf->getKey('basepath') . '?')) {
|
||||
if (!filter_var($link, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED & FILTER_FLAG_QUERY_REQUIRED)) {
|
||||
$this->_error = 'Invalid URL given.';
|
||||
return;
|
||||
}
|
||||
|
||||
if (!str_starts_with($link, $conf->getKey('basepath') . '?') ||
|
||||
parse_url($link, PHP_URL_HOST) != parse_url($conf->getKey('basepath'), PHP_URL_HOST)
|
||||
) {
|
||||
$this->_error = 'Trying to shorten a URL that isn\'t pointing at our instance.';
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue