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
This commit is contained in:
Barış Soner Uşaklı
2026-01-20 22:19:22 -05:00
parent 7bc9fe3b75
commit ec4e7ef1b7
2 changed files with 6 additions and 5 deletions

View File

@@ -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!

View File

@@ -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',