Skip to content

Commit 5498cf5

Browse files
committed
bug #31407 [Security] added support for updated "distinguished name" format in x509 authentication (Robert Kopera)
This PR was submitted for the master branch but it was squashed and merged into the 3.4 branch instead (closes #31407). Discussion ---------- [Security] added support for updated "distinguished name" format in x509 authentication RFC 2253 (https://tools.ietf.org/html/rfc2253) issue: #31406 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31406 | License | MIT | Doc PR | Commits ------- bdbac2c [Security] added support for updated \"distinguished name\" format in x509 authentication
2 parents 0797ef2 + bdbac2c commit 5498cf5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Symfony/Component/Security/Http/Firewall/X509AuthenticationListener.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ protected function getPreAuthenticatedData(Request $request)
4444
$user = null;
4545
if ($request->server->has($this->userKey)) {
4646
$user = $request->server->get($this->userKey);
47-
} elseif ($request->server->has($this->credentialKey) && preg_match('#/emailAddress=(.+\@.+\..+)(/|$)#', $request->server->get($this->credentialKey), $matches)) {
47+
} elseif (
48+
$request->server->has($this->credentialKey)
49+
&& preg_match('#emailAddress=(.+\@.+\.[^,/]+)($|,|/)#', $request->server->get($this->credentialKey), $matches)
50+
) {
4851
$user = $matches[1];
4952
}
5053

src/Symfony/Component/Security/Http/Tests/Firewall/X509AuthenticationListenerTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ public static function dataProviderGetPreAuthenticatedData()
5656
/**
5757
* @dataProvider dataProviderGetPreAuthenticatedDataNoUser
5858
*/
59-
public function testGetPreAuthenticatedDataNoUser($emailAddress)
59+
public function testGetPreAuthenticatedDataNoUser($emailAddress, $credentials)
6060
{
61-
$credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress;
6261
$request = new Request([], [], [], [], [], ['SSL_CLIENT_S_DN' => $credentials]);
6362

6463
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
@@ -76,10 +75,12 @@ public function testGetPreAuthenticatedDataNoUser($emailAddress)
7675

7776
public static function dataProviderGetPreAuthenticatedDataNoUser()
7877
{
79-
return [
80-
'basicEmailAddress' => ['cert@example.com'],
81-
'emailAddressWithPlusSign' => ['cert+something@example.com'],
82-
];
78+
yield ['cert@example.com', 'CN=Sample certificate DN/emailAddress=cert@example.com'];
79+
yield ['cert+something@example.com', 'CN=Sample certificate DN/emailAddress=cert+something@example.com'];
80+
yield ['cert@example.com', 'CN=Sample certificate DN,emailAddress=cert@example.com'];
81+
yield ['cert+something@example.com', 'CN=Sample certificate DN,emailAddress=cert+something@example.com'];
82+
yield ['cert+something@example.com', 'emailAddress=cert+something@example.com,CN=Sample certificate DN'];
83+
yield ['cert+something@example.com', 'emailAddress=cert+something@example.com'];
8384
}
8485

8586
/**

0 commit comments

Comments
 (0)