mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Fix issue with wildcard domain blocks
This commit is contained in:
parent
2d34e86f26
commit
96a226d90c
1 changed files with 13 additions and 0 deletions
|
@ -64,6 +64,19 @@ class DomainBlocksController extends ApiController {
|
||||||
abort_if(!strpos($domain, '.'), 400, 'Invalid domain');
|
abort_if(!strpos($domain, '.'), 400, 'Invalid domain');
|
||||||
abort_if(!filter_var($domain, FILTER_VALIDATE_DOMAIN), 400, 'Invalid domain');
|
abort_if(!filter_var($domain, FILTER_VALIDATE_DOMAIN), 400, 'Invalid domain');
|
||||||
|
|
||||||
|
$parts = explode('.', $domain);
|
||||||
|
|
||||||
|
if ($parts[0] == '*') {
|
||||||
|
// If we only have two parts, e.g., "*", "example", then we want to fail:
|
||||||
|
abort_if(count($parts) <= 2, 400, 'Invalid domain: This API does not support wildcard domain blocks yet');
|
||||||
|
|
||||||
|
// Otherwise we convert the *.foo.example to foo.example
|
||||||
|
$domain = implode('.', array_slice($parts, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Double check we definitely haven't let anything through:
|
||||||
|
abort_if(str_contains($domain, '*'), 400, 'Invalid domain');
|
||||||
|
|
||||||
$existing_domain_block = Instance::moderated()->whereDomain($domain)->first();
|
$existing_domain_block = Instance::moderated()->whereDomain($domain)->first();
|
||||||
|
|
||||||
if ($existing_domain_block) {
|
if ($existing_domain_block) {
|
||||||
|
|
Loading…
Reference in a new issue