Skip to content

Commit

Permalink
Deny unauthorized access to channel type.
Browse files Browse the repository at this point in the history
	modified:   lib/services/identity/controllers/identity-channel-controller.js
  • Loading branch information
kixxauth committed Oct 27, 2016
1 parent b0ecd3d commit 241e233
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/services/identity/controllers/identity-channel-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class IdentityChannelController extends IdentityItemController {
const id = req.params.id;
const args = {type, id};

if (!this.checkChannelAccess(req)) {
return next(Boom.forbidden('Access to the requested channel is forbidden'));
}

if (req.query.include) {
args.include = req.query.include.split(',');
}
Expand All @@ -37,6 +41,10 @@ class IdentityChannelController extends IdentityItemController {
const payload = req.body;
const args = {type, id};

if (!this.checkChannelAccess(req)) {
return next(Boom.forbidden('Access to the requested channel is forbidden'));
}

return this.bus.query({role: 'store', cmd: 'get', type}, args)
.then(resource => {
if (resource) {
Expand All @@ -63,6 +71,10 @@ class IdentityChannelController extends IdentityItemController {
const id = req.params.id;
const args = {type, id};

if (!this.checkChannelAccess(req)) {
return next(Boom.forbidden('Access to the requested channel is forbidden'));
}

return this.bus.sendCommand({role: 'store', cmd: 'remove', type}, args)
.then(() => {
res.body = {};
Expand All @@ -73,6 +85,14 @@ class IdentityChannelController extends IdentityItemController {
.catch(next);
}

checkChannelAccess(req) {
if (this.isAdminRequest(req)) {
return true;
}

return req.params.id === _.get(req, 'identity.channel.id');
}

static create(spec) {
if (!spec.bus || !_.isObject(spec.bus)) {
throw new Error('IdentityChannelController spec.bus is required');
Expand Down

0 comments on commit 241e233

Please sign in to comment.