Skip to content

Commit 370a5d9

Browse files
committed
allowRepeatAttributeName settings added in order to support AttributeStatements with Attribute elements with the same name
1 parent c12a61a commit 370a5d9

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ $advancedSettings = array (
520520
// attribute will not be rejected for this fact.
521521
'relaxDestinationValidation' => false,
522522

523+
// If true, the toolkit will not raised an error when the Statement Element
524+
// contain atribute elements with name duplicated
525+
'allowRepeatAttributeName' => false,
526+
523527
// If true, Destination URL should strictly match to the address to
524528
// which the response has been sent.
525529
// Notice that if 'relaxDestinationValidation' is true an empty Destintation

advanced_settings_example.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@
8585
// attribute will not be rejected for this fact.
8686
'relaxDestinationValidation' => false,
8787

88+
// If true, the toolkit will not raised an error when the Statement Element
89+
// contain atribute elements with name duplicated
90+
'allowRepeatAttributeName' => false,
91+
8892
// If true, Destination URL should strictly match to the address to
8993
// which the response has been sent.
9094
// Notice that if 'relaxDestinationValidation' is true an empty Destintation

lib/Saml2/Response.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ private function _getAttributesByKeyName($keyName = "Name")
779779

780780
$entries = $this->_queryAssertion('/saml:AttributeStatement/saml:Attribute');
781781

782+
$security = $this->_settings->getSecurityData();
783+
$allowRepeatAttributeName = $security['allowRepeatAttributeName'];
784+
782785
/** @var $entry DOMNode */
783786
foreach ($entries as $entry) {
784787
$attributeKeyNode = $entry->attributes->getNamedItem($keyName);
@@ -790,10 +793,12 @@ private function _getAttributesByKeyName($keyName = "Name")
790793
$attributeKeyName = $attributeKeyNode->nodeValue;
791794

792795
if (in_array($attributeKeyName, array_keys($attributes))) {
793-
throw new OneLogin_Saml2_ValidationError(
794-
"Found an Attribute element with duplicated ".$keyName,
795-
OneLogin_Saml2_ValidationError::DUPLICATED_ATTRIBUTE_NAME_FOUND
796-
);
796+
if (!$allowRepeatAttributeName) {
797+
throw new OneLogin_Saml2_ValidationError(
798+
"Found an Attribute element with duplicated ".$keyName,
799+
OneLogin_Saml2_ValidationError::DUPLICATED_ATTRIBUTE_NAME_FOUND
800+
);
801+
}
797802
}
798803

799804
$attributeValues = array();
@@ -804,7 +809,11 @@ private function _getAttributesByKeyName($keyName = "Name")
804809
}
805810
}
806811

807-
$attributes[$attributeKeyName] = $attributeValues;
812+
if (in_array($attributeKeyName, array_keys($attributes))) {
813+
$attributes[$attributeKeyName] = array_merge($attributes[$attributeKeyName], $attributeValues);
814+
} else {
815+
$attributes[$attributeKeyName] = $attributeValues;
816+
}
808817
}
809818
return $attributes;
810819
}

lib/Saml2/Settings.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ private function _addDefaultValues()
399399
$this->_security['relaxDestinationValidation'] = false;
400400
}
401401

402+
// Allow duplicated Attribute Names
403+
if (!isset($this->_security['allowRepeatAttributeName'])) {
404+
$this->_security['allowRepeatAttributeName'] = false;
405+
}
402406

403407
// Strict Destination match validation
404408
if (!isset($this->_security['destinationStrictlyMatches'])) {

tests/src/OneLogin/Saml2/ResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,14 @@ public function testGetAttributes()
622622
} catch (OneLogin_Saml2_ValidationError $e) {
623623
$this->assertContains('Found an Attribute element with duplicated Name', $e->getMessage());
624624
}
625+
626+
$settingsDir = TEST_ROOT .'/settings/';
627+
include $settingsDir.'settings1.php';
628+
$settingsInfo['security']['allowRepeatAttributeName'] = true;
629+
$settings2 = new OneLogin_Saml2_Settings($settingsInfo);
630+
$response5 = new OneLogin_Saml2_Response($settings2, $xml4);
631+
$attrs = $response5->getAttributes();
632+
$this->assertEquals([0 => "test", 1 => "test2"], $attrs['uid']);
625633
}
626634

627635
/**

0 commit comments

Comments
 (0)