Skip to content

Clarify the documentation for multiStatement in the README #1206

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

Closed
wants to merge 1 commit into from
Closed

Clarify the documentation for multiStatement in the README #1206

wants to merge 1 commit into from

Conversation

arp242
Copy link

@arp242 arp242 commented Apr 22, 2021

The current documentation for multiStatements in the README says:

Allow multiple statements in one query. While this allows batch
queries, it also greatly increases the risk of SQL injections.

However, I can't really find any reference to the risk of SQL
injections. This sets the clientMultiStatements flag (or
CLIENT_MULTI_STATEMENTS in the C API).

This comment was added in #411, but without much explanation, and I
can't find anything in e.g. #66 or other issues either.

The documentation for MySQL1 or MariaDB2 doesn't warn for SQL
injections, and after some internet searching the only reference I found
was in the PHP Docs3:

The API functions mysqli::query() and mysqli::real_query() do
not set a connection flag necessary for activating multi queries
in the server. An extra API call is used for multiple statements
to reduce the damage of accidental SQL injection attacks. An
attacker may try to add statements such as ; DROP DATABASE mysql
or ; SELECT SLEEP(999).

So I assume this is what this comment refers to.

This clarifies the comment, since the current phrasing is somewhat
unclear and it took me a bit to find out what exactly this refers to.

Description

Please explain the changes you made here.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

The current documentation for multiStatements in the README says:

	Allow multiple statements in one query. While this allows batch
	queries, it also greatly increases the risk of SQL injections.

However, I can't really find any reference to the risk of SQL
injections. This sets the clientMultiStatements flag (or
CLIENT_MULTI_STATEMENTS in the C API).

This comment was added in #411, but without much explanation, and I
can't find anything in e.g. #66 or other issues either.

The documentation for MySQL[1] or MariaDB[2] doesn't warn for SQL
injections, and after some internet searching the only reference I found
was in the PHP Docs[3]:

	The API functions mysqli::query() and mysqli::real_query() do
	not set a connection flag necessary for activating multi queries
	in the server. An extra API call is used for multiple statements
	to reduce the damage of accidental SQL injection attacks. An
	attacker may try to add statements such as ; DROP DATABASE mysql
	or ; SELECT SLEEP(999).

So I assume this is what this comment refers to.

This clarifies the comment, since the current phrasing is somewhat
unclear and it took me a bit to find out what exactly this refers to.

[1]: https://dev.mysql.com/doc/c-api/8.0/en/c-api-multiple-queries.html
[2]: https://mariadb.com/kb/en/mysql_real_connect/
[3]: https://www.php.net/manual/de/mysqli.quickstart.multiple-statement.php
@methane
Copy link
Member

methane commented Apr 23, 2021

IMO, both of current doc and proposed doc is overestimate the effect of multi statement.

If SQL injection is possible, there are some ways to attack it without multiple statement. (e.g. OR 1=1, OR 1 IN SELECT (...), etc).
So allowing multiple statement doesn't increase risk/damage greatly. It only allows injection simple/easy.

Actually speaking, MySQL security guideline don't recommend to disable muti queries.
https://dev.mysql.com/doc/refman/8.0/en/secure-client-programming.html

On the other hand, prepared statement doesn't accept multi-statement is more important information. It should be referred with interpolateParams option.

@arp242
Copy link
Author

arp242 commented Apr 23, 2021

Yeah, I agree. Both the PostgreSQL pq and go-sqlite3 driver just allow multi statements without fuss; AFAIK there isn't even a way to turn if off. But I figured that clarifying this was the smaller change.

I can just remove it?

@methane
Copy link
Member

methane commented May 2, 2023

I can just remove it?

Yes, please.

arp242 added a commit to arp242/mysql that referenced this pull request May 16, 2023
I can't really find any reference to the risk of SQL injections. This
sets the clientMultiStatements flag (or CLIENT_MULTI_STATEMENTS in the C
API).

This comment was added in go-sql-driver#411, but without much explanation, and I
can't find anything in e.g. go-sql-driver#66 or other issues either.

The documentation for MySQL[1] or MariaDB[2] doesn't warn for SQL
injections, and after some internet searching the only reference I found
was in the PHP Docs[3]:

	The API functions mysqli::query() and mysqli::real_query() do
	not set a connection flag necessary for activating multi queries
	in the server. An extra API call is used for multiple statements
	to reduce the damage of accidental SQL injection attacks. An
	attacker may try to add statements such as ; DROP DATABASE mysql
	or ; SELECT SLEEP(999).

So I assume this is what this comment refers to.

This removes the comment, as discussed in go-sql-driver#1206.

[1]: https://dev.mysql.com/doc/c-api/8.0/en/c-api-multiple-queries.html
[2]: https://mariadb.com/kb/en/mysql_real_connect/
[3]: https://www.php.net/manual/de/mysqli.quickstart.multiple-statement.php
@arp242
Copy link
Author

arp242 commented May 16, 2023

I deleted the original fork, guess I forgot I had a PR on it, and it seems I can no longer edit it now :-/ I had to open a new PR for this: #1430

@arp242 arp242 closed this May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants