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

   ## Is there an existing issue for this?
   
   - [x] I searched open and closed issues.
   
   ## Current Behavior
   
   AI request transformation rejects valid generated HTTP request targets 
containing a query string, while still applying the generated body and headers.
   
   For an original `POST /original?old=1`, a model response such as:
   
   ```http
   POST /rewritten?new=2 HTTP/1.1
   Content-Type: application/json
   X-AI: yes
   
   {"ai":"query"}
   ```
   
   leaves the downstream URI at `/original?old=1`, with the generated 
body/header applied.
   
   The template supplies the model with the original path plus raw query. The 
response parser extracts `/rewritten?new=2`, but rewriteRequestPath() applies 
the path-only regex `^/[a-zA-Z0-9/_\-]*$` to the whole target. The `?` causes 
rejection.
   
   ## Expected Behavior
   
   Parse an origin-form target into path/query components and apply valid 
generated components consistently. Valid query-bearing output should not become 
a partially transformed request routed to the original target.
   
   ## Reproduction
   
   Invoke actual AiRequestTransformerPlugin.doExecute() with a mocked 
ChatClient stream returning the HTTP text above. A real MockServerWebExchange 
and downstream body capture produced:
   
   ```text
   query.uri=http://localhost/original?old=1
   query.body={"ai":"query"}
   query.xAi=yes
   query.outboundUri=http://upstream.example/original?old=1
   ```
   
   A path-only `/rewritten` control passes this validation and mutates the 
request URI. Its separate stale routing-context behavior is a different 
integration issue.
   
   ## Location And Impact
   
   - 
[AiRequestTransformerTemplate.java:159](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/template/AiRequestTransformerTemplate.java#L159):
 prompt includes path plus raw query.
   - 
[AiRequestTransformerPlugin.java:250](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/AiRequestTransformerPlugin.java#L250):
 validates the entire target as a path-only string.
   - 
[AiRequestTransformerPlugin.java:128](https://github.com/apache/shenyu/blob/67596c1d228b62da75cd0a0ecb47d0ac5d995384/shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-request-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/request/AiRequestTransformerPlugin.java#L128):
 header/body changes precede target validation.
   
   Severity: Medium. Confidence: high. Query addition/removal/change requests 
silently fail for the target, and backends receive new body/header semantics on 
the old endpoint/query.
   
   ## Suggested Fix And Regression Coverage
   
   Use structured URI components, preserve the intended scheme/authority, and 
validate path/query separately. Decide on a consistent failure policy for 
rejected targets rather than applying an inconsistent partial transformation. 
Keep appropriate path validation.
   
   Add doExecute-level cases for generated query addition, replacement/removal, 
encoded values and path-only control. Assert the downstream target together 
with body/headers; coordinate routing-context synchronization with the separate 
stale-context issue.
   
   ## Validation And Related Issues
   
   Reviewed master `67596c1d228b62da75cd0a0ecb47d0ac5d995384` 
(`2.7.2-SNAPSHOT`). Discovery and isolated verifier reproductions passed; 
leader recompiled current plugin source and reran the query/path-only harness. 
Existing AiRequestTransformerPluginTest: 5 tests passed, without this target 
case.
   
   #6795 is streaming buffering, #6755 cache eviction, #6648 cache concurrency, 
#5973 the original feature request, and #7351 an AI-proxy refactor. No matching 
query-target validation issue was found.
   
   No external AI API or live gateway request was made; ChatClient was mocked.
   


-- 
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