The vulnerability exists in the _safe_file_name function located in litestar/stores/file.py. This function's purpose is to convert cache keys into filesystem-safe filenames for the FileStore caching backend. The flaw in the original implementation was its use of a non-injective transformation—specifically, Unicode NFKD normalization combined with substituting non-alphanumeric characters with their ord() value. This created scenarios where different cache keys could be normalized to the identical filename, resulting in a key collision.
The patch, identified in commit 85db6183a76f8a6b3fd6ee3c88d860b9f37a2cca, rectifies this by replacing the weak normalization logic with the hashlib.blake2s cryptographic hash function. This ensures that distinct keys will produce unique filenames, thereby eliminating the collision vector.
During an exploit, an attacker would craft a request with a path that, when used as a cache key, collides with the key of another cached resource. This malicious key is processed by FileStore.set (to poison the cache) or FileStore.get (to retrieve a poisoned entry). Both methods rely on the vulnerable _safe_file_name function to resolve the key to a filename. Consequently, the functions that would be observed in a runtime profile during exploitation are _safe_file_name, FileStore.set, and FileStore.get.