Skip to content

jws: name loose keySet options in fan-out verify error - #2085

Merged
lestrrat merged 1 commit into
develop/v3from
fix-v3-keyset-fanout-error-options
Apr 29, 2026
Merged

lestrrat merged 1 commit into
develop/v3from
fix-v3-keyset-fanout-error-options

Conversation

@lestrrat

Copy link
Copy Markdown
Collaborator

v3 backport of #2084.

When verification fails after WithRequireKid(false) and/or WithInferAlgorithmFromKey(true) widened the per-signature candidate set, the existing "tried N key(s) but none verified successfully" error gives the operator no signal that a loose option produced the fan-out. The common mis-diagnosis is to add more keys to the JWKS, when the actual problem is either a malformed JWS or a config looser than the deployment needs.

When the attempt count exceeds 1 under a loose-config keySetProvider, name the option(s) that fired in the final error: "tried M (alg,key) pair(s) but none verified successfully; jws.WithRequireKid(false) and/or jws.WithInferAlgorithmFromKey(true) widened the candidate set". The default-config message and the zero-keys-attempted message are unchanged, so any caller matching on those continues to work.

Regression test in jws/jws_test.go:TestVerifyFanoutErrorNamesLooseOptions builds a 3-key JWKS with alg=HS256 set on each, signs with a 4th (un-listed) key, calls Verify with WithKeySet(set, WithRequireKid(false)), and asserts the error contains both the count phrasing and the option name. Existing verify tests still pass.

When verification fails after WithRequireKid(false) and/or
WithInferAlgorithmFromKey(true) widened the (alg,key) candidate set,
the existing "tried N key(s) but none verified successfully" error
gives the operator no signal that a loose option produced the fan-out.
The common mis-diagnosis is to add more keys to the JWKS, when the
actual problem is either a malformed JWS or a config that's looser
than the deployment needs.

When the count exceeds 1 under a loose-config keySetProvider, name the
option(s) that fired in the final error: "tried M (alg,key) pair(s) but
none verified successfully; jws.WithRequireKid(false) and/or
jws.WithInferAlgorithmFromKey(true) widened the candidate set". The
default-config message and the no-keys-attempted message are unchanged.

v3 backport of the v4 fix.
@lestrrat
lestrrat merged commit ba44f88 into develop/v3 Apr 29, 2026
14 checks passed
@lestrrat
lestrrat deleted the fix-v3-keyset-fanout-error-options branch April 29, 2026 10:00
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