Skip to content

fix(response-rewrite): do not empty body when base64 secret is invalid#13586

Open
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:fix/response-rewrite-base64-secret-decode
Open

fix(response-rewrite): do not empty body when base64 secret is invalid#13586
AlinsRan wants to merge 1 commit into
apache:masterfrom
AlinsRan:fix/response-rewrite-base64-secret-decode

Conversation

@AlinsRan

Copy link
Copy Markdown
Contributor

Description

With body_base64 = true and body set to a secret reference ($env://..., $secret://...), the config-time base64 validation is skipped because the value is unknown until runtime. If the resolved secret is not valid base64, ngx.decode_base64 returned nil and the response body was silently set to empty — no log, hard to diagnose.

In body_filter, when base64 decoding fails, this now logs an error and leaves the upstream response body unchanged instead of emptying it, mirroring the existing failure handling in the filters path of the same plugin. The body is only overwritten on a successful decode.

Tests

t/secret/central-secret-refs.t TEST 13/14: a route configured with body = $env://TEST_NOT_BASE64 (resolves to a non-base64 value) and body_base64 = true; the request returns the unchanged upstream body and an error is logged.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change (N/A — bugfix, no config/behavior doc change)
  • I have verified that this change is backward compatible

When body is a secret reference and body_base64 is true, the config-time base64
validation is skipped because the value is unknown until runtime. If the
resolved secret is not valid base64, ngx.decode_base64 returned nil and the
response body was silently emptied. Log an error and leave the upstream response
body unchanged instead.

Add a test using an $env:// reference resolving to a non-base64 value.

Signed-off-by: AlinsRan <alinsran@apache.org>
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant