Skip to content

Commit e1ccae8

Browse files
committed
Merge branch 'w/8.8/bugfix/CLDSRV-616' into tmp/octopus/w/9.0/bugfix/CLDSRV-616
2 parents 77d41df + e9441c6 commit e1ccae8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/api/apiUtils/authorization/permissionChecks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ function _checkPrincipal(requester, principal) {
282282
if (principal === '*') {
283283
return true;
284284
}
285+
// User in unauthenticated (anonymous request)
286+
if (requester === undefined) {
287+
return false;
288+
}
285289
if (principal === requester) {
286290
return true;
287291
}

tests/unit/api/bucketPolicyAuth.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const assert = require('assert');
22
const { BucketInfo, BucketPolicy } = require('arsenal').models;
3+
const AuthInfo = require('arsenal').auth.AuthInfo;
34
const constants = require('../../../constants');
45
const { isBucketAuthorized, isObjAuthorized, validatePolicyResource }
56
= require('../../../lib/api/apiUtils/authorization/permissionChecks');
@@ -35,6 +36,9 @@ const basePolicyObj = {
3536
};
3637
const bucketName = 'matchme';
3738
const log = new DummyRequestLogger();
39+
const publicUserAuthInfo = new AuthInfo({
40+
canonicalID: constants.publicId,
41+
});
3842

3943
const authTests = [
4044
{
@@ -292,11 +296,21 @@ describe('bucket policy authorization', () => {
292296
it('should allow access to public user if principal is set to "*"',
293297
done => {
294298
const allowed = isBucketAuthorized(bucket, bucAction,
295-
constants.publicId, null, log);
299+
constants.publicId, publicUserAuthInfo, log);
296300
assert.equal(allowed, true);
297301
done();
298302
});
299303

304+
it('should deny access to public user if principal is not set to "*"', function itFn(done) {
305+
const newPolicy = this.test.basePolicy;
306+
newPolicy.Statement[0].Principal = { AWS: authInfo.getArn() };
307+
bucket.setBucketPolicy(newPolicy);
308+
const allowed = isBucketAuthorized(bucket, bucAction,
309+
constants.publicId, publicUserAuthInfo, log);
310+
assert.equal(allowed, false);
311+
done();
312+
});
313+
300314
authTests.forEach(t => {
301315
it(`${t.name}bucket owner`, function itFn(done) {
302316
const newPolicy = this.test.basePolicy;
@@ -376,7 +390,7 @@ describe('bucket policy authorization', () => {
376390
it('should allow access to public user if principal is set to "*"',
377391
done => {
378392
const allowed = isObjAuthorized(bucket, object, objAction,
379-
constants.publicId, null, log);
393+
constants.publicId, publicUserAuthInfo, log);
380394
assert.equal(allowed, true);
381395
done();
382396
});

0 commit comments

Comments
 (0)