apache / apache/shenyu

[BUG] Response transformer mutates response headers before validating body extraction

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

Description

- severity: Medium
- files: `shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/AiResponseTransformerPlugin.java:359-371`
- description: In the decorator's inner `flatMap`, the code does `this.getHeaders().clear(); this.getHeaders().putAll(newHeaders);` BEFORE checking whether `newBody` is non-null. If body extraction fails (returns null), the else-branch returns the ORIGINAL body bytes but with response headers already replaced by whatever the AI emitted. Original `Content-Type`/`Content-Length` are gone.
- impact: Corrupted response headers (and Content-Length mismatch) on any AI transformation where body extraction fails.
- suggested_fix: Only mutate headers after both header AND body extraction succeed.
- confidence: High
- related_existing: none — SEC-9 covers gzip decompression in the same file, not this ordering bug.

---
_Identified during the 2026-08-02 deep re-scan; full list in [`docs/scan2-2026-08-02/06-medium-tiers.md`](docs/scan2-2026-08-02/06-medium-tiers.md)._

Contributor guide

No contributing guide indexed for this repository

Research direction

Read shenyu-plugin/shenyu-plugin-ai/shenyu-plugin-ai-response-transformer/src/main/java/org/apache/shenyu/plugin/ai/transformer/response/AiResponseTransformerPlugin.java:359-371, focusing on the decorator's inner flatMap and its header/body extraction paths. Verify that a null body extraction leaves the original response headers and body unchanged, while headers are replaced only after both extractions succeed.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.