mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-05-04 13:16:31 +00:00
🤖 Auto commit for release 'develop' on 2026-03-06
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Rules\Webhook;
|
||||
|
||||
use Closure;
|
||||
@@ -7,6 +9,7 @@ use FireflyIII\Support\Facades\FireflyConfig;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
use function Safe\parse_url;
|
||||
|
||||
class IsValidWebhookUrl implements ValidationRule
|
||||
@@ -16,13 +19,14 @@ class IsValidWebhookUrl implements ValidationRule
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
$value = (string)$value;
|
||||
$resolved = gethostbyname(parse_url($value, PHP_URL_HOST));
|
||||
$value = (string) $value;
|
||||
$resolved = gethostbyname(parse_url($value, PHP_URL_HOST));
|
||||
Log::debug(sprintf('Now validating URL "%s" with IP "%s".', $value, $resolved));
|
||||
|
||||
// IPv4 is allowed to be in 127 range.
|
||||
if(filter_var($resolved, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && IpUtils::checkIp4($resolved, '127.0.0.0/8')) {
|
||||
if (filter_var($resolved, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && IpUtils::checkIp4($resolved, '127.0.0.0/8')) {
|
||||
Log::debug(sprintf('Local IP "%s" is allowed', $resolved));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,16 +35,15 @@ class IsValidWebhookUrl implements ValidationRule
|
||||
$fail('validation.no_reserved_ip')->translate();
|
||||
}
|
||||
$validProtocols = FireflyConfig::get('valid_url_protocols', config('firefly.valid_url_protocols'))->data;
|
||||
$parts = explode(',', $validProtocols);
|
||||
$valid = false;
|
||||
foreach($parts as $part) {
|
||||
if(str_starts_with($value, $part)) {
|
||||
$parts = explode(',', $validProtocols);
|
||||
$valid = false;
|
||||
foreach ($parts as $part) {
|
||||
if (str_starts_with($value, $part)) {
|
||||
$valid = true;
|
||||
}
|
||||
}
|
||||
if(false === $valid) {
|
||||
if (false === $valid) {
|
||||
$fail('validation.bad_url_prefix')->translate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user