Skip to content

[BUG] Cache plugin key ignores HTTP method and request body #6506

Closed

Description

@Aias00

Search before asking

  • I had searched in the issues and found no similar issues.

Apache ShenYu Component

shenyu-plugin

What happened

CacheUtils.dataKey(...) builds the cache key only from query string and raw path:

public static String dataKey(final ServerWebExchange exchange) {
    URI uri = exchange.getRequest().getURI();
    return DigestUtils.md5Hex(String.join(KEY_JOIN_RULE, uri.getQuery(), uri.getRawPath()));
}

The HTTP method, request body, and other request-varying inputs are not included. The cache plugin itself does not restrict caching to idempotent GET requests. As a result, different requests to the same path/query can reuse the same cache entry.

For example, these requests share the same cache key even though they can produce different upstream responses:

POST /orders/quote
{"sku":"A","quantity":1}
POST /orders/quote
{"sku":"B","quantity":1}

The second request can receive the first request's cached body.

Expected behavior

Cache keys should include the dimensions that affect the upstream response, or the plugin should clearly restrict and validate cache usage to request shapes where path/query is sufficient. At minimum, the HTTP method should be part of the key, and body-sensitive methods should either include a body hash or be rejected unless a configured cache-key expression is provided.

How to reproduce

  1. Enable the cache plugin for an endpoint that accepts POST requests.
  2. Send a POST request to /orders/quote with one body and let it be cached.
  3. Send another POST request to the same path/query but with a different body.
  4. The second request uses the same CacheUtils.dataKey(...) value and can receive the first response from cache.

Debug logs

No response

Environment

Current master branch.

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Activity

  1. github-actions commented on Jul 31, 2026

    @github-actions
    Contributor

    👋 Hello @Aias00

    A new issue has been opened by @Aias00:

    Please review when you have time. Thank you! 🙏

  2. Aias00 commented on Aug 2, 2026

    @Aias00
    ContributorAuthor

    Cross-link: related to #6505 — both are CachePlugin correctness defects. #6505 loses response status/headers on cache hit (entry scope); this issue is the cache key ignoring method & body (CacheUtils.java:45-49). Worth fixing together in one CachePlugin pass.

  3. added a commit that references this issue on Oct 16, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions