Aias00 opened a new issue, #7685:
URL: https://github.com/apache/shenyu/issues/7685

   ### Current behavior
   
   A request rule that only sets a header also rebuilds the entire request URI. 
`UriComponentsBuilder.fromUri(...)` retains the already escaped path, but the 
following `.build().encode()` escapes its percent signs again.
   
   Example with `{"header":{"setHeaders":{"X-Demo":"1"}}}`:
   
   ```text
   Input:       http://localhost/files/a%2Fb?x=hello%20world
   Mutated URI: http://localhost/files/a%252Fb?x=hello%20world
   ```
   
   ### Location
   
   - [RequestPlugin URI 
reconstruction](https://github.com/apache/shenyu/blob/66d7d954ca37d651a5ad916f988a8081157a7ab4/shenyu-plugin/shenyu-plugin-request/src/main/java/org/apache/shenyu/plugin/request/RequestPlugin.java#L79)
 (lines 79–86).
   - [Downstream URI matching reads the mutated raw 
path](https://github.com/apache/shenyu/blob/66d7d954ca37d651a5ad916f988a8081157a7ab4/shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/RequestUrlUtils.java#L93)
 when no context-path/rewrite override is present.
   
   ### Impact and priority
   
   **P2 / Medium.** Enabling a header or cookie transformation can change 
routing for requests with percent-escaped paths. Matching rules for the 
original raw path can stop matching; this is an unrelated side effect of a 
header-only rule. This report does not claim every upstream transport forwards 
the mutated path, because some use `ShenyuContext.realUrl`.
   
   ### Reproduction and evidence
   
   1. Enable a matching request-plugin rule with the header-only handle above.
   2. Use a request with raw URI `/files/a%2Fb?x=hello%20world`, without a 
context-path/rewrite override.
   3. Observe the URI and URI condition input in the next plugin: 
`/files/a%252Fb` instead of `/files/a%2Fb`.
   
   A standalone Java probe compiled the current `RequestPlugin.java` and 
`RequestPluginHandler.java` and invoked `doExecute()` with a 
`MockServerWebExchange` built from a `java.net.URI`. It observed the mutated 
URI above, `X-Demo=1`, and `RequestUrlUtils.getRewrittenRawPath()` returning 
`/files/a%252Fb`. This is a plugin-level reproduction, not a full 
deployed-gateway run.
   
   ### Suggested fix
   
   Preserve already encoded path/authority components while encoding newly 
supplied query values exactly once. Avoid rebuilding the URI when only 
headers/cookies change. Cover `%2F`, `%20`, non-ASCII escaped paths, and query 
mutations in the behavior verification.
   
   ### Related existing work
   
   Searched the 3,074-issue baseline and 85 open PRs, plus live 
RequestPlugin/encoding searches. #3235 concerns unencoded Chinese **query 
values**; #1770/#1768 concern WebClient outbound encoding; #6507 concerns null 
partial rule sections. None describes RequestPlugin re-encoding the existing 
raw **path** during a header-only mutation.
   
   ### Environment
   
   Apache ShenYu `2.7.2-SNAPSHOT`, 
`master@66d7d954ca37d651a5ad916f988a8081157a7ab4`. Reviewed under the 
repository-audit workflow; unit-test and CI issue categories excluded.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to