fix(logger): prevent meta_filter from caching access-phase verdict for log phase - #13790
Open
waterWang wants to merge 1 commit into
Open
fix(logger): prevent meta_filter from caching access-phase verdict for log phase#13790waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inaccess,run_plugin("access", ...)invokesmeta_filter(), which evaluates the plugin's_meta.filterand 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
$statusor$upstream_statusis evaluated against0/ empty at access phase, and that wrong verdict is reused at log phase.B.
$statusis cached as0, corrupting the output of every plugin on the request.statusis not inno_cacheable_var_names, so the access-phase read of$status(which is0at access time) is cached intoctx.varfor the remainder of the request. Every plugin that later reads$statusgets0.Changes
apisix/plugin.lua
Include
ngx.get_phase()in themeta_filtercache 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
statustono_cacheable_var_namesso that$statusis never cached. Each read fetches fromngx.var.statusdirectly, avoiding the access-phase0contamination.Related
_meta.filter#8256.