Hash cache key so reserved characters do not cause keys to be rejected.#116
Hash cache key so reserved characters do not cause keys to be rejected.#116
Conversation
smarcet
left a comment
There was a problem hiding this comment.
Good fix — the md5() hashing correctly eliminates PSR-6 reserved characters (/ in particular) from cache keys.
However, this PR is missing a regression test. Without one, the md5() call could be accidentally reverted with no test failure to catch it.
Suggested test coverage (integration test using the real cache backend):
-
Cache write/read with reserved characters — call
getClientByIdCacheablewith a client ID containing/(e.g..-_~87D8/Vcvr6fvQbH4HyNgwTlfSyQ3x.openstack.clientfromTestSeeder), assert it returns the correct client without throwingInvalidArgumentException. Call it a second time to verify the cached entry is also retrievable. -
Distinct cache entries for different IDs — call
getClientByIdCacheablewith two different client IDs that both contain/, assert they return different clients. This confirms the hashing doesn't accidentally collapse distinct keys.
These can go in a new tests/OAuth2ClientCacheTest.php extending BrowserKitTestCase (which seeds the test data and connects to Redis).
|
@mulldug please
|
…ed character violation symfony/cache v7+ enforces PSR-6 key validation in all adapters, including array. Client IDs may contain reserved characters (e.g. '/'), which caused getClientByIdCacheable() to throw InvalidArgumentException and return a server_error 400 during token exchange. Replace the raw client ID with its md5 hash in the cache key so the key is always a valid hex string, regardless of the client ID's content. Adds OAuth2ClientCacheTest to cover retrieval with reserved-character IDs and to confirm distinct IDs hash to distinct cache keys.
94793b4 to
c686d19
Compare
|
Tests have been added and the commit message updated. |
Cache keys were being rejected because they contained characters that are reserved in PSR-6 cache keys. The fix is to hash the key.