mirror of
https://github.com/predis/predis.git
synced 2026-11-29 07:32:05 +00:00
Fixed CRLF command injection / smuggling in AbstractAggregateConnection::write() (#1719)
This commit is contained in:
committed by
GitHub
parent
3ffaf10e99
commit
8ee8993eb7
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user