Skip to content

Commit

Permalink
Merge pull request #588 from SAML-Toolkits/no_value_nameid
Browse files Browse the repository at this point in the history
Allow empty NameID value when no strict or wantNameId is false
  • Loading branch information
pitbulk authored May 13, 2024
2 parents d040880 + 385219f commit d3884fb
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Saml2/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,16 +631,16 @@ public function getNameIdData()

$nameIdData = array();

$security = $this->_settings->getSecurityData();
if (!isset($nameId)) {
$security = $this->_settings->getSecurityData();
if ($security['wantNameId']) {
throw new ValidationError(
"NameID not found in the assertion of the Response",
ValidationError::NO_NAMEID
);
}
} else {
if ($this->_settings->isStrict() && empty($nameId->nodeValue)) {
if ($this->_settings->isStrict() && $security['wantNameId'] && empty($nameId->nodeValue)) {
throw new ValidationError(
"An empty NameID value found",
ValidationError::EMPTY_NAMEID
Expand Down
1 change: 1 addition & 0 deletions tests/data/responses/invalids/no_value_nameid.xml.base64
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PD94bWwgdmVyc2lvbj0iMS4wIj8+DQo8c2FtbHA6UmVzcG9uc2UgeG1sbnM6c2FtbHA9InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDpwcm90b2NvbCIgeG1sbnM6c2FtbD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmFzc2VydGlvbiIgSUQ9InBmeGQxODhjZWE0LWUyOWEtYTAwOC01ZmUxLTAwN2Q2MmJhN2E5NyIgVmVyc2lvbj0iMi4wIiBJc3N1ZUluc3RhbnQ9IjIwMTQtMDItMTlUMDE6Mzc6MDFaIiBEZXN0aW5hdGlvbj0iaHR0cHM6Ly9waXRidWxrLm5vLWlwLm9yZy9uZXdvbmVsb2dpbi9kZW1vMS9pbmRleC5waHA/YWNzIiBJblJlc3BvbnNlVG89Ik9ORUxPR0lOXzVmZTlkNmU0OTliMmYwOTEzMjA2YWFiM2Y3MTkxN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pzdHJpbmciPlNpeHRvMzwvc2FtbDpBdHRyaWJ1dGVWYWx1ZT48L3NhbWw6QXR0cmlidXRlPjxzYW1sOkF0dHJpYnV0ZSBOYW1lPSJzbiIgTmFtZUZvcm1hdD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmF0dHJuYW1lLWZvcm1hdDpiYXNpYyI+PHNhbWw6QXR0cmlidXRlVmFsdWUgeHNpOnR5cGU9InhzOnN0cmluZyI+TWFydGluMjwvc2FtbDpBdHRyaWJ1dGVWYWx1ZT48L3NhbWw6QXR0cmlidXRlPjxzYW1sOkF0dHJpYnV0ZSBOYW1lPSJlZHVQZXJzb25BZmZpbGlhdGlvbiIgTmFtZUZvcm1hdD0idXJuOm9hc2lzOm5hbWVzOnRjOlNBTUw6Mi4wOmF0dHJuYW1lLWZvcm1hdDpiYXNpYyI+PHNhbWw6QXR0cmlidXRlVmFsdWUgeHNpOnR5cGU9InhzOnN0cmluZyI+dXNlcjwvc2FtbDpBdHRyaWJ1dGVWYWx1ZT48c2FtbDpBdHRyaWJ1dGVWYWx1ZSB4c2k6dHlwZT0ieHM6c3RyaW5nIj5hZG1pbjwvc2FtbDpBdHRyaWJ1dGVWYWx1ZT48L3NhbWw6QXR0cmlidXRlPjwvc2FtbDpBdHRyaWJ1dGVTdGF0ZW1lbnQ+PC9zYW1sOkFzc2VydGlvbj48L3NhbWxwOlJlc3BvbnNlPg==
67 changes: 66 additions & 1 deletion tests/src/OneLogin/Saml2/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,71 @@ public function testGetNameIdData()
} catch (ValidationError $e) {
$this->assertStringContainsString('An empty NameID value found', $e->getMessage());
}

$xml7 = file_get_contents(TEST_ROOT . '/data/responses/invalids/no_value_nameid.xml.base64');
$response11 = new Response($this->_settings, $xml7);
$nameIdData12 = $response11->getNameIdData();
$expectedNameIdData10 = array(
'Value' => "",
'Format' => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
);
$this->assertEquals($expectedNameIdData10, $nameIdData12);

$settingsDir = TEST_ROOT .'/settings/';
include $settingsDir.'settings1.php';

$settingsInfo['strict'] = true;
$settingsInfo['security']['wantNameId'] = true;

$settings = new Settings($settingsInfo);
$response12 = new Response($settings, $xml7);

try {
$nameIdData13 = $response12->getNameIdData();
$this->fail('ValidationError was not raised');
} catch (ValidationError $e) {
$this->assertStringContainsString('An empty NameID value found', $e->getMessage());
}

$settingsInfo['security']['wantNameId'] = false;

$settings = new Settings($settingsInfo);
$response13 = new Response($settings, $xml7);

$nameIdData14 = $response13->getNameIdData();

$expectedNameIdData11 = array(
'Value' => "",
'Format' => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
);
$this->assertEquals($expectedNameIdData11, $nameIdData14);

$settingsInfo['strict'] = false;
$settingsInfo['security']['wantNameId'] = true;

$settings = new Settings($settingsInfo);
$response14 = new Response($settings, $xml7);

$nameIdData15 = $response14->getNameIdData();

$expectedNameIdData12 = array(
'Value' => "",
'Format' => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
);
$this->assertEquals($expectedNameIdData12, $nameIdData15);

$settingsInfo['security']['wantNameId'] = false;

$settings = new Settings($settingsInfo);
$response15 = new Response($settings, $xml7);

$nameIdData16 = $response15->getNameIdData();

$expectedNameIdData13 = array(
'Value' => "",
'Format' => "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
);
$this->assertEquals($expectedNameIdData13, $nameIdData16);
}

/**
Expand Down Expand Up @@ -643,7 +708,7 @@ public function testGetAttributes()
}

/**
* Tests the getAttributesWithFriendlyName method of the OneLogin_Saml2_Response
* Tests the getAttributesWithFriendlyName method of the Response
*
* @covers OneLogin\Saml2\Response::getAttributesWithFriendlyName
*/
Expand Down

0 comments on commit d3884fb

Please sign in to comment.