Repository navigation
Don't derive an HMAC key from an empty client secret - #579
Conversation
client_secret_oct_keys/2 only skipped the unauthenticated atom, so a client context with client_secret = <<>> produced a zero-length oct key that was added to the verification keys for ID tokens, JARM responses and userinfo, and to the request object keys. Treat <<>> like unauthenticated.
I think that would be sensible 👍 |
from_configuration_worker/3,4 now return {error, empty_client_secret} and
from_manual/4,5 raise empty_client_secret, so the misconfiguration shows up
at startup instead of as failed token requests. Use unauthenticated for
public clients.
The request-object test that used <<"">> as a stand-in secret for a
client_jwks client now uses a dummy secret, as guides/private-key-jwt.md
recommends.
|
Added the up-front check in f1ef337:
One thing to flag: I've updated the PR description to match. |
|
I should rethink that API at some point. Dummy values is not exactly a good way to do this. |
oidcc_jwt_util:client_secret_oct_keys/2builds anoctJWK from the client secret whenever an HS* algorithmis allowed. It only skips the
unauthenticatedatom, so a client context built withclient_secret = <<>>(for example from an unset environment variable) gets a zero-length HMAC key. That key then joins the
verification key set for ID tokens, JARM responses and signed userinfo, and the signing/encryption key set
for request objects.
An empty secret is never a working configuration, so this PR stops it in two places:
oidcc_client_context:from_configuration_worker/3,4return{error, empty_client_secret},and
from_manual/4,5raiseempty_client_secret. Public clients should useunauthenticated.<<>>is treated likeunauthenticated, so HS*-signed content fails withno_matching_keyeven if a context with an empty secret is built some other way.Clients configured correctly are unaffected.
Changes:
src/oidcc_jwt_util.erl: newclient_secret_oct_keys(_, <<>>) -> noneclause.src/oidcc_client_context.erl,lib/oidcc/client_context.ex: reject<<>>in the constructors; docsupdated;
empty_client_secretadded tooidcc_client_context:error().test/oidcc_jwt_util_test.erl,test/oidcc_token_test.erl: the key-derivation guard, including anID token and a JARM response signed with an empty key.
test/oidcc_client_context_test.erl,test/oidcc/client_context_test.exs: the constructors.test/oidcc_authorization_test.erl:create_redirect_url_with_request_object_no_hmac_testnow uses adummy secret instead of
<<"">>, asguides/private-key-jwt.mdrecommends.Behaviour change: code passing
""as the client secret, e.g. as the #442 workaround for aclient_jwks-only client, now fails at startup. A non-empty dummy secret still works. Probably worth achangelog note.
Testing (OTP 29 / Elixir 1.20):
rebar3fmt, eunit (152), ct (24), lint, hank and dialyzer, plusmixformat, test (81) and dialyzer, all pass.