apache / apache/shenyu

[BUG] CollapseSlashesFilter drops query string and fragment when collapsing path

Open Beginner friendly
#6,628 1 comment 0 reactions 0 assignees View on GitHub
priority: high type: bug
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

- Severity: High
- Location:
`shenyu-web/src/main/java/org/apache/shenyu/web/filter/CollapseSlashesFilter.java:36-38`
-
Description:
The filter computes `newPath = request.getURI().getRawPath().replaceAll("/{2,}", "/")` (path-only string, no query/fragment), then calls `request.getURI().resolve(newPath)`. Per `java.net.URI` resolution semantics, resolving a relative reference with only a path component **replaces** the query and fragment of the base URI with null. E.g. `URI.create("http://h/a//b?q=1#f").resolve("/a/b")` produces `http://h/a/b` — query and fragment silently lost.
-
Impact:
When `collapseSlashes=true`, any request with double-slashes in the path AND a query string loses all query parameters. Breaks pagination, search, API key passing, query-param-dependent routing.
-
Suggested fix:
Reconstruct the URI preserving query/fragment: `UriComponentsBuilder.fromUri(request.getURI()).replacePath(newPath).build().toUri()`.
-
Confidence: High
- Related existing: PERF-03 covers regex recompilation perf in the same filter, not the query-loss functional bug.

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/00-consolidated-critical-high.md`](docs/scan2-2026-08-02/00-consolidated-critical-high.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in shenyu-web/src/main/java/org/apache/shenyu/web/filter/CollapseSlashesFilter.java at lines 36-38 and reproduce the URI example with a double-slash path, query, and fragment. Confirm the collapsed path retains the query and fragment, then verify requests with query-dependent routing no longer lose those components.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.