diff --git a/lib/SimpleSAML/Utils/HTTP.php b/lib/SimpleSAML/Utils/HTTP.php
index 624e8b5056a34f868fdb38235d5137b91016a710..834901cb3c9494f44108d4385b4f43b76eb4f827 100644
--- a/lib/SimpleSAML/Utils/HTTP.php
+++ b/lib/SimpleSAML/Utils/HTTP.php
@@ -783,8 +783,8 @@ class HTTP
              */
 
             /** @var \SimpleSAML_Configuration $appcfg */
-            $appcfg = $cfg->getConfigItem('application', array());
-            $appurl = $appcfg->getString('baseURL', '');
+            $appcfg = $cfg->getConfigItem('application', null);
+            $appurl = ($appcfg instanceof \SimpleSAML_Configuration) ? $appcfg->getString('baseURL', '') : '';
             if (!empty($appurl)) {
                 $protocol = parse_url($appurl, PHP_URL_SCHEME);
                 $hostname = parse_url($appurl, PHP_URL_HOST);