From 2ae5097d9360c5c4cee3207b883c68e2f5398a47 Mon Sep 17 00:00:00 2001 From: les Date: Fri, 13 Sep 2019 11:08:18 +0200 Subject: [PATCH] ignore unimplemented ping url from fediverse --- server/federation/helpers.js | 13 +++++++++++++ server/federation/index.js | 5 +++-- server/routes.js | 7 ++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/server/federation/helpers.js b/server/federation/helpers.js index bb0270db..fd3ea81e 100644 --- a/server/federation/helpers.js +++ b/server/federation/helpers.js @@ -9,6 +9,19 @@ const url = require('url') const settings = require('../api/controller/settings') const Helpers = { + + // ignore unimplemented ping url from fediverse + async spamFilter (req, res, next) { + const urlToIgnore = [ + '/api/v1/instance', + '/api/meta', + '/api/statusnet/config.json', + '/poco', + ] + if (urlToIgnore.includes(req.path)) return res.status(404).send('Not Found') + next() + }, + async signAndSend (message, user, to) { // get the URI of the actor object and append 'inbox' to it const toUrl = url.parse(to) diff --git a/server/federation/index.js b/server/federation/index.js index e2c4c3a5..385c06e5 100644 --- a/server/federation/index.js +++ b/server/federation/index.js @@ -1,6 +1,5 @@ const express = require('express') const router = express.Router() -const config = require('config') const cors = require('cors') const Follows = require('./follows') const Users = require('./users') @@ -14,12 +13,14 @@ const debug = require('debug')('federation') * Federation is calling! * ref: https://www.w3.org/TR/activitypub/#Overview */ + + router.use(cors()) router.use(express.json({ type: ['application/json', 'application/activity+json', 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'] })) router.get('/m/:event_id', async (req, res) => { const event_id = req.params.event_id - // if (req.accepts('html')) return res.redirect(301, `/event/${event_id}`) + if (req.accepts('html')) return res.redirect(301, `/event/${event_id}`) const event = await Event.findByPk(req.params.event_id, { include: [ User, Tag, Place ] }) if (!event) { return res.status(404).send('Not found') } diff --git a/server/routes.js b/server/routes.js index 19c2e4f7..eefe59bf 100644 --- a/server/routes.js +++ b/server/routes.js @@ -4,6 +4,7 @@ const express = require('express') const api = require('./api') const federation = require('./federation') const webfinger = require('./federation/webfinger') +const { spamFilter } = require('./federation/helpers') const debug = require('debug')('routes') const router = express.Router() @@ -12,6 +13,9 @@ router.use((req, res, next) => { next() }) +// ignore unimplemented ping url from fediverse +router.use(spamFilter) + router.use('/favicon.ico', express.static(path.resolve(config.favicon || 'assets/favicon.ico'))) router.use('/media/', express.static(config.upload_path)) router.use('/api', api) @@ -20,9 +24,6 @@ router.use('/api', api) router.use('/.well-known', webfinger) router.use('/federation', federation) -// ignore unimplemented ping url from fediverse -router.use('/poco', (req, res) => res.status(404).send('404: Page not found')) - // Handle 404 // router.use((req, res) => res.status(404).send('404: Page not found'))