Fixed CRLF command injection / smuggling in AbstractAggregateConnection::write() (#1719)

This commit is contained in:
Vladyslav Vildanov
2026-09-11 17:58:18 +03:00
committed by GitHub
parent 3ffaf10e99
commit 8ee8993eb7
11 changed files with 75 additions and 402 deletions
@@ -1459,41 +1459,40 @@ repl_backlog_histlen:12978
}
/**
* Regression guard for CVE GHSA-w6f5-v2h6-g786 (CWE-93): an aggregate connection
* must refuse a raw, already-serialized command buffer instead of re-splitting it
* on "\r\n". The old parser ignored RESP bulk-length prefixes, so CRLF sequences
* smuggled into a value or key were parsed as extra commands and routed to a node.
*
* @group disconnected
*/
public function testWrite(): void
public function testWriteRejectsRawCommandBuffer(): void
{
$command1 = new Command\Redis\Json\JSONGET();
$command1->setArguments(['arg1']);
$command2 = new Command\Redis\Json\JSONGET();
$command2->setArguments(['arg2']);
$command3 = new Command\Redis\Json\JSONGET();
$command3->setArguments(['arg3']);
// A single command whose key carries a smuggled FLUSHDB payload; the old code
// would have re-parsed and routed the FLUSHDB, this must route nothing.
$command = new Command\Redis\Json\JSONGET();
$command->setArguments(["slug:PAD\r\n*1\r\n\$7\r\nFLUSHDB"]);
$master = $this->getMockConnection('tcp://127.0.0.1:6379?role=master');
$slave1 = $this->getMockConnection('tcp://127.0.0.1:6380?role=slave');
$slave1
$master
->expects($this->never())
->method('write');
$master
->expects($this->exactly(3))
->method('write')
->withConsecutive(
[$command1->serializeCommand()],
[$command2->serializeCommand()],
[$command3->serializeCommand()]
);
$slave1
->expects($this->never())
->method('write');
$replication = new MasterSlaveReplication();
$replication->add($master);
$replication->add($slave1);
$replication->write($command1->serializeCommand() . $command2->serializeCommand() . $command3->serializeCommand());
$this->expectException('Predis\NotSupportedException');
$this->expectExceptionMessage('Aggregate connections cannot write a raw command buffer');
$replication->write($command->serializeCommand());
}
/**