Bug: gw-error-format rewrites status and headers before response-body match
Potential security issues should be reported privately. This report concerns response-format correctness; no authentication bypass or data exposure is claimed.
- I searched the repository's issues and pull requests and believe this is not a duplicate.
I. Issue Description
gw-error-format can rewrite a response's status and headers when the configured match.responsebody does not match. A gateway-generated 403 with a different error body can become 200 with Content-Type: application/json while keeping its original plain-text body.
II. Describe what happened
At main@b44d4f77011ad7f63c2fefef5b8cd2dec0cff1c6, onHttpResponseHeader matches the status and absence of x-envoy-upstream-service-time, then immediately changes :status, removes content-length, and applies set_header. onHttpResponseBody subsequently leaves a nonmatching body unchanged, without restoring status or headers.
The existing body-mismatch test asserts only the unchanged body, so it does not detect the resulting status/header mismatch.
III. Describe what you expected to happen
A rule with both match.statuscode and match.responsebody should rewrite status, body, and configured headers only when both match. If the body differs, keep the original status, body, and headers. The README describes the two match fields together.
IV. How to reproduce it
- Configure
match.statuscode: "403",match.responsebody: "RBAC: access denied",replace.statuscode: "200",replace.responsebody: '{"code":401}', andset_headerwithcontent-type: application/json. - Supply a response with
:status: 403,content-type: text/plain, bodyDifferent error message, and nox-envoy-upstream-service-timeheader. - After the header and body callbacks, the source path yields status
200and JSON content type with the originalDifferent error messagebody. Expected: original403,text/plain, and original body.
From the plugin module directory, go test -count=1 -run '^TestOnHttpResponseBody$' -v . passes in native Go mode because the existing body-mismatch case does not assert status or headers. A real proxy-Wasm/Envoy reproduction has not been run.
V. Anything else we need to know?
This report is based on source inspection, the documented match semantics, and the native Go test path. Wasm mode was skipped because main.wasm is absent; no gateway runtime logs are available. AI assistance was used for analysis and drafting. No fix is included.
VI. Environment
- Higress version:
main@b44d4f77011ad7f63c2fefef5b8cd2dec0cff1c6 - OS: macOS/arm64 for the native Go test
- Others: Go 1.24.4; real Envoy/proxy-Wasm behavior not yet verified
Source: higress-group/higress