Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Exception when cache deserialization fails #1643

Closed
pmaytak opened this issue Feb 26, 2022 · 1 comment · Fixed by #1644
Closed

[Bug] Exception when cache deserialization fails #1643

pmaytak opened this issue Feb 26, 2022 · 1 comment · Fixed by #1644
Assignees
Milestone

Comments

@pmaytak
Copy link
Contributor

pmaytak commented Feb 26, 2022

Which version of Microsoft Identity Web are you using?
1.23.0

Actual behavior
Related to MSAL issue 3162.
When distributed cache serialization and encryption is enabled, in certain cases (like when encryption keys are changed), MSAL will fail to deserialize an already serialized cache entry and throw an exception.

Repro

  1. Use WebAppCallsMicrosoftGraph.
  2. Add distributed token caches, data protection (with data protection discriminator), and encryption.
...
.AddDistributedTokenCaches();
services.AddDataProtection(o =>
{
    o.ApplicationDiscriminator = "DataProtectionApplicationDiscriminator12";
});

services.Configure<MsalDistributedTokenCacheAdapterOptions>(options =>
{
    options.Encrypt = true;
});
  1. Set up some distributed cache like SQL or Redis.
  2. Login once, so that encrypted token is in the L2 cache. (Don't sign out, it will delete the cached token.)
  3. Change the data protection discriminator to something else.
  4. Login with the same account again.
  5. Data protection will fail decrypting the cache entry, and pass the encrypted entry to MSAL which will fail at deserialization.

Expected behavior

Other possible solution:

  • When deserialization error happens, cache is cleared, code execution continues.
    • Not good solution because if at least one machine in a distributed environment is misconfigured, the cache would be cleared for all machines constantly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants