diff --git a/src/server/activitypub.ts b/src/server/activitypub.ts index 33120eafd018..ed8cffe4b916 100644 --- a/src/server/activitypub.ts +++ b/src/server/activitypub.ts @@ -42,17 +42,11 @@ async function inbox(ctx: Router.RouterContext) { if (config.disableFederation) ctx.throw(404); // parse body - const text = await coBody.text(ctx); - - // check length - if (text.length > 65535) { - ctx.status = 413; - return; - } - - // to json - const json = await JSON.parse(text); - ctx.request.body = json; + const { parsed, raw } = await coBody.json(ctx, { + limit: '64kb', + returnRawBody: true, + }); + ctx.request.body = parsed; let signature: httpSignature.IParsedSignature; @@ -85,13 +79,13 @@ async function inbox(ctx: Router.RouterContext) { const digestAlgo = match[1]; const digestExpected = match[2]; - if (digestAlgo !== 'SHA-256') { // TODO: lc? + if (digestAlgo.toUpperCase() !== 'SHA-256') { logger.warn(`inbox: unsupported algorithm`); ctx.status = 401; return; } - const digestActual = crypto.createHash('sha256').update(text).digest('base64') + const digestActual = crypto.createHash('sha256').update(raw).digest('base64') if (digestExpected !== digestActual) { logger.warn(`inbox: digest missmatch`);