mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-21 15:03:12 +01:00
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:
@@ -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!
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user