diff --git a/.gitignore b/.gitignore index da172fa15..b37ebbb1d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ /cache.properties /composer.lock /composer.phar +/.phpunit.cache/ /vendor/ .phpunit.result.cache diff --git a/src/SAML2/HTTPArtifact.php b/src/SAML2/HTTPArtifact.php index ba27fbf32..812f29ae6 100644 --- a/src/SAML2/HTTPArtifact.php +++ b/src/SAML2/HTTPArtifact.php @@ -100,7 +100,7 @@ public function send(Message $message) : void public function receive(): Message { if (array_key_exists('SAMLart', $_REQUEST)) { - $artifact = base64_decode($_REQUEST['SAMLart']); + $artifact = base64_decode($_REQUEST['SAMLart'], true); $endpointIndex = bin2hex(substr($artifact, 2, 2)); $sourceId = bin2hex(substr($artifact, 4, 20)); } else { diff --git a/src/SAML2/HTTPPost.php b/src/SAML2/HTTPPost.php index 88639dd3b..6aac058cb 100644 --- a/src/SAML2/HTTPPost.php +++ b/src/SAML2/HTTPPost.php @@ -75,7 +75,7 @@ public function receive(): Message throw new \Exception('Missing SAMLRequest or SAMLResponse parameter.'); } - $msgStr = base64_decode($msgStr); + $msgStr = base64_decode($msgStr, true); $xml = new \DOMDocument(); $xml->loadXML($msgStr); diff --git a/src/SAML2/HTTPRedirect.php b/src/SAML2/HTTPRedirect.php index 8a387bc42..ebd67933c 100644 --- a/src/SAML2/HTTPRedirect.php +++ b/src/SAML2/HTTPRedirect.php @@ -116,7 +116,7 @@ public function receive(): Message throw new \Exception('Unknown SAMLEncoding: '.var_export($data['SAMLEncoding'], true)); } - $message = base64_decode($message); + $message = base64_decode($message, true); if ($message === false) { throw new \Exception('Error while base64 decoding SAML message.'); } diff --git a/tests/SAML2/HTTPRedirectTest.php b/tests/SAML2/HTTPRedirectTest.php index 03d30f2ee..e02083cf4 100644 --- a/tests/SAML2/HTTPRedirectTest.php +++ b/tests/SAML2/HTTPRedirectTest.php @@ -4,6 +4,7 @@ namespace SAML2; +use Exception; use PHPUnit\Framework\Error\Warning; use SAML2\DOMDocumentFactory; use SAML2\HTTPRedirect; @@ -165,7 +166,9 @@ public function testInvalidRequestData() : void $qs = 'SAMLRequest=cannotinflate'; $_SERVER['QUERY_STRING'] = $qs; - $this->expectException(\Exception::class, 'Error while inflating'); + $this->expectException(Exception::class); + $this->expectExceptionMessage('Error while base64 decoding SAML message.'); + $hr = new HTTPRedirect(); $request = @$hr->receive(); }