Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domain blocking #79

Merged
merged 1 commit into from
Dec 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ async function actorOnDemand (req, res, next) {
} catch (err) { return next(err) }
next()
}
// Do not boost posts from servers who abuse the service.
apex.net.inbox.post.splice(
// Blocked domain check is inserted into apex inbox route right after the sender is verified
apex.net.inbox.post.indexOf(apex.net.security.verifySignature) + 1,
0,
async function rejectBlockedDomains (req, res, next) {
try {
const url = new URL(res.locals.apex.sender.id)
const domain = await req.app.locals.apex.store.db.collection('servers').findOne({
hostname: url.hostname
})
if (domain?.blocked) {
console.log(`Ignoring post from ${url}:`, req.body)
return res.sendStatus(200)
}
} catch (err) {
console.error('Error checking domain blocks:', err)
}
next()
}
)

// define routes using prepacakged middleware collections
app.route(routes.inbox)
.post(actorOnDemand, apex.net.inbox.post)
Expand Down Expand Up @@ -198,6 +220,12 @@ client.connect()
const { default: AutoEncrypt } = await import('@small-tech/auto-encrypt')
apex.store.db = client.db(DB_NAME)
await apex.store.setup()
await apex.store.db.collection('servers').createIndex({
hostname: 1
}, {
name: 'servers-primary',
unique: true
})
apex.systemUser = await apex.store.getObject(apex.utils.usernameToIRI('system_service'), true)
if (!apex.systemUser) {
const systemUser = await apex.createActor('system_service', `${DOMAIN} system service`, `${DOMAIN} system service`, icon, 'Service')
Expand Down