Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update AP Helpers, improve url validation and add optional dns verifi…
…cation, disabled by default
- Loading branch information
Showing
3 changed files
with
54 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'), | ||
] | ||
]; |