From 1ceaa155070afc39a75cece0c8a38aeef2aaa75c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 18 Sep 2019 08:39:17 -0400 Subject: [PATCH] Fix returning strings instead of JSON objects as actors on bad responses --- lib/activitypub/federate.ts | 4 +--- lib/activitypub/middleware/http-signature.ts | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/activitypub/federate.ts b/lib/activitypub/federate.ts index d268d13..9e182b3 100644 --- a/lib/activitypub/federate.ts +++ b/lib/activitypub/federate.ts @@ -57,8 +57,6 @@ export async function getCachedActor(url: string): Promise { } async function cacheActor(actorObject: ActorObject) { - if (!actorObject.publicKey) return; - function getIconUrl(icon: string | object): string { return icon instanceof String ? icon : (icon as any).url; } @@ -88,7 +86,7 @@ async function fetchActor(url?: string): Promise { json: true }, (err, res) => { if (err) reject(err); - else resolve(res.body ? res.body as ActorObject : null); + else resolve(res.body && res.body instanceof Object ? res.body as ActorObject : null); }); }); } diff --git a/lib/activitypub/middleware/http-signature.ts b/lib/activitypub/middleware/http-signature.ts index 8f579a5..4f583b8 100644 --- a/lib/activitypub/middleware/http-signature.ts +++ b/lib/activitypub/middleware/http-signature.ts @@ -25,9 +25,6 @@ export = async (req: Request, res: Response, next: NextFunction) => { console.log(`Could not retrieve actor ${req.body.actor} to validate HTTP signature for`, req.body); res.status(401).end("Could not retrieve actor to validate HTTP signature"); } - } else if (!actor.publicKey) { - console.log(`Could not validate HTTP signature, actor missing public key: ${actor}`); - res.status(401).end("Actor missing public key.") } else if (!validate(req, actor.publicKey.publicKeyPem)) { console.log(`Could not validate HTTP signature for ${req.body.actor}`); res.status(401).end("Could not validate HTTP signature");