X-Git-Url: http://git.squeep.com/?p=websub-hub;a=blobdiff_plain;f=src%2Fmanager.js;h=b6d2ccb6322fa2162662cc925e0859b4927d42e2;hp=9d4a282c2aac17864d3e330ba4e655cd424493fc;hb=4d71e429a0d0890184635727e227759876347fed;hpb=b489a88ad17b51463ae57f1b54f84053059c3909 diff --git a/src/manager.js b/src/manager.js index 9d4a282..b6d2ccb 100644 --- a/src/manager.js +++ b/src/manager.js @@ -606,6 +606,21 @@ class Manager { this.logger.info(_scope, 'finished', { ctx }); } + + /** + * Determine if a profile url matches enough of a topic url to describe control over it. + * Topic must match hostname and start with the profile's path. + * @param {URL} profileUrlObj + * @param {URL} topicUrlObj + * @returns {Boolean} + */ + static _profileControlsTopic(profileUrlObj, topicUrlObj) { + const hostnameMatches = profileUrlObj.hostname === topicUrlObj.hostname; + const pathIsPrefix = topicUrlObj.pathname.startsWith(profileUrlObj.pathname); + return hostnameMatches && pathIsPrefix; + } + + /** * GET request for authorized /admin information. * @param {http.ServerResponse} res @@ -625,7 +640,7 @@ class Manager { const profileUrlObj = new URL(ctx.session.authenticatedProfile); ctx.topics = ctx.topics.filter((topic) => { const topicUrlObj = new URL(topic.url); - return (topicUrlObj.hostname === profileUrlObj.hostname); + return Manager._profileControlsTopic(profileUrlObj, topicUrlObj); }); } @@ -659,7 +674,7 @@ class Manager { if (ctx.session && ctx.session.authenticatedProfile) { const profileUrlObj = new URL(ctx.session.authenticatedProfile); const topicUrlObj = new URL(ctx.topic.url); - if (topicUrlObj.hostname !== profileUrlObj.hostname) { + if (!Manager._profileControlsTopic(profileUrlObj, topicUrlObj)) { ctx.topic = null; ctx.subscriptions = []; }