From ec4e7ef1b7b02e533edbf3b15bea1afc19a92fe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 20 Jan 2026 22:19:22 -0500 Subject: [PATCH] fix: closes #13199 normalize accept header @julianlam tried accepts module ran into issues when the route was requested via browser or via $.ajax with the default headers, for example accepts(req).type(activitypub._constants.acceptableTypes) still returns true when /post/123 is loaded via browser or via $.ajax --- src/activitypub/helpers.js | 9 +++++---- src/activitypub/index.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/activitypub/helpers.js b/src/activitypub/helpers.js index 80135808ab..a966d26ac0 100644 --- a/src/activitypub/helpers.js +++ b/src/activitypub/helpers.js @@ -65,10 +65,11 @@ Helpers.isUri = (value) => { }); }; -Helpers.assertAccept = accept => (accept && accept.split(',').some((value) => { - const parts = value.split(';').map(v => v.trim()); - return activitypub._constants.acceptableTypes.includes(value || parts[0]); -})); +Helpers.assertAccept = (accept) => { + if (!accept) return false; + const normalized = accept.split(',').map(s => s.trim().replace(/\s*;\s*/g, ';')).join(','); + return activitypub._constants.acceptableTypes.some(type => normalized.includes(type)); +}; Helpers.isWebfinger = (value) => { // N.B. returns normalized handle, so truthy check! diff --git a/src/activitypub/index.js b/src/activitypub/index.js index 92dd10b544..4ab6159f2f 100644 --- a/src/activitypub/index.js +++ b/src/activitypub/index.js @@ -41,7 +41,7 @@ ActivityPub._constants = Object.freeze({ acceptablePublicAddresses: ['https://www.w3.org/ns/activitystreams#Public', 'as:Public', 'Public'], acceptableTypes: [ 'application/activity+json', - 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'application/ld+json;profile="https://www.w3.org/ns/activitystreams"', ], acceptedPostTypes: [ 'Note', 'Page', 'Article', 'Question', 'Video',