erlef / oidcc

OpenId Connect client library in Erlang & Elixir
https://hexdocs.pm/oidcc
Apache License 2.0
183 stars 49 forks source link

cache-control ending in max-age=0 crashes provider configuration worker #370

Closed adamcstephens closed 3 months ago

adamcstephens commented 3 months ago

oidcc version

3.2.0

Erlang version

27.0

Elixir version

1.17.2

Summary

Attempting to integrate with kanidm (https://kanidm.com) as an OIDC provider, I am unable to successfully start the provider configuration worker, as it crashes with {:error, :badarg}.

I have an instance publicly available at: https://id.robins.wtf/oauth2/openid/temp

After troubleshooting, I tracked it down to an issue with the parsing of the cache-control header. Kanidm sets cache-control: no-store, no-cache, max-age=0 in its responses, which returns true from the foldl here: https://github.com/erlef/oidcc/blob/299114248949c8c83d5a853f1340991733c763c0/src/oidcc_provider_configuration.erl#L589-L603

Even setting a fallback expiry does not help, as the max-age=0 at the end of the header ensures the fallback is not honored. It sets true on max-age and then skips the 0.

Current behavior

iex(6)> Oidcc.ProviderConfiguration.Worker.start_link(%{issuer: "https://id.robins.wtf/oauth2/openid/temp"})
{:ok, #PID<0.847.0>}
[error] GenServer Sower.Provider terminating
** (MatchError) no match of right hand side value: {:error, :badarg}
    (oidcc 3.2.0) src/oidcc_provider_configuration_worker.erl:185: :oidcc_provider_configuration_worker.handle_continue/2
    (stdlib 6.0) gen_server.erl:2163: :gen_server.try_handle_continue/3
    (stdlib 6.0) gen_server.erl:2072: :gen_server.loop/7
    (stdlib 6.0) proc_lib.erl:329: :proc_lib.init_p_do_apply/3
Last message: {:continue, :load_configuration}

How to reproduce

See current behavior.

Expected behavior

I expect the worker process to successfully initialize.

This error wasn't clear at all and required a bit of digging, so if possible it would be nice to expose a more helpful error.

maennchen commented 3 months ago

Thanks for the detailed report and the test provider! That makes it a lot simpler. Having a look now.

adamcstephens commented 3 months ago

Thanks for the quick fix and release! :heart: