fix(elasticsearch-logger): guard os.date against invalid index template#13542
Open
AlinsRan wants to merge 1 commit into
Open
fix(elasticsearch-logger): guard os.date against invalid index template#13542AlinsRan wants to merge 1 commit into
AlinsRan wants to merge 1 commit into
Conversation
6899fc4 to
e1b209d
Compare
The dynamic-index feature passes the user-controlled time format straight to os.date in replace_time(). os.date raises (instead of returning nil) on some invalid strftime escapes, so a crafted index template would throw in the log phase rather than degrade gracefully. Wrap the call in pcall and fall back to an empty replacement on failure, as the existing nil-check already intended. Signed-off-by: AlinsRan <alinsran@apache.org>
e1b209d to
b6cd667
Compare
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.
TL;DR
Dynamic Elasticsearch index names containing
{*t}/{!*t}produced a garbage index likeservices-table: 0x7f...instead of being rejected.Cause
The
indexfield supports{time_format}placeholders passed straight toos.date. The existingif not timeguard assumes bad input returnsnil, but on LuaJIT/OpenResty it never does:{*t}/{!*t}makeos.datereturn a table, not a string. It then flows intongx.re.gsub, which stringifies it into the index name.Fix
Require
os.dateto return a string before using it; otherwise logfailed to parse time formatand fall back to an empty replacement. Wrapped inpcallfor defense-in-depth on non-LuaJIT runtimes (whereos.datecan raise on a bad escape).Test
t/plugin/elasticsearch-logger2.tTEST 10:prefix{*t}suffix(and{!*t}) now resolves toprefixsuffixwith afailed to parse time formatlog, instead of embedding atable: 0x...address.Checklist