Skip to content

[Bug] Exception when cache deserialization fails #1643

Closed

Description

@pmaytak

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.

Activity

  1. added this to the 1.23.1 milestone on Mar 5, 2022
  2. jennyf19 commented on Mar 15, 2022

    @jennyf19
    Collaborator

    released in 1.23.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions