mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 10:37:45 +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) => {
|
Helpers.assertAccept = (accept) => {
|
||||||
const parts = value.split(';').map(v => v.trim());
|
if (!accept) return false;
|
||||||
return activitypub._constants.acceptableTypes.includes(value || parts[0]);
|
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) => {
|
Helpers.isWebfinger = (value) => {
|
||||||
// N.B. returns normalized handle, so truthy check!
|
// 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'],
|
acceptablePublicAddresses: ['https://www.w3.org/ns/activitystreams#Public', 'as:Public', 'Public'],
|
||||||
acceptableTypes: [
|
acceptableTypes: [
|
||||||
'application/activity+json',
|
'application/activity+json',
|
||||||
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
|
'application/ld+json;profile="https://www.w3.org/ns/activitystreams"',
|
||||||
],
|
],
|
||||||
acceptedPostTypes: [
|
acceptedPostTypes: [
|
||||||
'Note', 'Page', 'Article', 'Question', 'Video',
|
'Note', 'Page', 'Article', 'Question', 'Video',
|
||||||
|
|||||||
Reference in New Issue
Block a user