id-mask icon indicating copy to clipboard operation
id-mask copied to clipboard

Combination of legacyKeys and caching Feature return legacy keys during masking

Open gako opened this issue 1 year ago • 0 comments

I encountered a behaviour that seems to be against the definition for the usage of legacy keys.

I have an IdMask with legacy keys for backward compatibility, which works fine ` KeyManager.IdSecretKey legacyKey = new KeyManager.IdSecretKey(0, legacySecret); KeyManager.IdSecretKey domainKey = new KeyManager.IdSecretKey(1, domainSecret); KeyManager keyManager = KeyManager.Factory.withKeyAndLegacyKeys(domainKey, legacyKey);

IdMasks.forLongIds(Config.builder(keyManager).enableCache(true) `

If I unmask a id that was masked with the legacyKey in the past and then try to mask the same value with the new idmask it will still return the old legacy masked value, probably due to the fact that unmasking the legacy value stores it in the cache and reused it during masking.

As a workaround disabled cache solves the problem, but it probably would be better to not stored legacy masked values in the cache or distinguis in the cache between used cache keys.

gako avatar Nov 24 '23 13:11 gako