Skip to content

Do not support multiple statements for security and API reasons #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ interface ConnectionInterface
*
* function (QueryCommand $cmd, ConnectionInterface $conn): void
*
* The given `$sql` parameter MUST contain a single statement. Support
* for multiple statements is disabled for security reasons because it
* could allow for possible SQL injection attacks and this API is not
* suited for exposing multiple possible results.
*
* @return QueryCommand|null Return QueryCommand if $callback not specified.
* @throws Exception if the connection is not initialized or already closed/closing
*/
Expand Down
2 changes: 0 additions & 2 deletions src/Protocal/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ public function authenticate()
Constants::CLIENT_INTERACTIVE |
Constants::CLIENT_TRANSACTIONS |
Constants::CLIENT_SECURE_CONNECTION |
Constants::CLIENT_MULTI_RESULTS |
Constants::CLIENT_MULTI_STATEMENTS |
Constants::CLIENT_CONNECT_WITH_DB;

$packet = pack('VVc', $clientFlags, $this->maxPacketSize, $this->charsetNumber)
Expand Down
18 changes: 17 additions & 1 deletion tests/ResultQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testSimpleSelect()
$loop->run();
}

public function testInvalidSelect()
public function testInvalidSelectShouldFail()
{
$loop = \React\EventLoop\Factory::create();

Expand All @@ -122,6 +122,22 @@ public function testInvalidSelect()
$loop->run();
}

public function testInvalidMultiStatementsShouldFailToPreventSqlInjections()
{
$loop = \React\EventLoop\Factory::create();

$connection = new \React\MySQL\Connection($loop, $this->getConnectionOptions());
$connection->connect(function () {});

$connection->query('select 1;select 2;', function ($command, $conn) {
$this->assertEquals(true, $command->hasError());
$this->assertContains("You have an error in your SQL syntax", $command->getError()->getMessage());
});

$connection->close();
$loop->run();
}

public function testEventSelect()
{
$this->expectOutputString('result.result.results.end.');
Expand Down