Skip to content
This repository was archived by the owner on May 31, 2024. It is now read-only.

Commit 41bd59c

Browse files
csarrazifabpot
authored andcommitted
Fixed issue with blank password with Ldap
The bind operation of LDAP, as described in RFC 4513, provides a method which allows for authentication of users. For the Simple Authentication Method a user may use the anonymous authentication mechanism, the unauthenticated authentication mechanism, or the name/password authentication mechanism. The unauthenticated authentication mechanism is used when a client who desires to establish an anonymous authorization state passes a non-zero length distinguished name and a zero length password. Most LDAP servers either can be configured to allow this mechanism or allow it by default. _Web-based applications which perform the simple bind operation with the client's credentials are at risk when an anonymous authorization state is established. This can occur when the web-based application passes a distinguished name and a zero length password to the LDAP server._ Thus, misconfiguring a server with simple bind can trick Symfony into thinking the username/password tuple as valid, potentially leading to unauthorized access.
1 parent 069e08a commit 41bd59c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Core/Authentication/Provider/LdapBindAuthenticationProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ protected function checkAuthentication(UserInterface $user, UsernamePasswordToke
7373
$username = $token->getUsername();
7474
$password = $token->getCredentials();
7575

76+
if ('' === $password) {
77+
throw new BadCredentialsException('The presented password must not be empty.');
78+
}
79+
7680
try {
7781
$username = $this->ldap->escape($username, '', LDAP_ESCAPE_DN);
7882
$dn = str_replace('{username}', $username, $this->dnString);

Core/Tests/Authentication/Provider/LdapBindAuthenticationProviderTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@
2121
*/
2222
class LdapBindAuthenticationProviderTest extends \PHPUnit_Framework_TestCase
2323
{
24+
/**
25+
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
26+
* @expectedExceptionMessage The presented password must not be empty.
27+
*/
28+
public function testEmptyPasswordShouldThrowAnException()
29+
{
30+
$userProvider = $this->getMock('Symfony\Component\Security\Core\User\UserProviderInterface');
31+
$ldap = $this->getMock('Symfony\Component\Ldap\LdapClientInterface');
32+
$userChecker = $this->getMock('Symfony\Component\Security\Core\User\UserCheckerInterface');
33+
34+
$provider = new LdapBindAuthenticationProvider($userProvider, $userChecker, 'key', $ldap);
35+
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
36+
$reflection->setAccessible(true);
37+
38+
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', '', 'key'));
39+
}
40+
2441
/**
2542
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
2643
* @expectedExceptionMessage The presented password is invalid.
@@ -40,7 +57,7 @@ public function testBindFailureShouldThrowAnException()
4057
$reflection = new \ReflectionMethod($provider, 'checkAuthentication');
4158
$reflection->setAccessible(true);
4259

43-
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', '', 'key'));
60+
$reflection->invoke($provider, new User('foo', null), new UsernamePasswordToken('foo', 'bar', 'key'));
4461
}
4562

4663
public function testRetrieveUser()

0 commit comments

Comments
 (0)