Skip to content

Commit bb713ac

Browse files
authored
Merge pull request #51 from clue-labs/multi
Do not support multiple statements for security and API reasons
2 parents 2ccca8a + 0edb22f commit bb713ac

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
@@ -425,8 +425,6 @@ public function authenticate()
425425
Constants::CLIENT_INTERACTIVE |
426426
Constants::CLIENT_TRANSACTIONS |
427427
Constants::CLIENT_SECURE_CONNECTION |
428-
Constants::CLIENT_MULTI_RESULTS |
429-
Constants::CLIENT_MULTI_STATEMENTS |
430428
Constants::CLIENT_CONNECT_WITH_DB;
431429

432430
$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
@@ -460,7 +460,7 @@ public function testSimpleSelect()
460460
$loop->run();
461461
}
462462

463-
public function testInvalidSelect()
463+
public function testInvalidSelectShouldFail()
464464
{
465465
$loop = \React\EventLoop\Factory::create();
466466

@@ -478,6 +478,22 @@ public function testInvalidSelect()
478478
$loop->run();
479479
}
480480

481+
public function testInvalidMultiStatementsShouldFailToPreventSqlInjections()
482+
{
483+
$loop = \React\EventLoop\Factory::create();
484+
485+
$connection = new \React\MySQL\Connection($loop, $this->getConnectionOptions());
486+
$connection->connect(function () {});
487+
488+
$connection->query('select 1;select 2;', function ($command, $conn) {
489+
$this->assertEquals(true, $command->hasError());
490+
$this->assertContains("You have an error in your SQL syntax", $command->getError()->getMessage());
491+
});
492+
493+
$connection->close();
494+
$loop->run();
495+
}
496+
481497
public function testEventSelect()
482498
{
483499
$this->expectOutputString('result.result.results.end.');

0 commit comments

Comments
 (0)