Skip to content

fix(logger): prevent meta_filter from caching access-phase verdict for log phase - #13790

Open
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/logger-meta-filter-phase-cache
Open

fix(logger): prevent meta_filter from caching access-phase verdict for log phase#13790
waterWang wants to merge 1 commit into
apache:masterfrom
waterWang:fix/logger-meta-filter-phase-cache

Conversation

@waterWang

Copy link
Copy Markdown

Description

Fixes #13724

Since 3.16.0, every logger plugin carries an access-phase handler (_M.access = log_util.check_and_read_req_body, introduced in #13034). Because the plugin now runs in access, run_plugin("access", ...) invokes meta_filter(), which evaluates the plugin's _meta.filter and caches the verdict for the rest of the request. This causes two problems:

A. Filter conditions on response-phase variables are decided before those variables have values.

A filter referencing $status or $upstream_status is evaluated against 0 / empty at access phase, and that wrong verdict is reused at log phase.

B. $status is cached as 0, corrupting the output of every plugin on the request.

status is not in no_cacheable_var_names, so the access-phase read of $status (which is 0 at access time) is cached into ctx.var for the remainder of the request. Every plugin that later reads $status gets 0.

Changes

apisix/plugin.lua

Include ngx.get_phase() in the meta_filter cache key so that access-phase and log-phase verdicts are cached separately. The log-phase call recomputes the verdict with correct response-phase variables.

apisix/core/ctx.lua

Add status to no_cacheable_var_names so that $status is never cached. Each read fetches from ngx.var.status directly, avoiding the access-phase 0 contamination.

Related

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Aug 6, 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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: logger _meta.filter evaluates response-phase variables at access phase, breaking filters and caching $status as 0

1 participant