Skip to content

Node.js based forum software built for the modern web

fix: #13136, do not log 404s for AP requests

Julian Lam93f48409c5aa
diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js
index 5a50e2e8ed..79aebc25dc 100644
--- a/src/activitypub/helpers.js
+++ b/src/activitypub/helpers.js
@@ -64,6 +64,11 @@ Helpers.isUri = (value) => {
});
};
+Helpers.assertAccept = accept => (accept && accept.split(',').some((value) => {
+ const parts = value.split(';').map(v => v.trim());
+ return activitypub._constants.acceptableTypes.includes(value || parts[0]);
+}));
+
Helpers.isWebfinger = (value) => {
// N.B. returns normalized handle, so truthy check!
if (webfingerRegex.test(value) && !Helpers.isUri(value)) {
diff --git a/src/controllers/404.js b/src/controllers/404.js
index becc206e76..bed1a085e3 100644
--- a/src/controllers/404.js
+++ b/src/controllers/404.js
@@ -6,6 +6,7 @@ const validator = require('validator');
const meta = require('../meta');
const plugins = require('../plugins');
+const activitypub = require('../activitypub');
const middleware = require('../middleware');
const helpers = require('../middleware/helpers');
const { secureRandom } = require('../utils');
@@ -24,6 +25,12 @@ exports.handle404 = helpers.try(async (req, res) => {
if (isClientScript.test(req.url)) {
res.type('text/javascript').status(404).send('Not Found');
+ } else if (
+ activitypub.helpers.assertAccept(req.headers.accept) ||
+ (req.headers['Content-Type'] && activitypub._constants.acceptableTypes.includes(req.headers['Content-Type']))
+ ) {
+ // todo: separate logging of AP 404s
+ res.sendStatus(404);
} else if (
!res.locals.isAPI && (
req.path.startsWith(`${relativePath}/assets/uploads`) ||
diff --git a/src/middleware/activitypub.js b/src/middleware/activitypub.js
index f9b8dcd009..ee7d8a2460 100644
--- a/src/middleware/activitypub.js
+++ b/src/middleware/activitypub.js
@@ -16,10 +16,8 @@ middleware.assertS2S = async function (req, res, next) {
return next('route');
}
- const pass = (accept && accept.split(',').some((value) => {
- const parts = value.split(';').map(v => v.trim());
- return activitypub._constants.acceptableTypes.includes(value || parts[0]);
- })) || (contentType && activitypub._constants.acceptableTypes.includes(contentType));
+ const pass = activitypub.helpers.assertAccepts(accept) ||
+ (contentType && activitypub._constants.acceptableTypes.includes(contentType));
if (!pass) {
return next('route');