@@ -677,17 +677,23 @@ function _validate_json_policy_document(input_policy_document) {
677677
678678/**
679679 * The function will validate the policy document basic structure
680- * (currently - only that we don't have Principal NotPrincipal)
680+ * (currently - only that we don't have Principal NotPrincipal in every Statement )
681681 * @param {object } policy_document
682682 */
683683
684684 function _validate_policy_document_iam_structure ( policy_document ) {
685+ // as we check this before the schema check - here we ensure that we have the Statement as array and it is iterable
686+ if ( ! policy_document . Statement || ! Array . isArray ( policy_document . Statement ) ) {
687+ const { code, http_code, type } = IamError . MalformedPolicyDocument ;
688+ const message_with_details = 'Syntax errors in policy.' ;
689+ throw new IamError ( { code, message : message_with_details , http_code, type } ) ;
690+ }
685691 for ( const statement of policy_document . Statement ) {
686692 const statement_principal = statement . Principal || statement . NotPrincipal ;
687693 if ( statement_principal ) {
688- const { code, http_code, type } = IamError . MalformedPolicyDocument ;
689- const message_with_details = 'Policy document should not specify a principal.' ;
690- throw new IamError ( { code, message : message_with_details , http_code, type } ) ;
694+ const { code, http_code, type } = IamError . MalformedPolicyDocument ;
695+ const message_with_details = 'Policy document should not specify a principal.' ;
696+ throw new IamError ( { code, message : message_with_details , http_code, type } ) ;
691697 }
692698 }
693699 }
0 commit comments