@@ -149,20 +149,21 @@ async function _is_object_version_fit(req, predicate, value) {
149149 return res ;
150150}
151151
152- async function has_bucket_policy_permission ( policy , account , method , arn_path , req , disallow_public_access = false ) {
152+ async function has_bucket_policy_permission ( policy , account , method , arn_path , req , disallow_public_access = false ,
153+ should_pass_principal = true ) {
153154 const [ allow_statements , deny_statements ] = _ . partition ( policy . Statement , statement => statement . Effect === 'Allow' ) ;
154155
155156 // the case where the permission is an array started in op get_object_attributes
156157 const method_arr = Array . isArray ( method ) ? method : [ method ] ;
157158
158159 // look for explicit denies
159160 const res_arr_deny = await is_statement_fit_of_method_array (
160- deny_statements , account , method_arr , arn_path , req ) ; // No need to disallow in "DENY"
161+ deny_statements , account , method_arr , arn_path , req , undefined , should_pass_principal ) ; // No need to disallow in "DENY"
161162 if ( res_arr_deny . every ( item => item ) ) return 'DENY' ;
162163
163164 // look for explicit allows
164165 const res_arr_allow = await is_statement_fit_of_method_array (
165- allow_statements , account , method_arr , arn_path , req , disallow_public_access ) ;
166+ allow_statements , account , method_arr , arn_path , req , disallow_public_access , should_pass_principal ) ;
166167 if ( res_arr_allow . every ( item => item ) ) return 'ALLOW' ;
167168
168169 // implicit deny
@@ -217,15 +218,17 @@ function _is_resource_fit(arn_path, statement) {
217218 return statement . Resource ? resource_fit : ! resource_fit ;
218219}
219220
220- async function is_statement_fit_of_method_array ( statements , account , method_arr , arn_path , req , disallow_public_access = false ) {
221+ async function is_statement_fit_of_method_array ( statements , account , method_arr , arn_path , req ,
222+ disallow_public_access = false , should_pass_principal = true ) {
221223 return Promise . all ( method_arr . map ( method_permission =>
222- _is_statements_fit ( statements , account , method_permission , arn_path , req , disallow_public_access ) ) ) ;
224+ _is_statements_fit ( statements , account , method_permission , arn_path , req , disallow_public_access , should_pass_principal ) ) ) ;
223225}
224226
225- async function _is_statements_fit ( statements , account , method , arn_path , req , disallow_public_access = false ) {
227+ async function _is_statements_fit ( statements , account , method , arn_path , req , disallow_public_access = false ,
228+ should_pass_principal = true ) {
226229 for ( const statement of statements ) {
227230 const action_fit = _is_action_fit ( method , statement ) ;
228- const principal_fit = _is_principal_fit ( account , statement , disallow_public_access ) ;
231+ const principal_fit = should_pass_principal ? _is_principal_fit ( account , statement , disallow_public_access ) : true ;
229232 const resource_fit = _is_resource_fit ( arn_path , statement ) ;
230233 const condition_fit = await _is_condition_fit ( statement , req , method ) ;
231234
0 commit comments