From c2de3dc16d7b605845fa8aa7e2a812a35a325d0a Mon Sep 17 00:00:00 2001
From: Mischa Salle <msalle@nikhef.nl>
Date: Wed, 10 Jun 2020 19:10:50 +0200
Subject: [PATCH] Check explicitly whether array element is defined

Check whether http://macedir.org/entity-category is set in the EntityAttributes
before using it as argument in in_array(). This prevents a "TypeError:
in_array() expects parameter 2 to be array, null given" error.

This situation happens when we do have EntityAttributes in the metadata but
none of type "http://macedir.org/entity-category". An example is an IdP
supporting https://refeds.org/category/research-and-scholarship, which would
have "http://macedir.org/entity-category-support" but not per se also
"http://macedir.org/entity-category".
---
 lib/SimpleSAML/Utils/Config/Metadata.php | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/SimpleSAML/Utils/Config/Metadata.php b/lib/SimpleSAML/Utils/Config/Metadata.php
index c591ed1be..8bfc5471e 100644
--- a/lib/SimpleSAML/Utils/Config/Metadata.php
+++ b/lib/SimpleSAML/Utils/Config/Metadata.php
@@ -298,10 +298,10 @@ class Metadata
      */
     public static function isHiddenFromDiscovery(array $metadata): bool
     {
-        Logger::maskErrors(E_ALL);
-        $hidden = in_array(self::$HIDE_FROM_DISCOVERY, $metadata['EntityAttributes'][self::$ENTITY_CATEGORY], true);
-        Logger::popErrorMask();
-        return $hidden === true;
+        if (!isset($metadata['EntityAttributes'][self::$ENTITY_CATEGORY])) {
+            return false;
+        }
+        return in_array(self::$HIDE_FROM_DISCOVERY, $metadata['EntityAttributes'][self::$ENTITY_CATEGORY], true);
     }
 
 
-- 
GitLab