From 538ca2a7c7898b698d3c607e99ad32044c70c884 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 15 May 2020 20:51:16 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AA=E3=83=AC=E3=83=BC=E3=81=AB=E4=B8=8D?= =?UTF-8?q?=E6=AD=A3=E3=81=AAURL=E3=81=AF=E8=BF=BD=E5=8A=A0=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=81=AA=E3=81=84=E3=82=88=E3=81=86=E3=81=AB=20(#6351?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * リレーに不正なURLは追加できないように * lint --- src/client/pages/instance/relays.vue | 10 ++++++++++ src/server/api/endpoints/admin/relays/add.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/client/pages/instance/relays.vue b/src/client/pages/instance/relays.vue index 568f5edd71..9b523bd0ec 100644 --- a/src/client/pages/instance/relays.vue +++ b/src/client/pages/instance/relays.vue @@ -64,6 +64,11 @@ export default Vue.extend({ inbox }).then((relay: any) => { this.refresh(); + }).catch((e: any) => { + this.$root.dialog({ + type: 'error', + text: e.message || e + }); }); }, @@ -72,6 +77,11 @@ export default Vue.extend({ inbox }).then(() => { this.refresh(); + }).catch((e: any) => { + this.$root.dialog({ + type: 'error', + text: e.message || e + }); }); }, diff --git a/src/server/api/endpoints/admin/relays/add.ts b/src/server/api/endpoints/admin/relays/add.ts index 3ea6bcc73b..bcda1050e8 100644 --- a/src/server/api/endpoints/admin/relays/add.ts +++ b/src/server/api/endpoints/admin/relays/add.ts @@ -1,6 +1,7 @@ import $ from 'cafy'; import define from '../../../define'; import { addRelay } from '../../../../../services/relay'; +import { ApiError } from '../../../error'; export const meta = { desc: { @@ -17,8 +18,22 @@ export const meta = { validator: $.str }, }, + + errors: { + invalidUrl: { + message: 'Invalid URL', + code: 'INVALID_URL', + id: 'fb8c92d3-d4e5-44e7-b3d4-800d5cef8b2c' + }, + } }; export default define(meta, async (ps, user) => { + try { + if (new URL(ps.inbox).protocol !== 'https:') throw 'https only'; + } catch { + throw new ApiError(meta.errors.invalidUrl); + } + return await addRelay(ps.inbox); });