@@ -24,7 +24,7 @@ const { Upload } = require('@aws-sdk/lib-storage');
2424const { getSignedUrl } = require ( '@aws-sdk/s3-request-presigner' ) ;
2525const config = require ( 'config' ) ;
2626
27- const { ALLUSERS , MetadataDirective, TaggingDirective } = require ( '../components/constants' ) ;
27+ const { ALLUSERS , DEFAULTREGION , MetadataDirective, TaggingDirective } = require ( '../components/constants' ) ;
2828const log = require ( '../components/log' ) ( module . filename ) ;
2929const utils = require ( '../components/utils' ) ;
3030
@@ -582,7 +582,7 @@ const objectStorageService = {
582582 const resourceKey = isPrefix ? resource + '*' : resource ; // prefixes/need/trailing/wildcard/*
583583 newPolicies
584584 . push ( {
585- Action : 's3:GetObject' ,
585+ Action : [ 's3:GetObject' , 's3:GetObjectVersion' ] ,
586586 Resource : resourceKey ,
587587 Effect : 'Allow' ,
588588 Principal : '*' ,
@@ -604,17 +604,18 @@ const objectStorageService = {
604604
605605 /**
606606 * @function getPublic
607- * checks for a Bucket Policy or ACL that will make the given resource public
608- * @param {string } path the path of the resource
609- * @param {string } bucketId of COMS bucket for the resource
610- * @returns {Promise<boolean> } whether the given resource is public
607+ * Checks for a Bucket Policy or ACL that will make the given resource public
608+ * @param {string } options.path The path of the resource to check
609+ * @param {string } [options.bucketId] Optional bucketId to retrieve bucket configuration
610+ * @param {object } [options.bucket] Optional bucket object containing bucketId (alternative to bucketId)
611+ * @returns {Promise<boolean> } True if the resource is public via policy or ACL, false otherwise
611612 */
612- async getPublic ( { path, bucketId } ) {
613- const data = await utils . getBucket ( bucketId ) ;
614- const resource = data . bucket + '/' + path ;
615- const hasPublicPolicy = await this . hasEffectivePublicPolicy ( resource , data ) ;
613+ async getPublic ( { path, bucketId = undefined , bucket = undefined } ) {
614+ const bucketData = bucket ? { ... bucket , region : DEFAULTREGION } : await utils . getBucket ( bucketId ) ;
615+ const resource = bucketData . bucket + '/' + path ;
616+ const hasPublicPolicy = await this . hasEffectivePublicPolicy ( resource , bucketData ) ;
616617 // if resource is an object, check for public ACL's (ACL's cannot apply to prefixes)
617- const hasPublicAcl = data . key !== resource ? await this . hasPublicAcl ( data , path ) : false ;
618+ const hasPublicAcl = bucketData . key !== resource ? await this . hasPublicAcl ( bucketData , path ) : false ;
618619 // Check for COMS Bucket Policy for this resource
619620 return hasPublicAcl || hasPublicPolicy ;
620621 } ,
@@ -623,11 +624,12 @@ const objectStorageService = {
623624 * @function hasEffectivePublicPolicy
624625 * check for a Bucket Policy that will make the given resource public
625626 * @param {* } resource
626- * @param {* } data
627+ * @param {* } bucketData
627628 */
628- async hasEffectivePublicPolicy ( resource , data ) {
629+ async hasEffectivePublicPolicy ( resource , bucketData ) {
629630 try {
630- const existingPolicy = await this . _getS3Client ( data ) . send ( new GetBucketPolicyCommand ( { Bucket : data . bucket } ) ) ;
631+ const existingPolicy = await this . _getS3Client ( bucketData )
632+ . send ( new GetBucketPolicyCommand ( { Bucket : bucketData . bucket } ) ) ;
631633 const statement = JSON . parse ( existingPolicy . Policy ) . Statement ;
632634 // A Deny policy on resource or above, which override Allow policies will set public status to false
633635 const denyPolicies = statement
@@ -651,7 +653,7 @@ const objectStorageService = {
651653 return ( allowPolicies . length > 0 ) ? true : false ;
652654 }
653655 } catch ( e ) {
654- log . debug ( 'No existing effective policies found' , { function : 'getPublic ' } ) ;
656+ log . debug ( 'No existing effective policies found' , { function : 'hasEffectivePublicPolicy ' } ) ;
655657 return false ;
656658 }
657659 } ,
0 commit comments