Skip to content

[BUG] Rule match cache reuses a rule from another selector for the same request path #7976

Open

Description

@Aias00

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

  1. Enable a test plugin using AbstractShenyuPlugin, with default match caches enabled.
  2. Add custom-flow selector A: AND header X-Tenant = a; add selector B: AND header X-Tenant = b. Set both enabled and continued=true.
  3. Under A add enabled rule RA: uri = /x. Under B add enabled rule RB: uri = /x.
  4. Execute GET /x with X-Tenant=a. Observed doExecute receives A and RA.
  5. 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?

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

  1. imDwAaY commented on Oct 22, 2026

    @imDwAaY
    Contributor

    PR #7681 (fix(plugin): isolate match cache across config updates) already scopes rule match results to the selected selector — its ruleCacheKey is built as selectorData.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.

  2. Aias00 commented on Nov 11, 2026

    @Aias00
    ContributorAuthor

    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 require pathOnlySelectorSet(selectors). The rule cache key is (plugin, path) with no selector id, and matchRuleAndExecute uses a cached rule without checking ruleData.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions