diff options
author | Andreas Fischer <bantu@phpbb.com> | 2013-09-28 03:19:24 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@phpbb.com> | 2013-09-28 03:19:24 +0200 |
commit | 426994a7f87b9e07a64036235761366ad1fd1cc7 (patch) | |
tree | f75fd34bafa8699cbe4e4e5cf875dd4d5cf4b33e | |
parent | d18bded3acf8e307a5329fe3777b616bbc1d9119 (diff) | |
parent | c6aefcf555b51e7bcf00332290c9d94beddec02c (diff) | |
download | forums-426994a7f87b9e07a64036235761366ad1fd1cc7.tar forums-426994a7f87b9e07a64036235761366ad1fd1cc7.tar.gz forums-426994a7f87b9e07a64036235761366ad1fd1cc7.tar.bz2 forums-426994a7f87b9e07a64036235761366ad1fd1cc7.tar.xz forums-426994a7f87b9e07a64036235761366ad1fd1cc7.zip |
Merge branch 'ticket/11873' into prep-release-3.0.12
* ticket/11873:
[ticket/11873] Add unit test for large password input.
[ticket/11873] Do not hash very large passwords in order to safe resources.
-rw-r--r-- | phpBB/includes/functions.php | 7 | ||||
-rw-r--r-- | tests/security/hash_test.php | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index b2b12c1445..eef4ade4e7 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -502,6 +502,13 @@ function phpbb_hash($password) */ function phpbb_check_hash($password, $hash) { + if (strlen($password) > 4096) + { + // If the password is too huge, we will simply reject it + // and not let the server try to hash it. + return false; + } + $itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; if (strlen($hash) == 34) { diff --git a/tests/security/hash_test.php b/tests/security/hash_test.php index 0c2580c19b..e226365ef3 100644 --- a/tests/security/hash_test.php +++ b/tests/security/hash_test.php @@ -17,5 +17,13 @@ class phpbb_security_hash_test extends phpbb_test_case $this->assertTrue(phpbb_check_hash('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); $this->assertFalse(phpbb_check_hash('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); } + + public function test_check_hash_with_large_input() + { + // 16 MB password, should be rejected quite fast + $start_time = time(); + $this->assertFalse(phpbb_check_hash(str_repeat('a', 1024 * 1024 * 16), '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1')); + $this->assertLessThanOrEqual(5, time() - $start_time); + } } |