@@ -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,19 @@ 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 , region : DEFAULTREGION } ?? await utils . getBucket ( bucketId ) ;
615+ console . log ( '--- getPublic' , bucketData . bucketId ) ;
616+ const resource = bucketData . bucket + '/' + path ;
617+ const hasPublicPolicy = await this . hasEffectivePublicPolicy ( resource , bucketData ) ;
616618 // 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 ;
619+ const hasPublicAcl = bucketData . key !== resource ? await this . hasPublicAcl ( bucketData , path ) : false ;
618620 // Check for COMS Bucket Policy for this resource
619621 return hasPublicAcl || hasPublicPolicy ;
620622 } ,
@@ -623,11 +625,12 @@ const objectStorageService = {
623625 * @function hasEffectivePublicPolicy
624626 * check for a Bucket Policy that will make the given resource public
625627 * @param {* } resource
626- * @param {* } data
628+ * @param {* } bucketData
627629 */
628- async hasEffectivePublicPolicy ( resource , data ) {
630+ async hasEffectivePublicPolicy ( resource , bucketData ) {
629631 try {
630- const existingPolicy = await this . _getS3Client ( data ) . send ( new GetBucketPolicyCommand ( { Bucket : data . bucket } ) ) ;
632+ const existingPolicy = await this . _getS3Client ( bucketData )
633+ . send ( new GetBucketPolicyCommand ( { Bucket : bucketData . bucket } ) ) ;
631634 const statement = JSON . parse ( existingPolicy . Policy ) . Statement ;
632635 // A Deny policy on resource or above, which override Allow policies will set public status to false
633636 const denyPolicies = statement
@@ -651,7 +654,7 @@ const objectStorageService = {
651654 return ( allowPolicies . length > 0 ) ? true : false ;
652655 }
653656 } catch ( e ) {
654- log . debug ( 'No existing effective policies found' , { function : 'getPublic ' } ) ;
657+ log . debug ( 'No existing effective policies found' , { function : 'hasEffectivePublicPolicy ' } ) ;
655658 return false ;
656659 }
657660 } ,
0 commit comments