fix(log-sanitize): return raw tables to avoid double delay_encode#13605
Open
shreemaan-abhishek wants to merge 1 commit into
Open
fix(log-sanitize): return raw tables to avoid double delay_encode#13605shreemaan-abhishek wants to merge 1 commit into
shreemaan-abhishek wants to merge 1 commit into
Conversation
redact_params/redact_extra_opts already returned a delay_encode pool slot, but the AI plugin call sites wrap that slot in delay_encode a second time. cjson ignores the inner slot's __tostring metamethod, so the log line emits the wrapper table instead of the redacted JSON. Since delay_encode recycles a 16-slot pool, the inner slot may also hold another request's data by flush time, risking stale or unredacted content in logs. Return raw tables and let the existing single delay_encode at each call site do the encoding.
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
apisix/utils/log-sanitize.lua'sredact_params/redact_extra_optsalready return a recycleddelay_encodepool slot (a{data=, force=}table with a__tostringmetamethod). The AI plugin call sites then wrap that slot incore.json.delay_encode(..., true)a second time:apisix/plugins/ai-proxy/base.lua:265apisix/plugins/ai-providers/base.lua:132apisix/plugins/ai-providers/base.lua:779When the log line flushes, cjson encodes the inner wrapper table (cjson ignores
__tostring), so the log emits the wrapper structure instead of the redacted JSON. Worse,delay_encoderecycles a 16-slot pool, so by flush time the inner slot may already hold an unrelated request's data, risking stale or unredacted content from a different request in the logs. This triggers on every AI-proxy / ai-providers request log at info level.This makes the sanitizer return raw tables and lets the single
delay_encodealready present at each call site do the encoding.Checklist