Skip to content

Commit 0edb22f

Browse files
committed
Do not support multiple statements for security and API reasons
1 parent d1ab545 commit 0edb22f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/ConnectionInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ interface ConnectionInterface
3232
*
3333
* function (QueryCommand $cmd, ConnectionInterface $conn): void
3434
*
35+
* The given `$sql` parameter MUST contain a single statement. Support
36+
* for multiple statements is disabled for security reasons because it
37+
* could allow for possible SQL injection attacks and this API is not
38+
* suited for exposing multiple possible results.
39+
*
3540
* @return QueryCommand|null Return QueryCommand if $callback not specified.
3641
* @throws Exception if the connection is not initialized or already closed/closing
3742
*/

src/Protocal/Parser.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ public function authenticate()
406406
Constants::CLIENT_INTERACTIVE |
407407
Constants::CLIENT_TRANSACTIONS |
408408
Constants::CLIENT_SECURE_CONNECTION |
409-
Constants::CLIENT_MULTI_RESULTS |
410-
Constants::CLIENT_MULTI_STATEMENTS |
411409
Constants::CLIENT_CONNECT_WITH_DB;
412410

413411
$packet = pack('VVc', $clientFlags, $this->maxPacketSize, $this->charsetNumber)

tests/ResultQueryTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function testSimpleSelect()
104104
$loop->run();
105105
}
106106

107-
public function testInvalidSelect()
107+
public function testInvalidSelectShouldFail()
108108
{
109109
$loop = \React\EventLoop\Factory::create();
110110

@@ -122,6 +122,22 @@ public function testInvalidSelect()
122122
$loop->run();
123123
}
124124

125+
public function testInvalidMultiStatementsShouldFailToPreventSqlInjections()
126+
{
127+
$loop = \React\EventLoop\Factory::create();
128+
129+
$connection = new \React\MySQL\Connection($loop, $this->getConnectionOptions());
130+
$connection->connect(function () {});
131+
132+
$connection->query('select 1;select 2;', function ($command, $conn) {
133+
$this->assertEquals(true, $command->hasError());
134+
$this->assertContains("You have an error in your SQL syntax", $command->getError()->getMessage());
135+
});
136+
137+
$connection->close();
138+
$loop->run();
139+
}
140+
125141
public function testEventSelect()
126142
{
127143
$this->expectOutputString('result.result.results.end.');

0 commit comments

Comments
 (0)