Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/api/apiUtils/authorization/permissionChecks.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ function _checkPrincipal(requester, principal) {
if (principal === '*') {
return true;
}
// User in unauthenticated (anonymous request)
if (requester === undefined) {
return false;
}
if (principal === requester) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "s3",
"version": "7.70.51-5",
"version": "7.70.51-6",
"description": "S3 connector",
"main": "index.js",
"engines": {
Expand Down
18 changes: 16 additions & 2 deletions tests/unit/api/bucketPolicyAuth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert');
const { BucketInfo, BucketPolicy } = require('arsenal').models;
const AuthInfo = require('arsenal').auth.AuthInfo;
const constants = require('../../../constants');
const { isBucketAuthorized, isObjAuthorized, validatePolicyResource }
= require('../../../lib/api/apiUtils/authorization/permissionChecks');
Expand Down Expand Up @@ -35,6 +36,9 @@ const basePolicyObj = {
};
const bucketName = 'matchme';
const log = new DummyRequestLogger();
const publicUserAuthInfo = new AuthInfo({
canonicalID: constants.publicId,
});

const authTests = [
{
Expand Down Expand Up @@ -292,11 +296,21 @@ describe('bucket policy authorization', () => {
it('should allow access to public user if principal is set to "*"',
done => {
const allowed = isBucketAuthorized(bucket, bucAction,
constants.publicId, null, log);
constants.publicId, publicUserAuthInfo, log);
assert.equal(allowed, true);
done();
});

it('should deny access to public user if principal is not set to "*"', function itFn(done) {
const newPolicy = this.test.basePolicy;
newPolicy.Statement[0].Principal = { AWS: authInfo.getArn() };
bucket.setBucketPolicy(newPolicy);
const allowed = isBucketAuthorized(bucket, bucAction,
constants.publicId, publicUserAuthInfo, log);
assert.equal(allowed, false);
done();
});

authTests.forEach(t => {
it(`${t.name}bucket owner`, function itFn(done) {
const newPolicy = this.test.basePolicy;
Expand Down Expand Up @@ -376,7 +390,7 @@ describe('bucket policy authorization', () => {
it('should allow access to public user if principal is set to "*"',
done => {
const allowed = isObjAuthorized(bucket, object, objAction,
constants.publicId, null, log);
constants.publicId, publicUserAuthInfo, log);
assert.equal(allowed, true);
done();
});
Expand Down
Loading