リレーに不正なURLは追加できないように (#6351)

* リレーに不正なURLは追加できないように

* lint
This commit is contained in:
MeiMei 2020-05-15 20:51:16 +09:00 committed by GitHub
parent e133392d04
commit 706c2fe925
2 changed files with 25 additions and 0 deletions

View file

@ -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
});
});
},

View file

@ -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);
});