Skip to content

Commit

Permalink
fix: add instance blocks (#1326)
Browse files Browse the repository at this point in the history
* fix: add instance blocks

* block domains, not just instances
  • Loading branch information
nolanlawson authored Jul 9, 2019
1 parent ade28cc commit 6b40b2e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/routes/_actions/addInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/routes/_pages/settings/instances/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ <h1 id="add-an-instance-h1">Add instance</h1>
methods: {
onSubmit (event) {
event.preventDefault()
event.stopPropagation()
logInToInstance()
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/routes/_static/blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const DOMAIN_BLOCKS = [
'gab.com',
'gab.ai'
]

0 comments on commit 6b40b2e

Please sign in to comment.