mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
feat: resolve objects from ids in middleware
This commit is contained in:
@@ -55,8 +55,8 @@ middleware.validate = async function (req, res, next) {
|
||||
const actorHostname = new URL(actor).hostname;
|
||||
const objectHostname = new URL(object.id).hostname;
|
||||
if (actorHostname !== objectHostname) {
|
||||
winston.verbose('[middleware/activitypub] Origin check failed.');
|
||||
return res.sendStatus(403);
|
||||
winston.verbose('[middleware/activitypub] Origin check failed, stripping object down to id.');
|
||||
req.body.object = [object.id];
|
||||
}
|
||||
winston.verbose('[middleware/activitypub] Origin check passed.');
|
||||
}
|
||||
@@ -75,6 +75,21 @@ middleware.validate = async function (req, res, next) {
|
||||
next();
|
||||
};
|
||||
|
||||
middleware.resolveObjects = async function (req, res, next) {
|
||||
const { object } = req.body;
|
||||
if (typeof object === 'string' || (Array.isArray(object) && object.every(o => typeof o === 'string'))) {
|
||||
winston.verbose('[middleware/activitypub] Resolving object(s)...');
|
||||
try {
|
||||
req.body.object = await activitypub.helpers.resolveObjects(object);
|
||||
winston.verbose('[middleware/activitypub] Object(s) successfully resolved.');
|
||||
} catch (e) {
|
||||
winston.verbose('[middleware/activitypub] Failed to resolve object(s).');
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
middleware.configureResponse = async function (req, res, next) {
|
||||
res.header('Content-Type', 'application/activity+json');
|
||||
next();
|
||||
|
||||
Reference in New Issue
Block a user