From c741be86539159cca74e0cf155b2f9b7eacb568e Mon Sep 17 00:00:00 2001 From: Her Email Date: Wed, 6 Dec 2023 00:38:44 -0500 Subject: [PATCH] no login via neodb itself --- mastodon/api.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mastodon/api.py b/mastodon/api.py index b2df9ca0..06de9ff3 100644 --- a/mastodon/api.py +++ b/mastodon/api.py @@ -265,7 +265,7 @@ class TootVisibilityEnum: UNLISTED = "unlisted" -def detect_server_info(login_domain): +def detect_server_info(login_domain) -> tuple[str, str, str]: url = f"https://{login_domain}/api/v1/instance" try: response = get(url, headers={"User-Agent": USER_AGENT}) @@ -306,7 +306,16 @@ def get_or_create_fediverse_application(login_domain): if not settings.MASTODON_ALLOW_ANY_SITE: logger.error(f"Disallowed to create app for {domain}") raise Exception("不支持其它实例登录") + if settings.SITE_DOMAIN.lower() == login_domain.lower(): + raise ValueError("必须使用其它实例登录") domain, api_domain, server_version = detect_server_info(login_domain) + if ( + settings.SITE_DOMAIN.lower() == domain.lower() + or settings.SITE_DOMAIN.lower() == api_domain.lower() + ): + raise ValueError("必须使用其它实例登录") + if "neodb/" in server_version: + raise ValueError("必须使用非NeoDB实例登录") if login_domain != domain: app = MastodonApplication.objects.filter(domain_name__iexact=domain).first() if app: