Skip to content

fix: invalidate req_post_args and post_arg.* cache on set_body_data - #14043

Open
bhuvan-somisetty wants to merge 1 commit into
apache:masterfrom
bhuvan-somisetty:fix-patch-set-body-data-invalidation
Open

bhuvan-somisetty wants to merge 1 commit into
apache:masterfrom
bhuvan-somisetty:fix-patch-set-body-data-invalidation

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown

Description

In apisix/patch.lua, monkey-patched ngx.req.set_body_data only cleared _request_body_table and _request_body_type, leaving api_ctx.req_post_args populated with stale cached form arguments from the pre-rewrite body. In addition, invalidation of post_arg.* variables in var._cache was nested inside if api_ctx and api_ctx._request_body_table then, which skipped variable cache invalidation whenever _request_body_table was not yet populated or was nil.

This PR updates ngx.req.set_body_data:

  1. Always clears api_ctx.req_post_args so that subsequent calls to core.request.get_post_args(ctx) re-parse arguments from the updated body.
  2. Unconditionally clears post_arg.* variables in api_ctx.var._cache whenever ngx.req.set_body_data is invoked.
  3. Adds comprehensive test coverage in t/core/request.t (TEST 20).

Which issue(s) this PR fixes:

Fixes #14042

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
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

In `apisix/patch.lua`, monkey-patched `ngx.req.set_body_data` only cleared
`_request_body_table` and `_request_body_type`, leaving `api_ctx.req_post_args`
with stale cached arguments from the pre-rewrite body. Additionally,
clearing `post_arg.*` variables in `var._cache` was gated behind
`api_ctx._request_body_table`, skipping variable invalidation if
`_request_body_table` had not been populated or had already been cleared.

This commit updates `ngx.req.set_body_data` to always invalidate
`api_ctx.req_post_args` as well as any cached `post_arg.*` variables in
`api_ctx.var._cache` regardless of `_request_body_table` status.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: ngx.req.set_body_data fails to invalidate req_post_args and post_arg.* cache

1 participant