diff --git a/src/routes/_actions/addInstance.js b/src/routes/_actions/addInstance.js index 8a2a2a4e..c91eb140 100644 --- a/src/routes/_actions/addInstance.js +++ b/src/routes/_actions/addInstance.js @@ -6,17 +6,25 @@ import { store } from '../_store/store' import { updateVerifyCredentialsForInstance } from './instances' import { updateCustomEmojiForInstance } from './emoji' import { database } from '../_database/database' +import { DOMAIN_BLOCKS } from '../_static/blocks' const REDIRECT_URI = (typeof location !== 'undefined' ? location.origin : 'https://pinafore.social') + '/settings/instances/add' +function createKnownError (message) { + let err = new Error(message) + err.knownError = true + return err +} + async function redirectToOauth () { let { instanceNameInSearch, loggedInInstances } = store.get() - instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/$/, '').replace('/$', '').toLowerCase() + instanceNameInSearch = instanceNameInSearch.replace(/^https?:\/\//, '').replace(/\/+$/, '').toLowerCase() if (Object.keys(loggedInInstances).includes(instanceNameInSearch)) { - let err = new Error(`You've already logged in to ${instanceNameInSearch}`) - err.knownError = true - throw err + throw createKnownError(`You've already logged in to ${instanceNameInSearch}`) + } + if (DOMAIN_BLOCKS.some(domain => new RegExp(`(?:\\.|^)${domain}$`, 'i').test(instanceNameInSearch))) { + throw createKnownError('This service is blocked') } let registrationPromise = registerApplication(instanceNameInSearch, REDIRECT_URI) let instanceInfo = await getInstanceInfo(instanceNameInSearch) diff --git a/src/routes/_pages/settings/instances/add.html b/src/routes/_pages/settings/instances/add.html index be692728..478d21fd 100644 --- a/src/routes/_pages/settings/instances/add.html +++ b/src/routes/_pages/settings/instances/add.html @@ -112,6 +112,7 @@ methods: { onSubmit (event) { event.preventDefault() + event.stopPropagation() logInToInstance() } } diff --git a/src/routes/_static/blocks.js b/src/routes/_static/blocks.js new file mode 100644 index 00000000..064b6ffc --- /dev/null +++ b/src/routes/_static/blocks.js @@ -0,0 +1,4 @@ +export const DOMAIN_BLOCKS = [ + 'gab.com', + 'gab.ai' +]