diff --git a/CHANGELOG.md b/CHANGELOG.md index b1662cae..5ecedcab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - Update MediaStorageService, improve head header handling ([3590adbd](https://github.com/pixelfed/pixelfed/commit/3590adbd)) - Update admin user view, improve previews ([ff2c16fe](https://github.com/pixelfed/pixelfed/commit/ff2c16fe)) - Update FanoutDeletePipeline, fix AP object ([0d802c31](https://github.com/pixelfed/pixelfed/commit/0d802c31)) +- Update Remote Auth feature, fix custom domain bug and enforce banned domains ([acabf603](https://github.com/pixelfed/pixelfed/commit/acabf603)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.8 (2023-05-29)](https://github.com/pixelfed/pixelfed/compare/v0.11.7...v0.11.8) diff --git a/app/Http/Controllers/RemoteAuthController.php b/app/Http/Controllers/RemoteAuthController.php index d48e5b98..72a2a08d 100644 --- a/app/Http/Controllers/RemoteAuthController.php +++ b/app/Http/Controllers/RemoteAuthController.php @@ -7,6 +7,7 @@ use Illuminate\Http\Request; use App\Services\Account\RemoteAuthService; use App\Models\RemoteAuth; use App\Profile; +use App\Instance; use App\User; use Purify; use Illuminate\Support\Facades\Auth; @@ -36,6 +37,8 @@ class RemoteAuthController extends Controller public function getAuthDomains(Request $request) { + abort_unless(config_cache('pixelfed.open_registration') && config('remote-auth.mastodon.enabled'), 404); + if(config('remote-auth.mastodon.domains.only_custom')) { $res = config('remote-auth.mastodon.domains.custom'); if(!$res || !strlen($res)) { @@ -45,6 +48,19 @@ class RemoteAuthController extends Controller return response()->json($res); } + if( config('remote-auth.mastodon.domains.custom') && + !config('remote-auth.mastodon.domains.only_default') && + strlen(config('remote-auth.mastodon.domains.custom')) > 3 && + strpos(config('remote-auth.mastodon.domains.custom'), '.') > -1 + ) { + $res = config('remote-auth.mastodon.domains.custom'); + if(!$res || !strlen($res)) { + return []; + } + $res = explode(',', $res); + return response()->json($res); + } + $res = config('remote-auth.mastodon.domains.default'); $res = explode(',', $res); @@ -57,6 +73,27 @@ class RemoteAuthController extends Controller $this->validate($request, ['domain' => 'required']); $domain = $request->input('domain'); + + if(str_starts_with(strtolower($domain), 'http')) { + $res = [ + 'domain' => $domain, + 'ready' => false, + 'action' => 'incompatible_domain' + ]; + return response()->json($res); + } + + $validateInstance = Helpers::validateUrl('https://' . $domain . '/?block-check=' . time()); + + if(!$validateInstance) { + $res = [ + 'domain' => $domain, + 'ready' => false, + 'action' => 'blocked_domain' + ]; + return response()->json($res); + } + $compatible = RemoteAuthService::isDomainCompatible($domain); if(!$compatible) { diff --git a/app/Services/Account/RemoteAuthService.php b/app/Services/Account/RemoteAuthService.php index b9936b7b..4412352a 100644 --- a/app/Services/Account/RemoteAuthService.php +++ b/app/Services/Account/RemoteAuthService.php @@ -12,6 +12,14 @@ class RemoteAuthService { const CACHE_KEY = 'pf:services:remoteauth:'; + public static function getConfig() + { + return json_encode([ + 'default_only' => config('remote-auth.mastodon.domains.only_default'), + 'custom_only' => config('remote-auth.mastodon.domains.only_custom'), + ]); + } + public static function getMastodonClient($domain) { if(RemoteAuthInstance::whereDomain($domain)->exists()) { diff --git a/public/js/remote_auth.js b/public/js/remote_auth.js index e4353ac7..88c60f98 100644 Binary files a/public/js/remote_auth.js and b/public/js/remote_auth.js differ diff --git a/public/mix-manifest.json b/public/mix-manifest.json index d23c311d..233d7ba7 100644 Binary files a/public/mix-manifest.json and b/public/mix-manifest.json differ diff --git a/resources/assets/components/remote-auth/StartComponent.vue b/resources/assets/components/remote-auth/StartComponent.vue index b8b096e1..c93fc8f7 100644 --- a/resources/assets/components/remote-auth/StartComponent.vue +++ b/resources/assets/components/remote-auth/StartComponent.vue @@ -24,8 +24,8 @@ @click="handleRedirect(domain)"> {{ domain }} -
-

+


+

@@ -43,6 +43,12 @@