fix: add instance blocks (#1326)

* fix: add instance blocks

* block domains, not just instances
This commit is contained in:
Nolan Lawson 2019-07-08 19:26:44 -07:00 committed by GitHub
parent ade28cca5d
commit 6b40b2efbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View file

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

View file

@ -112,6 +112,7 @@
methods: {
onSubmit (event) {
event.preventDefault()
event.stopPropagation()
logInToInstance()
}
}

View file

@ -0,0 +1,4 @@
export const DOMAIN_BLOCKS = [
'gab.com',
'gab.ai'
]