mirror of https://github.com/pixelfed/pixelfed
Update AP Helpers, improve url validation and add optional dns verification, disabled by default
parent
a00a520bf3
commit
2bef3e415d
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Redis;
|
||||||
|
|
||||||
|
class DomainService
|
||||||
|
{
|
||||||
|
const CACHE_KEY = 'pf:services:domains:';
|
||||||
|
|
||||||
|
public static function hasValidDns($domain)
|
||||||
|
{
|
||||||
|
if(!$domain || !strlen($domain) || strpos($domain, '.') == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(config('security.url.trusted_domains')) {
|
||||||
|
if(in_array($domain, explode(',', config('security.url.trusted_domains')))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Cache::remember(self::CACHE_KEY . 'valid-dns:' . $domain, 14400, function() use($domain) {
|
||||||
|
return count(dns_get_record($domain, DNS_A | DNS_AAAA)) > 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'url' => [
|
||||||
|
'verify_dns' => env('PF_SECURITY_URL_VERIFY_DNS', false),
|
||||||
|
|
||||||
|
'trusted_domains' => env('PF_SECURITY_URL_TRUSTED_DOMAINS', 'pixelfed.social,pixelfed.art,mastodon.social'),
|
||||||
|
]
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue