make apiExternal reject unknown servers
This commit is contained in:
parent
15706c8c2b
commit
4f48f3065c
|
|
@ -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']> {
|
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 (!/^https?:\/\//.test(hostUrl)) throw new Error('invalid host name');
|
||||||
if (endpoint.includes('://')) throw new Error('invalid endpoint');
|
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++;
|
pendingApiRequestsCount.value++;
|
||||||
|
|
||||||
const onFinally = () => {
|
const onFinally = () => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue