mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 03:55:55 +01:00
refactor: remove verbose logs,
This commit is contained in:
@@ -31,30 +31,30 @@ middleware.assertS2S = async function (req, res, next) {
|
||||
};
|
||||
|
||||
middleware.validate = async function (req, res, next) {
|
||||
winston.verbose('[middleware/activitypub] Validating incoming payload...');
|
||||
// winston.verbose('[middleware/activitypub] Validating incoming payload...');
|
||||
|
||||
// Sanity-check payload schema
|
||||
const required = ['id', 'type', 'actor', 'object'];
|
||||
if (!required.every(prop => req.body.hasOwnProperty(prop))) {
|
||||
winston.verbose('[middleware/activitypub] Request body missing required properties.');
|
||||
// winston.verbose('[middleware/activitypub] Request body missing required properties.');
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
winston.verbose('[middleware/activitypub] Request body check passed.');
|
||||
// winston.verbose('[middleware/activitypub] Request body check passed.');
|
||||
|
||||
// History check
|
||||
const seen = await db.isSortedSetMember('activities:datetime', req.body.id);
|
||||
if (seen) {
|
||||
winston.verbose(`[middleware/activitypub] Activity already seen, ignoring (${req.body.id}).`);
|
||||
// winston.verbose(`[middleware/activitypub] Activity already seen, ignoring (${req.body.id}).`);
|
||||
return res.sendStatus(200);
|
||||
}
|
||||
|
||||
// Checks the validity of the incoming payload against the sender and rejects on failure
|
||||
const verified = await activitypub.verify(req);
|
||||
if (!verified) {
|
||||
winston.verbose('[middleware/activitypub] HTTP signature verification failed.');
|
||||
// winston.verbose('[middleware/activitypub] HTTP signature verification failed.');
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
winston.verbose('[middleware/activitypub] HTTP signature verification passed.');
|
||||
// winston.verbose('[middleware/activitypub] HTTP signature verification passed.');
|
||||
|
||||
let { actor, object } = req.body;
|
||||
|
||||
@@ -74,10 +74,10 @@ middleware.validate = async function (req, res, next) {
|
||||
const objectHostname = new URL(object.id).hostname;
|
||||
// require that all actors have the same hostname as the object for now
|
||||
if (!actorHostnames.every(actorHostname => actorHostname === objectHostname)) {
|
||||
winston.verbose('[middleware/activitypub] Origin check failed, stripping object down to id.');
|
||||
// winston.verbose('[middleware/activitypub] Origin check failed, stripping object down to id.');
|
||||
req.body.object = [object.id];
|
||||
}
|
||||
winston.verbose('[middleware/activitypub] Origin check passed.');
|
||||
// winston.verbose('[middleware/activitypub] Origin check passed.');
|
||||
}
|
||||
|
||||
// Cross-check key ownership against received actor
|
||||
@@ -89,10 +89,10 @@ middleware.validate = async function (req, res, next) {
|
||||
return [v.substring(0, index), v.slice(index + 1)];
|
||||
})).get('keyId');
|
||||
if (`"${compare}"` !== keyId) {
|
||||
winston.verbose('[middleware/activitypub] Key ownership cross-check failed.');
|
||||
// winston.verbose('[middleware/activitypub] Key ownership cross-check failed.');
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
winston.verbose('[middleware/activitypub] Key ownership cross-check passed.');
|
||||
// winston.verbose('[middleware/activitypub] Key ownership cross-check passed.');
|
||||
|
||||
next();
|
||||
};
|
||||
@@ -100,12 +100,12 @@ middleware.validate = async function (req, res, next) {
|
||||
middleware.resolveObjects = async function (req, res, next) {
|
||||
const { type, object } = req.body;
|
||||
if (type !== 'Delete' && (typeof object === 'string' || (Array.isArray(object) && object.every(o => typeof o === 'string')))) {
|
||||
winston.verbose('[middleware/activitypub] Resolving object(s)...');
|
||||
// winston.verbose('[middleware/activitypub] Resolving object(s)...');
|
||||
try {
|
||||
req.body.object = await activitypub.helpers.resolveObjects(object);
|
||||
winston.verbose('[middleware/activitypub] Object(s) successfully resolved.');
|
||||
// winston.verbose('[middleware/activitypub] Object(s) successfully resolved.');
|
||||
} catch (e) {
|
||||
winston.verbose('[middleware/activitypub] Failed to resolve object(s).');
|
||||
// winston.verbose('[middleware/activitypub] Failed to resolve object(s).');
|
||||
return res.sendStatus(424);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user