Kaynağa Gözat

[ZF2014-05] Fix for null-byte binding

- Disables ability to provide a null byte in a password when binding.
Matthew Weier O'Phinney 11 yıl önce
ebeveyn
işleme
516a6f8442
2 değiştirilmiş dosya ile 14 ekleme ve 0 silme
  1. 4 0
      library/Zend/Ldap.php
  2. 10 0
      tests/Zend/Ldap/BindTest.php

+ 4 - 0
library/Zend/Ldap.php

@@ -814,6 +814,10 @@ class Zend_Ldap
     {
         $moreCreds = true;
 
+        // Security check: remove null bytes in password
+        // @see https://net.educause.edu/ir/library/pdf/csd4875.pdf
+        $password = str_replace("\0", '', $password);
+
         if ($username === null) {
             $username = $this->_getUsername();
             $password = $this->_getPassword();

+ 10 - 0
tests/Zend/Ldap/BindTest.php

@@ -260,4 +260,14 @@ class Zend_Ldap_BindTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(is_resource($ldap->getResource()));
         $this->assertEquals(TESTS_ZEND_LDAP_USERNAME, $ldap->getBoundUser());
     }
+
+    /**
+     * @see https://net.educause.edu/ir/library/pdf/csd4875.pdf
+     */
+    public function testBindWithNullPassword()
+    {
+        $ldap = new Zend_Ldap($this->_options);
+        $this->setExpectedException('Zend_Ldap_Exception', 'Invalid credentials');
+        $ldap->bind($this->_altUsername, "\0invalidpassword");
+    }
 }