A fun alternative would be to hex encode all strings (X'...hex bytes...'), and this whole problem magically goes away.
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I prefer this not to be strictly tied to backslash escaping, as other databases (such as PostgreSQL) may implement additional means of escaping. Also, I don't think that any interaction with the Connection setting is a good idea, in particular when tampering with such settings. I believe that the suggestion involving calls to "SET @@SESSION.sql_mode..." originates from a local use-case, and it will probably break in more general contexts, e.g. in setups that other users may have.
Hello,
On Mon, Oct 6, 2014 at 4:12 AM, Lukas Eder <lukas...@gmail.com> wrote:
> Here's a little feedback. While I understand that this is an annoying issue
> to MySQL users, I do think that in the long run, backslash escaping should
> be avoided in MySQL for database interoperability reasons. I trust that
> MySQL is going to start enforcing a stricter SQL standards compatibility in
> the future - this was also Oracle's official position mentioned at the
> Oracle Open World conference. I will be blogging about this pretty soon.
I agree MySQL should get their act together and stick to the standard.
A coworker however brought up a concern. Given that MySQL's default
behavior is to escape backslashes, he thinks not escaping backslashes
might be less tested and have issues. For example, he pointed me to:
http://bazaar.launchpad.net/~mysql/connectorj/5.1/view/head:/src/com/mysql/jdbc/PreparedStatement.java#L4781
I don't have enough context to tell how much of an issue this is going
to be, but it's something to keep in mind.
> For the time being, this is a real issue, of course, and we'll implement
> #3000 eventually, which allows for alternative string escaping modes:
> https://github.com/jOOQ/jOOQ/issues/3000
:)
> I prefer this not to be strictly tied to backslash escaping, as other
> databases (such as PostgreSQL) may implement additional means of escaping.
Do you want a pull request to support PostgreSQL's escaping?
> Also, I don't think that any interaction with the Connection setting is a
> good idea, in particular when tampering with such settings. I believe that
> the suggestion involving calls to "SET @@SESSION.sql_mode..." originates
> from a local use-case, and it will probably break in more general contexts,
> e.g. in setups that other users may have.
Agree. I was going for something that would be fool-proof and do the
safe thing by default. We can revisit this in the future.
Thanks for fixing this!
Agree. I was going for something that would be fool-proof and do the
safe thing by default. We can revisit this in the future.
Thanks for fixing this!We certainly should. I really wonder if there is any way through standard JDBC API to access the NO_BACKSLASH_ESCAPES property. I haven't found it in Connection.getClientInfo(), nor in INFORMATION_SCHEMA.SESSION_VARIABLES... I also don't find it in @@SESSION.sql_mode
> It looks like the setting is only exposed if it is active. The variable can
> be obtained from SHOW VARIABLES LIKE 'sql_mode', or via SELECT
> @@SESSION.sql_mode FROM DUAL. I suspect that if we support an AUTO mode, we
> would need to check this flag prior to query execution (lazily, only the
> first time we actually encounter an inlined string variable).
batch queries also end up needing this. Do you know what other queries
or features indirectly inline?
> Another option would be to add another setting value called DEFAULT, which
> means OFF for most databases and ON for MySQL / MariaDB. If the setting is
> not specified, we'll actually use this DEFAULT as it aligns with MySQL's own
> default. This would then be the sensible default for new users, to keep them
> from running into this issue when they start using jOOQ.
>
> What do you think?
On one hand, I like the idea of having the default be to escape
backslashes for MySQL users. Besides aligning jOOQ with the database's
default behavior, it reduces the impact of having the wrong setting
(mangled data instead of a SQL injection). On the other hand, it might
impact jOOQ users who turned NO_BACKSLASH_ESCAPES and aren't careful
when upgrading to the newer version.
Sorry, I take that back. I just looked into how dollar quoted strings
work and there is probably no safe way to sanitize such an input.
Thankfully, the issue isn't the same as backslash, so it's best to
simply ignore dollar quoted strings.
2014-10-07 19:49 GMT+02:00 Alok Menghrajani <al...@squareup.com>:> It looks like the setting is only exposed if it is active. The variable can
> be obtained from SHOW VARIABLES LIKE 'sql_mode', or via SELECT
> @@SESSION.sql_mode FROM DUAL. I suspect that if we support an AUTO mode, we
> would need to check this flag prior to query execution (lazily, only the
> first time we actually encounter an inlined string variable).
batch queries also end up needing this. Do you know what other queries
or features indirectly inline?I'm not sure what you mean...? How do batch queries need this?
create table jooqtest(title varchar(255), primary key(title));
insert into jooqtest (title) values ("hello"),("world"),("foo"),("bar");
Yes, this is why we usually keep a section for incompatible changes in the release notes. This change will not be shipped with patch releases, only with a minor release.From how I've perceived the discussion between Morgan Tocker and Bill Karwin (on the previously linked blog article by Morgan), I suspect that few people actually turned that flag on. So the risk / benefit ratio is probably in favour of breaking compatibility this time - in particular given that the setNString() method that you've pointed out to me also assumes that the flag is not set.
On Tue, Oct 7, 2014 at 11:23 PM, Lukas Eder <lukas...@gmail.com> wrote:2014-10-07 19:49 GMT+02:00 Alok Menghrajani <al...@squareup.com>:> It looks like the setting is only exposed if it is active. The variable can
> be obtained from SHOW VARIABLES LIKE 'sql_mode', or via SELECT
> @@SESSION.sql_mode FROM DUAL. I suspect that if we support an AUTO mode, we
> would need to check this flag prior to query execution (lazily, only the
> first time we actually encounter an inlined string variable).
batch queries also end up needing this. Do you know what other queries
or features indirectly inline?I'm not sure what you mean...? How do batch queries need this?Sorry, I wasn't very clear. Given the following table:
create table jooqtest(title varchar(255), primary key(title));
insert into jooqtest (title) values ("hello"),("world"),("foo"),("bar");And a batch query:create.batch(create.update(table("jooqtest")).set(field("title"), value("aaa")).where(field("title").eq("something\\' or 1=1 ORDER BY title DESC LIMIT 1-- ")),create.update(table("jooqtest")).set(field("title"), value("bbb")).where(field("title").eq("whatever"))).execute();
In theory, the batch query shouldn't do anything. However, the batch request is prone to SQLi and one of the rows (in this case "hello" which is the first row) gets overwritten with "aaa".
I'm assuming the batch feature internally calls inline.
My question was: are there other types of queries or other jOOQ features which call inline?
Yes, this is why we usually keep a section for incompatible changes in the release notes. This change will not be shipped with patch releases, only with a minor release.From how I've perceived the discussion between Morgan Tocker and Bill Karwin (on the previously linked blog article by Morgan), I suspect that few people actually turned that flag on. So the risk / benefit ratio is probably in favour of breaking compatibility this time - in particular given that the setNString() method that you've pointed out to me also assumes that the flag is not set.:) for favoring security over backwards compatibility!
--