Skip to content

Add hashAlgo option to GravatarHelper for legacy MD5 hashing#336

Merged
dereuromark merged 1 commit into
masterfrom
gravatar-hash-algo
Jun 8, 2026
Merged

Add hashAlgo option to GravatarHelper for legacy MD5 hashing#336
dereuromark merged 1 commit into
masterfrom
gravatar-hash-algo

Conversation

@dereuromark

Copy link
Copy Markdown
Owner

Background

Gravatar switched the avatar email hash from MD5 to SHA-256 in 2024. GravatarHelper follows SHA-256, which is correct for accounts with a real Gravatar image (legacy MD5 mappings still resolve). But for accounts without a Gravatar image, the generated default avatar (identicon, monsterid, retro, ...) is derived from the hash itself - so switching the algorithm silently changes everyone's default avatar.

Change

Add a hashAlgo option so callers can opt back into the legacy identifier:

  • hashAlgo config key, default sha256 (no behavior change by default)
  • md5 supported for pre-2024 accounts that want their familiar default avatar back
  • unknown values fall back to sha256 instead of producing a broken hash
  • the option is stripped before building the URL query string and before rendering img attributes, so it never leaks into output
// legacy account - restore the pre-2024 default avatar
$this->Gravatar->image($email, ['hashAlgo' => 'md5']);

Tests

Added testHashAlgoMd5, testHashAlgoFallsBackToSha256, and testHashAlgoNotLeakedIntoOutput. Full GravatarHelper suite green; phpstan and phpcs clean.

Gravatar switched the avatar email hash from MD5 to SHA-256 in 2024. The
helper follows SHA-256 by default, but that changes the generated default
avatar (identicon, monsterid, etc.) for every account that has no real
Gravatar image, since the picture is derived from the hash.

Add a hashAlgo option (sha256 default, md5 supported) so callers can keep
the legacy identifier for pre-2024 accounts. Unknown values fall back to
sha256, and the option is stripped before building the URL query and the
img attributes.
@dereuromark dereuromark merged commit 7e7158c into master Jun 8, 2026
16 checks passed
@dereuromark dereuromark deleted the gravatar-hash-algo branch June 8, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant