@@ -2568,22 +2568,36 @@ This weakness can lead to vulnerabilities. For example:
2568
2568
For example, the widely-used Node.js MySQL library
2569
2569
[mysqljs/mysql](https://github.com/mysqljs/mysql)
2570
2570
as of early 2022 is exploitable through its parameterized library
2571
- if a JavaScript object can be sent as a parameter to it
2571
+ if a JavaScript object can be sent as a parameter to it.
2572
2572
(see
2573
2573
[Finding an Authorization Bypass on my Own Website](https://maxwelldulin.com/BlogPost?post=9185867776) by Maxwell Dulin (ꓘ)).
2574
2574
2575
- That last issue for application-side processing (that
2576
- complex data types may not always be escaped properly)
2577
- can be a *huge* challenge to solve:
2578
-
2579
- 1. The safe solution is to disable processing of complex types
2580
- (types other than numbers and strings) by the library.
2575
+ That last issue for application-side processing
2576
+ (that complex data types may not always be escaped properly)
2577
+ can be confusing, so an example may help.
2578
+ In the Node.js mysqljs/mysql library,
2579
+ imagine that an attacker manages to provide
2580
+ the JavaScript *object* `{password = 1}` as the password parameter
2581
+ and it's used in the SQL query
2582
+ `SELECT * FROM accounts WHERE username = ? AND password = ?`.
2583
+ The library will internally expand the expression after `AND`
2584
+ into `password = ``password`` = 1`.
2585
+ The MYSQL DBMS will interpret `password = ``password``` as 1 (true),
2586
+ and then determine that `1 = 1` is true.
2587
+ Thus result: this expression will *always* true.
2588
+ This incorrect escaping of a complex data type
2589
+ is enough to completely bypass authentication in some situations.
2590
+
2591
+ Unfortunately, this last issue can be a challenge to solve:
2592
+
2593
+ 1. The safe solution is to make sure that complex data types
2594
+ (types other than numbers and strings) are not expanded by the library
2595
+ unless the developer specifically marks them as allowed.
2581
2596
This may be impractical if the application already depends on this,
2582
- and there may not be a way to fully disable it .
2597
+ and the library might not provide a way to fully disable the functionality .
2583
2598
For example, mysqljs/mysql allows setting `stringifyObjects` to true
2584
2599
when calling `mysql.createConnection`, but while this can help,
2585
- this only disables
2586
- escaping generic Objects - it does not
2600
+ this only disables escaping generic Objects - it does not
2587
2601
disable other complex data types such as arrays.
2588
2602
2. The general solution is to verify every type before calling the library.
2589
2603
For example, require that all data expected to be strings must be strings.
0 commit comments