Skip to content

Commit

Permalink
Bugfix: enable strict mode for base64_decode
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Apr 24, 2024
1 parent 1b5d487 commit 42f95f4
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/SAML2/HTTPArtifact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/SAML2/HTTPPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/SAML2/HTTPRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
}
Expand Down
4 changes: 3 additions & 1 deletion tests/SAML2/HTTPRedirectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,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();
}
Expand Down

0 comments on commit 42f95f4

Please sign in to comment.