fix: enforce minimum digest length - #280
Merged
Merged
Conversation
The RFC 4226 dynamic truncation reads four bytes starting at an offset in [0, 15], i.e. up to the 19th byte of the digest. A shorter hash (e.g. md5, 16 bytes) makes the truncation read past the end of the digest, collapsing the generated/verified OTP to a small, secret-independent set of values. Enforce the minimum digest size required by the spec instead of accepting any hash_algos() entry: - validate against hash_hmac_algos() so non-HMAC algorithms (crc32, adler32) are rejected up front instead of crashing later in hash_hmac() - require the raw digest to be at least 19 bytes, computed dynamically so the rule holds for any current or future algorithm without per-algo magic values Both entry points are covered (direct setter and otpauth:// provisioning URI). md5 and other sub-19-byte digests are now rejected; sha1/sha256/sha512 remain. Docblocks and docs updated to drop md5 from the supported values, and the behavioural change is documented for the v11.5 upgrade.
Spomky
force-pushed
the
fix/enforce-minimum-digest-length
branch
from
June 6, 2026 23:37
f12fc76 to
7247a77
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Reject digest algorithms that cannot satisfy the RFC 4226 dynamic truncation.
The truncation reads four bytes starting at an offset taken from the low nibble of the last digest byte, i.e. an offset in
[0, 15], so it reads up to the 19th byte. A digest shorter than 19 bytes (e.g.md5, 16 bytes) makes the truncation read past the end of the hash, collapsing the generated and verified OTP to a small, secret-independent set of values.This is framed as an enforcement of the spec constraint, not a nominative blacklist: the length rule generically rejects every too-short digest (
md4,ripemd128,tiger128, …),md5being one case.Changes
OTP::getParameterMap()validates thealgorithmagainsthash_hmac_algos()(instead ofhash_algos()), which also rejects non-HMAC algorithms (crc32,adler32, …) that previously slipped through and crashed later inhash_hmac().strlen(hash($algo, '', true))— no per-algorithm magic values, robust to future PHP additions.withDigest/setDigest) and theotpauth://provisioning URI (Factory::loadFromProvisioningUri).OTPInterface::getDigest()anddoc/Customize.mdno longer presentmd5as a supported value.doc/UPGRADE_v11-v12.md(ships in v11.5.0).Compatibility
Breaking for accounts configured with a sub-19-byte digest (
md5& co.) — those were already out of spec and non-interoperable with authenticator apps. They must be re-enrolled withsha1,sha256orsha512.Tests / QA