Skip to content

Commit 247a45c

Browse files
authored
Merge pull request #525 from pitbulk/4.x-dev
Compatibility with PHP 8.1
2 parents 2130bac + 12fc7b8 commit 247a45c

2 files changed

Lines changed: 41 additions & 10 deletions

File tree

src/Saml2/Response.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ public function isValid($requestId = null)
269269

270270
// Check destination
271271
if ($this->document->documentElement->hasAttribute('Destination')) {
272-
$destination = trim($this->document->documentElement->getAttribute('Destination'));
272+
$destination = $this->document->documentElement->getAttribute('Destination');
273+
if (isset($destination)) {
274+
$destination = trim($destination);
275+
}
273276
if (empty($destination)) {
274277
if (!$security['relaxDestinationValidation']) {
275278
throw new ValidationError(
@@ -308,12 +311,14 @@ public function isValid($requestId = null)
308311
// Check the issuers
309312
$issuers = $this->getIssuers();
310313
foreach ($issuers as $issuer) {
311-
$trimmedIssuer = trim($issuer);
312-
if (empty($trimmedIssuer) || $trimmedIssuer !== $idPEntityId) {
313-
throw new ValidationError(
314-
"Invalid issuer in the Assertion/Response (expected '$idPEntityId', got '$trimmedIssuer')",
315-
ValidationError::WRONG_ISSUER
316-
);
314+
if (isset($issuer)) {
315+
$trimmedIssuer = trim($issuer);
316+
if (empty($trimmedIssuer) || $trimmedIssuer !== $idPEntityId) {
317+
throw new ValidationError(
318+
"Invalid issuer in the Assertion/Response (expected '$idPEntityId', got '$trimmedIssuer')",
319+
ValidationError::WRONG_ISSUER
320+
);
321+
}
317322
}
318323
}
319324

@@ -554,7 +559,10 @@ public function getAudiences()
554559

555560
$entries = $this->_queryAssertion('/saml:Conditions/saml:AudienceRestriction/saml:Audience');
556561
foreach ($entries as $entry) {
557-
$value = trim($entry->textContent);
562+
$value = $entry->textContent;
563+
if (isset($value)) {
564+
$value = trim($value);
565+
}
558566
if (!empty($value)) {
559567
$audiences[] = $value;
560568
}

src/Saml2/Utils.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ public static function treeCopyReplace(DomNode $targetNode, DomNode $sourceNode,
221221
*/
222222
public static function formatCert($cert, $heads = true)
223223
{
224+
if (is_null($cert)) {
225+
return;
226+
}
227+
224228
$x509cert = str_replace(array("\x0D", "\r", "\n"), "", $cert);
225229
if (!empty($x509cert)) {
226230
$x509cert = str_replace('-----BEGIN CERTIFICATE-----', "", $x509cert);
@@ -245,6 +249,10 @@ public static function formatCert($cert, $heads = true)
245249
*/
246250
public static function formatPrivateKey($key, $heads = true)
247251
{
252+
if (is_null($key)) {
253+
return;
254+
}
255+
248256
$key = str_replace(array("\x0D", "\r", "\n"), "", $key);
249257
if (!empty($key)) {
250258
if (strpos($key, '-----BEGIN PRIVATE KEY-----') !== false) {
@@ -319,7 +327,12 @@ public static function redirect($url, array $parameters = array(), $stay = false
319327
* Verify that the URL matches the regex for the protocol.
320328
* By default this will check for http and https
321329
*/
322-
$wrongProtocol = !preg_match(self::$_protocolRegex, $url);
330+
if (isset(self::$_protocolRegex)) {
331+
$protocol = self::$_protocolRegex;
332+
} else {
333+
$protocol = "";
334+
}
335+
$wrongProtocol = !preg_match($protocol, $url);
323336
$url = filter_var($url, FILTER_VALIDATE_URL);
324337
if ($wrongProtocol || empty($url)) {
325338
throw new Error(
@@ -773,6 +786,10 @@ public static function parseTime2SAML($time)
773786
*/
774787
public static function parseSAML2Time($time)
775788
{
789+
if (empty($time)) {
790+
return null;
791+
}
792+
776793
$matches = array();
777794

778795
/* We use a very strict regex to parse the timestamp. */
@@ -1010,7 +1027,10 @@ public static function calculateX509Fingerprint($x509cert, $alg = 'sha1')
10101027
if (strncmp($curData, '-----END CERTIFICATE', 20) == 0) {
10111028
break;
10121029
}
1013-
$data .= trim($curData);
1030+
if (isset($curData)) {
1031+
$curData = trim($curData);
1032+
}
1033+
$data .= $curData;
10141034
}
10151035
}
10161036

@@ -1043,6 +1063,9 @@ public static function calculateX509Fingerprint($x509cert, $alg = 'sha1')
10431063
*/
10441064
public static function formatFingerPrint($fingerprint)
10451065
{
1066+
if (is_null($fingerprint)) {
1067+
return;
1068+
}
10461069
$formatedFingerprint = str_replace(':', '', $fingerprint);
10471070
$formatedFingerprint = strtolower($formatedFingerprint);
10481071
return $formatedFingerprint;

0 commit comments

Comments
 (0)