fix: PATCH /v1/admin/api-keys/{key_id} returns 500 — cjson roundtrip bug#70
Merged
Conversation
Root cause: Redis cjson.decode/encode roundtrip converts empty JSON
arrays [] to objects {}, corrupting scope_filter and permissions fields.
Jackson then fails to deserialize {} into List<String>.
Fix: Replace Lua cjson roundtrip with Java-side read-modify-write
using Jackson serialization. Reads key, validates status, applies
partial updates, writes back with clean Jackson JSON.
Trade-off: not atomic (was Lua atomic), but admin key updates are
low-frequency operations with minimal race risk.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PATCH to any API key returns 500 Internal Server Error.
Root cause
The Lua
UPDATE_KEY_LUAscript usescjson.decode→ modify →cjson.encoderoundtrip. Redis cjson converts empty JSON arrays[]to objects{}. Whenscope_filterorpermissionsis[], the re-encoded JSON has{}which Jackson cannot deserialize intoList<String>, causing an unhandled exception → 500.Fix
Replace the Lua cjson roundtrip with Java-side read-modify-write:
jedis.get()— read current key JSONobjectMapper.readValue()— deserialize with JacksonobjectMapper.writeValueAsString()— serialize with Jackson (clean, no cjson issues)jedis.set()— write backTrade-off: not atomic (was Lua atomic), but admin key updates are low-frequency operations.
Test plan
mvn verify— 419 tests, 0 failures, 95%+ coverage