Skip to content

Commit 9545abd

Browse files
committed
Bugfix: enable strict mode for base64_decode
1 parent 1b5d487 commit 9545abd

5 files changed

Lines changed: 8 additions & 4 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
/cache.properties
33
/composer.lock
44
/composer.phar
5+
/.phpunit.cache/
56
/vendor/
67
.phpunit.result.cache

src/SAML2/HTTPArtifact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function send(Message $message) : void
100100
public function receive(): Message
101101
{
102102
if (array_key_exists('SAMLart', $_REQUEST)) {
103-
$artifact = base64_decode($_REQUEST['SAMLart']);
103+
$artifact = base64_decode($_REQUEST['SAMLart'], true);
104104
$endpointIndex = bin2hex(substr($artifact, 2, 2));
105105
$sourceId = bin2hex(substr($artifact, 4, 20));
106106
} else {

src/SAML2/HTTPPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function receive(): Message
7575
throw new \Exception('Missing SAMLRequest or SAMLResponse parameter.');
7676
}
7777

78-
$msgStr = base64_decode($msgStr);
78+
$msgStr = base64_decode($msgStr, true);
7979

8080
$xml = new \DOMDocument();
8181
$xml->loadXML($msgStr);

src/SAML2/HTTPRedirect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function receive(): Message
116116
throw new \Exception('Unknown SAMLEncoding: '.var_export($data['SAMLEncoding'], true));
117117
}
118118

119-
$message = base64_decode($message);
119+
$message = base64_decode($message, true);
120120
if ($message === false) {
121121
throw new \Exception('Error while base64 decoding SAML message.');
122122
}

tests/SAML2/HTTPRedirectTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SAML2;
66

7+
use Exception;
78
use PHPUnit\Framework\Error\Warning;
89
use SAML2\DOMDocumentFactory;
910
use SAML2\HTTPRedirect;
@@ -165,7 +166,9 @@ public function testInvalidRequestData() : void
165166
$qs = 'SAMLRequest=cannotinflate';
166167
$_SERVER['QUERY_STRING'] = $qs;
167168

168-
$this->expectException(\Exception::class, 'Error while inflating');
169+
$this->expectException(Exception::class);
170+
$this->expectExceptionMessage('Error while base64 decoding SAML message.');
171+
169172
$hr = new HTTPRedirect();
170173
$request = @$hr->receive();
171174
}

0 commit comments

Comments
 (0)