fix(redis-schema): copy policy schemas instead of mutating shared tables#13555
Merged
shreemaan-abhishek merged 2 commits intoJun 22, 2026
Merged
Conversation
e0b73a9 to
64795a2
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a schema cross-contamination bug in apisix/utils/redis-schema.lua where limit-conn extended Redis policy schemas by mutating shared tables at module load time, causing unrelated plugins (e.g., limit-count, limit-req) to unexpectedly inherit key_ttl (and its default) during schema validation.
Changes:
- Build
limit-conn’s Redis / Redis Cluster schema variants via a copiedpropertiestable (instead of mutating the shared base tables). - Add regression coverage to ensure
key_ttlis not injected intolimit-count/limit-reqconfigs even whenlimit-connis loaded first. - Add assertions that
limit-connstill applieskey_ttldefaulting and honors explicitkey_ttl.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| apisix/utils/redis-schema.lua | Avoids mutating shared Redis policy schema tables by creating limit-conn-specific variants with copied properties. |
| t/utils/redis-schema.t | Adds regression tests to prevent key_ttl leakage into other plugins and to pin limit-conn’s key_ttl behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…bles 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 core.table.deepcopy of the shared base so the extra property stays local to limit-conn. deepcopy matches the schema-derive idiom already used by limit-count and ai-cache, and yields a fully independent tree so future nested edits cannot leak back into the shared base. Add t/utils/redis-schema.t: one block loads limit-conn first and asserts limit-count/limit-req confs across redis and redis-cluster do not gain a key_ttl; a second block pins limit-conn's own behavior (default 3600 applied, explicit value honored). Signed-off-by: janiussyafiq <izzraff.js@gmail.com>
limit-req bound redis_schema.schema directly, holding a live reference to the shared module table. It only reads the table today, so nothing leaks, but the alias is a latent footgun: any future in-place mutation reachable through limit-req would poison every other consumer. deepcopy the schema at load time to match limit-count and ai-cache, so limit-req owns an independent copy. No behavior change. Signed-off-by: janiussyafiq <izzraff.js@gmail.com>
adc3a8c to
c7dfd28
Compare
shreemaan-abhishek
approved these changes
Jun 22, 2026
nic-6443
approved these changes
Jun 22, 2026
membphis
approved these changes
Jun 22, 2026
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.luaexportspolicy_to_additional_properties(the sharedredis/redis-clusterschema tables) for reuse bylimit-count,limit-req, andlimit-conn. limit-conn'skey_ttlvariants were derived by mutating those shared tables in place at module load:Because the table is shared,
key_ttl(and its default of3600) leaked into the base tables seen by every other consumer. Observable effect:limit-countandlimit-reqconfs silently gained akey_ttl = 3600field during schema validation, even though neither plugin understands the property. A consumer-sidecore.table.deepcopy(redis_schema.schema)doesn't help — by load time it copies the already-mutated tables.Changes
apisix/utils/redis-schema.lua— derive limit-conn'skey_ttlvariants fromcore.table.deepcopyof the shared base, then addkey_ttlto the copy. The sharedredis/redis-clustertables stay clean.deepcopyis the schema-derive idiom already used bylimit-count, and it yields a fully independent tree so future nested edits cannot leak back into the shared base.apisix/plugins/limit-req.lua—limit-reqboundredis_schema.schemadirectly (a live reference to the shared module table). It only reads it today, but the alias is a latent footgun: any future in-place mutation reachable through limit-req would poison every other consumer.deepcopythe schema at load time so limit-req owns an independent copy, matchinglimit-countandai-cache.Behavior
limit-connis unchanged:key_ttlstill accepted, default3600still 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 simply no longer injected.Tests
t/utils/redis-schema.t:limit-connfirst (so any shared-table leak would be visible) and assertslimit-count/limit-reqconfs acrossredisandredis-clusterdo not gainkey_ttl;limit-conn's own behavior (default3600applied, explicit value honored).Which issue(s) this PR fixes:
None (pre-existing latent bug found while building on
redis-schema).Checklist