fix: actors.assert attempting to process things that aren't actors, #12809

This commit is contained in:
Julian Lam
2024-09-19 14:52:05 -04:00
parent 6752a54116
commit 6b4b4b1a00
2 changed files with 18 additions and 0 deletions

View File

@@ -20,6 +20,16 @@ const activitypub = module.parent.exports;
const Actors = module.exports; const Actors = module.exports;
Actors.assert = async (ids, options = {}) => { Actors.assert = async (ids, options = {}) => {
/**
* Ensures that the passed in ids or webfinger handles are stored in database.
* Options:
* - update: boolean, forces re-fetch/process of the resolved id
* Return one of:
* - An array of newly processed ids
* - false: if input incorrect (or webfinger handle cannot resolve)
* - true: no new IDs processed; all passed-in IDs present.
*/
// Handle single values // Handle single values
if (!Array.isArray(ids)) { if (!Array.isArray(ids)) {
ids = [ids]; ids = [ids];
@@ -89,6 +99,12 @@ Actors.assert = async (ids, options = {}) => {
try { try {
// winston.verbose(`[activitypub/actors] Processing ${id}`); // winston.verbose(`[activitypub/actors] Processing ${id}`);
const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get('uid', 0, id, { cache: process.env.CI === 'true' }); const actor = (typeof id === 'object' && id.hasOwnProperty('id')) ? id : await activitypub.get('uid', 0, id, { cache: process.env.CI === 'true' });
if (
!activitypub._constants.acceptableActorTypes.has(actor.type) ||
!activitypub._constants.requiredActorProps.every(prop => actor.hasOwnProperty(prop))
) {
return null;
}
// Follow counts // Follow counts
try { try {

View File

@@ -33,6 +33,8 @@ ActivityPub._constants = Object.freeze({
acceptedPostTypes: [ acceptedPostTypes: [
'Note', 'Page', 'Article', 'Question', 'Note', 'Page', 'Article', 'Question',
], ],
acceptableActorTypes: new Set(['Application', 'Group', 'Organization', 'Person', 'Service']),
requiredActorProps: ['inbox', 'outbox'],
acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])], acceptedProtocols: ['https', ...(process.env.CI === 'true' ? ['http'] : [])],
}); });
ActivityPub._cache = requestCache; ActivityPub._cache = requestCache;