Skip to main content
Menu
Advisories

A PEM public key after an OpenSSL preamble is used as an HMAC secret

GHSA-PWM3-WVJF-P5RJPublished Updated GitHub

Description

Impact

A verification key given without an explicit algorithm defaults to HS256 unless it is PEM-encoded, and a PEM key paired with an HMAC algorithm is refused. Both checks only looked for -----BEGIN at the start of the key. OpenSSL writes a preamble before the PEM block when exporting from PKCS#12 (Bag Attributes, subject=, issuer= lines), so such a public key or certificate was taken for a raw shared secret: the hub verified HS256 tokens using the public key text as the HMAC secret.

Anyone holding the public key, which is public by design, can then mint tokens the hub accepts, with attacker-chosen grants: publish and subscribe on every topic, private updates included.

The issue reveals itself: the issuer's real RS256 or ES256 tokens stop verifying as soon as the key is deployed, which limits how long a deployment stays in this state unnoticed.

Affected deployments. Hubs configured with a PEM public key or certificate that carries a preamble and no explicit algorithm (alg in the verifier block), and Go library users passing such a key to mercure.Static with an HS* algorithm.

Patches

A key containing a PEM block anywhere is treated as PEM: without an algorithm it is refused at startup, and with an HS* algorithm the verifier refuses it (ErrPEMKeyHMACAlgorithm).

The 0.x branch is no longer maintained and won't receive a fix: upgrade to 1.x.

Workarounds

Strip everything before -----BEGIN from the key, or set the algorithm explicitly (for example alg RS256).

Affected versions

References

GitHub · dunglas/mercure