fix(redis-schema): copy policy schemas instead of mutating shared tables#13555
Open
janiussyafiq wants to merge 3 commits into
Open
fix(redis-schema): copy policy schemas instead of mutating shared tables#13555janiussyafiq wants to merge 3 commits into
janiussyafiq wants to merge 3 commits into
Conversation
limit-conn's key_ttl schema variants were built by mutating the shared policy_to_additional_properties tables in place, leaking key_ttl (and its default of 3600) into every other consumer of apisix/utils/redis-schema.lua: limit-count and limit-req confs silently gained a key_ttl = 3600 field during validation. Build the limit-conn variants from a shallow copy of the shared base so the extra property stays local to limit-conn. A stray explicit key_ttl on limit-count/limit-req is still tolerated (their schemas do not reject additional properties); it is just no longer injected.
e0b73a9 to
64795a2
Compare
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.
Description
apisix/utils/redis-schema.luabuilds limit-conn'skey_ttlschema variants by mutating the sharedpolicy_to_additional_propertiestables in place:Since this runs at module load,
key_ttl(and its default of 3600) leaks into the baseredis/redis-clustertables that every other consumer of this module reuses. Observable effect today:limit-countandlimit-reqconfs silently gain akey_ttl = 3600field during schema validation (defaults are applied to the conf), even though neither plugin understands the property.limit-count'score.table.deepcopy(redis_schema.schema)doesn't help — it copies the already-mutated tables.This PR builds the limit-conn variants from a shallow copy of the shared base, so the extra property stays local to limit-conn:
redis/redis-clustertables no longer carrykey_ttllimit-connbehavior is unchanged (key_ttlstill accepted, default 3600 still applied)limit-count/limit-reqconfs no longer get a foreignkey_ttlinjected; a stray explicitkey_ttlon those plugins is still tolerated (their schemas do not reject additional properties) — it is just no longer injectedNew regression test
t/utils/redis-schema.t(the existing home forapisix/utils/*tests, alongsidebatch-processor.t/rfc5424.t): one block validateslimit-count/limit-reqconfs acrossredisandredis-clusterpolicies — withlimit-connloaded first so any shared-table leak would be visible — and asserts nokey_ttlis injected; a second block pinslimit-conn's own behavior (default 3600 applied, explicit value honored). On unfixed master the first block fails withlimit-count redis got key_ttl: 3600(and the three other combinations); with the fix all cases pass.This also unblocks new consumers of
redis-schema.Which issue(s) this PR fixes:
None (pre-existing latent bug found while building on
redis-schema).Checklist