Skip to content

Commit 5e8962d

Browse files
committed
fix(handler): deny access when body.allowed is 'false'
1 parent 5f2b0bb commit 5e8962d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/handlers/authorize-handler.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ AuthorizeHandler.prototype.handle = function(request, response) {
7777
throw new InvalidArgumentError('Invalid argument: `response` must be an instance of Response');
7878
}
7979

80-
if ('false' === request.query.allowed) {
80+
const notAllowed = [
81+
request.query.allowed,
82+
request.body.allowed
83+
].some(allowed => 'false' === allowed);
84+
85+
if (notAllowed) {
8186
return Promise.reject(new AccessDeniedError('Access denied: user denied access to application'));
8287
}
8388

test/integration/handlers/authorize-handler_test.js

+18
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,24 @@ describe('AuthorizeHandler integration', function() {
177177
});
178178
});
179179

180+
it('should throw an error if `allowed` is `false` body', function() {
181+
const model = {
182+
getAccessToken: function() {},
183+
getClient: function() {},
184+
saveAuthorizationCode: function() {}
185+
};
186+
const handler = new AuthorizeHandler({ authorizationCodeLifetime: 120, model: model });
187+
const request = new Request({ body: { allowed: 'false' }, headers: {}, method: {}, query: {} });
188+
const response = new Response({ body: {}, headers: {} });
189+
190+
return handler.handle(request, response)
191+
.then(should.fail)
192+
.catch(function(e) {
193+
e.should.be.an.instanceOf(AccessDeniedError);
194+
e.message.should.equal('Access denied: user denied access to application');
195+
});
196+
});
197+
180198
it('should redirect to an error response if a non-oauth error is thrown', function() {
181199
const model = {
182200
getAccessToken: function() {

0 commit comments

Comments
 (0)