-
Notifications
You must be signed in to change notification settings - Fork 78
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
Add API for unquoted escaped strings #39
Comments
No, we cannot do that. This module did that a long time ago and a security CVE was filed against it and we had to remove it. You need to include the % inside the string you want to escape: const result = mysql.query('SELECT * FROM table WHERE description LIKE ? LIMIT 3', [`%${req.query.q}%`]);
Pull request #29 is working towards this, so if that works for you, then we are already working towards it, so this would be a duplicate of that. And since the mysql module takes just plan queries, you can also alternatively not use this module at all and instead use any escaping module you like, for example https://hiddentao.com/squel/ |
Hello Doug. Much thanks for addressing my questions.
Do you know the CVE # off-hand? I'm curious as to how what is essentially a labour-saving utility routine can have a security issue, and whether that applies to how I'm doing it too (assuming the people calling it understood what it did and were using it correctly—if CVEs can be filed because users are abusing the tools they have, we need to file one against the concept of a memory address!).
I would have assumed (had I thought of doing it this way) that given its special meaning, percent would be one of the characters that got escaped, and so this technique would not work. I see now that it is not escaped. It seems this library is not aware of whether the string to be escaped is intended for use as a plain string, or LIKE or RLIKE value (seems similar to the
Good point :-) But I would rather help improve the defaults if I can.
That issue is quite long and I don't have time today to read through it, so I can't yet confirm if it is a duplicate. |
That's right, because this library is not a full sql constructor like https://hiddentao.com/squel/ and is not designed to be; one already exists and it is https://hiddentao.com/squel/ :) The only difference is at the sql langauge level and at that level there are only two things: values and identifiers. The LIKE etc. takes a value, and even characters like the % can be altered within your sql statement, so without this library fully building out your entire statement, then it would not have any idea what the wildcard chars are for that particular string. I think, based on what you're describing, you would be much happier using the https://hiddentao.com/squel/ module over this module anyway, as it is a higher level abstraction, which seems to me what you're desiring here. |
Another thing to note is that this module is also made to function with modules like squel. For example their toParam() method https://hiddentao.com/squel/#parameters produces the two values to pass into this module format. It includes the % character in the array and not in the sql as well, so a change here would break a lot of integration with mysql module and all the various sql formatting / orm libraries. I'm not saying there cannot be a change here, but ideally they shouldn't all break all of a sudden when they are very useful libs. Probably should open a dialog with all these module as part of initial seeking to determine how to keep them all working together. |
Parties talking to each other never created new problems :-) |
My first attempt to use Node's mysql package went like this [paraphrasing code]:
This worked fine. My second attempt to use Node's mysql package went somewhat downhill:
I traced the problem back to this package. It can be characterised as one of two things:
As an aside, I looked at the code of this package and all three points of return from escapeString() duplicitously wrap the escaped string in quote characters, à la
return "'" + val + "'";
— you ought to refactor to have this happen in a single place, e.g.:This removes duplication and reduces the chances of bugs being introduced (e.g. a new return point being added but forgetting to wrap in quotes).
The text was updated successfully, but these errors were encountered: