diff --git a/modules/authorize/templates/authorize_403.php b/modules/authorize/templates/authorize_403.php
index 9b02c1444ac47e6a6511dae2f13d536270ccd125..6d63c2763eb5a664fa5b8db0fd95556f4aaaa0bc 100644
--- a/modules/authorize/templates/authorize_403.php
+++ b/modules/authorize/templates/authorize_403.php
@@ -10,7 +10,6 @@
  * @version $Id$
  */
 
-global $state;
 
 $this->data['403_header'] = $this->t('{authorize:Authorize:403_header}');
 $this->data['403_text'] = $this->t('{authorize:Authorize:403_text}');
@@ -19,7 +18,13 @@ $this->includeAtTemplateBase('includes/header.php');
 ?>
 <h1><?php echo $this->data['403_header']; ?></h1>
 <p><?php echo $this->data['403_text']; ?></p>
-<p><a href="<?php echo SimpleSAML_Module::getModuleURL('core/authenticate.php', array('as' => $state['Source']['auth']))."&logout"; ?>"><?php echo $this->t('{status:logout}'); ?></a></p>
+<?php
+if (isset($this->data['LogoutURL'])) {
+?>
+<p><a href="<?php echo htmlspecialchars($this->data['LogoutURL']); ?>"><?php echo $this->t('{status:logout}'); ?></a></p>
+<?php
+}
+?>
 <?php
 $this->includeAtTemplateBase('includes/footer.php');
 ?>
diff --git a/modules/authorize/www/authorize_403.php b/modules/authorize/www/authorize_403.php
index 60e0d9b7c1427f785b25e9c401f6933adbd8f65c..54d702fb0c21d88bd4f9aae8ef9c8567e1054261 100644
--- a/modules/authorize/www/authorize_403.php
+++ b/modules/authorize/www/authorize_403.php
@@ -15,6 +15,9 @@ $state = SimpleSAML_Auth_State::loadState($id, 'authorize:Authorize');
 
 $globalConfig = SimpleSAML_Configuration::getInstance();
 $t = new SimpleSAML_XHTML_Template($globalConfig, 'authorize:authorize_403.php');
+if (isset($state['Source']['auth'])) {
+    $t->data['LogoutURL'] = SimpleSAML_Module::getModuleURL('core/authenticate.php', array('as' => $state['Source']['auth']))."&logout";
+}
 header('HTTP/1.0 403 Forbidden');
 $t->show();