diff --git a/lib/SimpleSAML/Utils/Config/Metadata.php b/lib/SimpleSAML/Utils/Config/Metadata.php
index 8232e2d3fe3860f95b6da2feca07d2510998f18c..297cae30a31f7f5a25c9845495f95ad075691a1e 100644
--- a/lib/SimpleSAML/Utils/Config/Metadata.php
+++ b/lib/SimpleSAML/Utils/Config/Metadata.php
@@ -117,7 +117,7 @@ class Metadata
 
         // check attributes is an associative array
         if (isset($contact['attributes'])) {
-            if (empty($contact['attributes']) || empty(array_filter(array_keys($contact['attributes']), 'is_string'))) {
+            if (empty($contact['attributes']) || !is_array($contact['attributes']) || empty(array_filter(array_keys($contact['attributes']), 'is_string'))) {
                 throw new \InvalidArgumentException('"attributes" must be an array and cannot be empty.');
             }
         }
diff --git a/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php b/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php
index 318983438643315529ea0459fa982227b680b80e..95f0aa547c5a0c33ff3f135684ee42ea674e9502 100644
--- a/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php
+++ b/tests/lib/SimpleSAML/Utils/Config/MetadataTest.php
@@ -215,6 +215,7 @@ class MetadataTest extends \PHPUnit_Framework_TestCase
         }
         $contact['contactType'] = 'technical';
         $contact['name'] = 'to_be_removed';
+        $contact['attributes'] = array('test' => 'testval');
         $parsed = Metadata::getContact($contact);
         foreach (array_keys($parsed) as $key) {
             $this->assertEquals($parsed[$key], $contact[$key]);