make apiExternal reject unknown servers

This commit is contained in:
FineArchs 2023-10-15 19:57:12 +09:00 committed by GitHub
parent 15706c8c2b
commit 4f48f3065c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -54,6 +54,8 @@ export function api<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoin
export function apiExternal<E extends keyof Misskey.Endpoints, P extends Misskey.Endpoints[E]['req']>(hostUrl: string, endpoint: E, data: P = {} as any, token?: string | null | undefined, signal?: AbortSignal): Promise<Misskey.Endpoints[E]['res']> {
if (!/^https?:\/\//.test(hostUrl)) throw new Error('invalid host name');
if (endpoint.includes('://')) throw new Error('invalid endpoint');
const knownUrls = (await api('federation/instances', { blocked: false })).map(v => v.host);
if (!knownUrls.includes(URL(hostUrl).host)) throw new Error(hostname + 'is blocked by or not known to this server.');
pendingApiRequestsCount.value++;
const onFinally = () => {