Summary
Valkey's Lua scripting error handling previously allowed a malicious user to inject arbitrary data into the server's response stream by abusing improperly handled null characters.
In deployments where multiple logical users share the same client connection, this can corrupt responses or return attacker-controlled data to other users over that shared connection.
Affected context
This vulnerability appears in Valkey instances that:
- Enable and use Lua scripting capabilities
- Allow untrusted or partially trusted clients to execute scripts
- Use client connection pooling, multiplexing, or shared connections between different application users
The problem specifically arises when Lua script errors are generated and returned, and the error handling logic fails to safely process embedded null characters, allowing crafted content to spill into the response stream.
Exploit preconditions
- Attack surface: Valkey Lua scripting interface exposed to clients (e.g., via application backends or direct access).
- Required access: Ability to send scripting commands and supply controlled Lua code or arguments to a Valkey instance.
- Trigger point: Execution of a Lua script that intentionally triggers an error condition containing specially crafted data, including null characters.
- Why exploitation is possible: The error handling code for Lua scripts does not properly neutralize or delimit null characters, enabling attackers to inject arbitrary information into the response stream and affect subsequent responses on the same connection.
Why this happens
The underlying issue is improper neutralization of special elements in output that forms part of a structured response, mapping to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.
By not handling null characters correctly in Lua script error messages, the server's response framing becomes unreliable: injected bytes can break expected message boundaries, causing data intended for one client operation to be corrupted, merged with, or replaced by attacker-controlled content.
Conceptually, this is an output encoding and protocol-framing flaw, where the system assumes error text is benign and fails to sanitize characters that have special meaning to the response parser or downstream consumer.
Potential impact
- Response tampering on a shared connection, where other users may receive attacker-injected data.
- Corruption of application-level protocol framing between the application and Valkey.
- Misleading or incorrect data being returned to the application, potentially influencing business logic.
- Undermining of data integrity guarantees, leading to subtle bugs or security checks being bypassed due to corrupted responses.
- Potential information exposure if injected responses cause the application to log or display internal data in unexpected ways.
General mitigation guidance
Effective mitigation centers on hardening error handling and response construction boundaries:
- Ensure that error messages and script outputs are treated as untrusted text and are strictly encoded or sanitized before being placed on the wire.
- Enforce clear response framing rules so that special characters (including null bytes) cannot escape their intended field or segment.
- Prefer protocols and client libraries that do not multiplex different security principals over the same low-level Valkey connection, reducing cross-user impact if response corruption occurs.
- Apply defense-in-depth by validating and constraining Lua script inputs and outputs, limiting the ability of untrusted users to create arbitrary or unexpected error messages.
- Use least-privilege principles for scripting access, reserving script execution for trusted components and restricting direct script access from low-trust clients.
How teams detect issues like this
Organizations can detect and monitor for this class of issue using:
- Static analysis and code review: Look for error handling paths that concatenate raw script output or error text directly into protocol responses without sanitization or encoding, especially where null characters or control characters are possible.
- Protocol-level testing: Use fuzzing or integration tests that send Lua scripts designed to generate unusual error messages (including embedded nulls and control characters) and validate that responses remain well-framed and parseable.
- Runtime monitoring: Instrument Valkey clients and proxies to detect malformed or unexpected response frames, such as truncated messages, unexpected delimiters, or inconsistent length fields.
- Security gateways and automated tools: Employ reverse proxies or security gateways with protocol-awareness that can flag anomalous responses and apply generic output sanitization policies where feasible.

