News for hackers. Stuff that matters.
Re:Finding an authorization bypass on my own website by hn_throwaway_99 on Saturday March 05, 2022 @07:51PM (#30573776)
Developers shouldn't have to think about these things. If I'm doing any sort of string interpolation, whether it be in a SQL statement like this or in something like a log or print formatter, I should be able to put whatever the f I want into the value, without checking it. That's the whole point of using interpolated statements like this in the first place: it should be safe to run (but may throw something like a type error in the DB) regardless of what is stuffed in the value.

This is solely a mysqljs bug.

Re:Finding an authorization bypass on my own website by Merad on Saturday March 05, 2022 @08:29PM (#30574036)
If you use any strongly typed language with a halfway decent framework you _don't_ have to think about this because the request will automatically be validated and rejected for invalid input before your code is ever hit.
Re:Finding an authorization bypass on my own website by nicoburns on Saturday March 05, 2022 @09:04PM (#30574295)
That’s also true of a decent JS library. The problem here being that the library wasn’t decent.

A library in a strongly typed language would still need to use parameterised queries or escape the strings just like a JS library. And it would be just as easy or difficult to have an incorrect sanitising function.

In fact, the specified string is not invalid input, it would be perfectly valid to store backticks in a string field in MySQL. They just need to be correctly escaped before being submitted to the database.

Re:Finding an authorization bypass on my own website by hn_throwaway_99 on Saturday March 05, 2022 @09:42PM (#30574517)
That's not really true. Pretty much every DB driver I know, in every language, will take prepared statement values that are any valid DB datatype: strings, ints, decimals, etc., and, importantly, JSON values because most DBs now support JSON. Many JS DB frameworks will take any JS object and convert it to a JSON string because that's obviously a trivial operation (it is "JavaScript Object Notation" after all).

Again, the only bug here is the completely incorrect serialization that mysqljs does.

Re:Finding an authorization bypass on my own website by Merad on Saturday March 05, 2022 @11:04PM (#30574934)
You're missing my point because you're focused on the database query. I'm talking about the web application framework. If this was written in Asp.Net, for example, the password field would be declared as a string and the data binding code within Asp.Net would validate that the field was in fact a string as part of instantiating a model for the strongly typed request body. If someone passed in an object for that field your code for the endpoint, including all of the database interaction, would never be called because the framework would automatically return a 400 response when data binding failed.
Re:Finding an authorization bypass on my own website by thinkharderdev on Sunday March 06, 2022 @06:31AM (#30576788)
I don't think it would actually be possible to use proper prepared statements for a "feature" like this. The whole point is that query is built dynamically from any JSON object. So you could, strictly speaking, build a prepared statement dynamically but you would have the exact same bug.