Skip to content

Commit 830e02e

Browse files
Add specific example of bad expansion
I hate to add even more detail, but the description is so abstract that it's hard to understand without a specific example. So, here's an example. Signed-off-by: David A. Wheeler <[email protected]>
1 parent 4b12dd5 commit 830e02e

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

secure_software_development_fundamentals.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,22 +2568,36 @@ This weakness can lead to vulnerabilities. For example:
25682568
For example, the widely-used Node.js MySQL library
25692569
[mysqljs/mysql](https://github.com/mysqljs/mysql)
25702570
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.
25722572
(see
25732573
[Finding an Authorization Bypass on my Own Website](https://maxwelldulin.com/BlogPost?post=9185867776) by Maxwell Dulin (ꓘ)).
25742574

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.
25812596
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.
25832598
For example, mysqljs/mysql allows setting `stringifyObjects` to true
25842599
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
25872601
disable other complex data types such as arrays.
25882602
2. The general solution is to verify every type before calling the library.
25892603
For example, require that all data expected to be strings must be strings.

0 commit comments

Comments
 (0)