redis: fix uncaught exception in inline command hex escape parser causing full-process DoS [fj4WqyCCw3C5ShR1RfB7MoBPTpkRrBFYP1uT35g3MvT] - #46644
Open
waterWang wants to merge 2 commits into
Conversation
|
Hi @waterWang, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
Contributor
|
Thanks @waterWang for the PR. The change looks good to me. However it needs a couple of fixes please. Every commit needs DCO to record the author. See here on how to fix it https://github.com/envoyproxy/envoy/pull/46644/checks?check_run_id=93843380399 Also PR needs format fix. Please run the fix the code automatically. |
yanavlasov
requested changes
Aug 12, 2026
| the two hex digits of a ``\xHH`` escape in a dedicated buffer and converts them only once both | ||
| are present, matching Redis semantics. A truncated escape (one hex digit before the closing | ||
| quote) is emitted literally instead of crashing, and the out-of-bounds read when ``\x`` was the | ||
| first content of a quoted argument is eliminated. No newline at end of file |
Contributor
There was a problem hiding this comment.
Suggested change
| first content of a quoted argument is eliminated. | |
| first content of a quoted argument is eliminated. | |
Needs newline after last sentence to be formatted correctly.
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.
Fixes #46642
Root cause
source/extensions/filters/network/common/redis/codec_impl.cc,DecoderImpl::parseSlice,State::InlineStringQuotedEscapeHex:When entering the
InlineStringQuotedEscapeHexstate, the escape markerxwas pushed into the value string. Each hex digit was then pushed one at a time, and the code checkeds[s.size() - 3] == xto detect when the escape marker plus two hex digits had been accumulated. If the user argument already contained a literalxbefore the\xHHsequence (e.g.SET key "x\x41"), the 3-back check could match that literalxafter only one hex digit, prematurely callingstd::stoulon a string starting withx(e.g."x4"), which throwsstd::invalid_argument. The exception was not caught (onlyRedis::ProtocolErroris caught at the filter callsites), causingstd::terminateand aborting the entire Envoy process.Additionally, when
\xwas the first content of a quoted argument, after one hex digits.size() == 2, sos[s.size() - 3]was an out-of-bounds read (operator).Fix
Parser fix (codec_impl.cc, codec_impl.h): Stop pushing the escape marker
xinto the value string. Instead, accumulate hex digits in a dedicated scratch buffer (inline_hex_digits_). Convert to a single byte using manual hex conversion (nostd::stoul) only after exactly two hex digits are seen. A non-hex digit or end-of-quote before the second digit flushes the literalxfollowed by any accumulated digits, matching Redis semantics.Defense in depth (proxy_filter.cc, client_impl.cc): Add a
catch (std::exception&)handler alongside the existingProtocolErrorcatch at both decoder callsites, so any unexpected exception from the decoder is treated as a protocol error rather than terminating the process.Tests: Added regression tests for:
xbefore\xHHescape (the crash input)\xescape at the start of a quoted string (the OOB read)\xHHescapes