Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
Rule match results are stored under plugin name and request path, without selector ID. After selecting a selector, AbstractShenyuPlugin accepts the cached rule without checking its selectorId. Therefore, two selectors selected by different request headers can execute each other's rules.
Expected Behavior
A cached rule must belong to the currently selected selector. Isolate entries by selector and path, and ensure negative entries have the same isolation.
Steps To Reproduce
- Enable a test plugin using AbstractShenyuPlugin, with default match caches enabled.
- Add custom-flow selector A: AND
header X-Tenant = a; add selector B: ANDheader X-Tenant = b. Set both enabled and continued=true. - Under A add enabled rule RA:
uri = /x. Under B add enabled rule RB:uri = /x. - Execute GET /x with X-Tenant=a. Observed doExecute receives A and RA.
- Execute GET /x with X-Tenant=b. Observed doExecute receives B and RA, instead of B and RB.
The header-based selectors are not positively cached, but their URI-only rules are. Thus selector selection is correct while rule selection crosses the selector boundary. This can apply the wrong route, transformation or policy handle, depending on the plugin.
Anything else?
- Rule lookup:
Lines 120 to 132 in 862f5e3
// if the L2 cache fails to hit, execute default strategy. RuleData ruleData = obtainRuleDataCacheIfEnabled(path); if (Objects.nonNull(ruleData) && Objects.isNull(ruleData.getId())) { return handleRuleIfNull(pluginName, exchange, chain); } if (Objects.isNull(ruleData)) { ruleData = defaultMatchRule(exchange, rules, path); if (Objects.isNull(ruleData)) { return handleRuleIfNull(pluginName, exchange, chain); } } printLog(ruleData, pluginName); return doExecute(exchange, chain, selectorData, ruleData); - Cache key:
Lines 175 to 178 in 862f5e3
public void cacheRuleData(final String path, final RuleData ruleData, final int initialCapacity, final long maximumSize, final long ttl) { MapUtils.computeIfAbsent(RULE_DATA_MAP, ruleData.getPluginName(), map -> new WindowTinyLFUMap<>(initialCapacity, ttl, maximumSize, Boolean.FALSE)).put(path, ruleData); }
Environment
ShenYu master, 2.7.2-SNAPSHOT, commit 862f5e37e894bd8cef85ef540a8629f313e9ecdf, Java 17.
Validation
Reproduced with a minimal concrete AbstractShenyuPlugin subclass, real BaseDataCache/MatchDataCache, Spring MockServerWebExchange and execute(...).block(). The subclass records selector/rule IDs in doExecute. Match caches use the default enabled settings. The existing 90 targeted matching/cache/predicate tests passed; this does not exercise a deployed HTTP gateway.
Activity
imDwAaY commentedon Oct 22, 2026
PR #7681 (fix(plugin): isolate match cache across config updates) already scopes rule match results to the selected selector — its
ruleCacheKeyis built asselectorData.getId().length() + ":" + selectorData.getId() + path— and only caches when every enabled candidate has stable URI conditions, so the cross-selector rule reuse reported here (including the negative-entry case) appears covered. That PR is currently open with changes requested.Should this issue stay open as a tracking item until #7681 merges, or be closed once it lands? I will hold off on a separate fix to avoid conflicting with that change.
Aias00 commentedon Nov 11, 2026
Confirmed this is still present on master (9dd9a12). In
AbstractShenyuPlugin.defaultMatchRule, the positive rule-cache write only requires that the current selector's enabled rules are path-only. Unlike the negative branch, it does not requirepathOnlySelectorSet(selectors). The rule cache key is(plugin, path)with no selector id, andmatchRuleAndExecuteuses a cached rule without checkingruleData.getSelectorId()against the selected selector. So when selectors are chosen by a non-path condition (header, cookie, query, host, ip), a later request on the same path that selects a different selector can execute with the first selector's rule. The open fix is #8103.