php / php/php-src

password_verify() failed to verify bcrypt passwords containing null bytes

Open
#21,673 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: standard Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
$hash = password_hash("secret", PASSWORD_BCRYPT);
var_dump(password_verify("secret", $hash));
var_dump(password_verify("secret" . chr(0) . "suffix", $hash));
?>

Resulted in this output:

bool(true)
bool(true)

But I expected this output instead:

bool(true)
bool(false)
PHP Version
all supported version
Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with password_hash(), password_verify(), PASSWORD_BCRYPT, and a null byte, then trace the PHP implementation and existing password verification tests. Done means a password with a null-byte suffix no longer verifies against the original bcrypt hash, while the unchanged password still verifies.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
authentication, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.