Skip to content

Commit 044f610

Browse files
Clean up application-side text
This example includes some backquotes, which are both part of the text but are also used in markdown to indicate teletype font (tt). This led to problems. Fix that, and while we're at it, clarify the text. This is challenging to explain, so adding a few asides should make it easier to understand. Signed-off-by: David A. Wheeler <[email protected]>
1 parent e9deefb commit 044f610

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

secure_software_development_fundamentals.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2597,20 +2597,26 @@ can be confusing, so an example may help.
25972597
In the Node.js mysqljs/mysql library,
25982598
imagine that an attacker manages to provide
25992599
the JavaScript *object* `{password = 1}` as the password parameter
2600-
and it's used in the SQL query
2601-
`SELECT * FROM accounts WHERE username = ? AND password = ?`.
2600+
(this is not just a string, but an actual JavaScript object).
2601+
Now imagine that this object is used in the SQL query
2602+
<tt>SELECT * FROM accounts WHERE username = ? AND password = ?</tt>
2603+
(note that this is parameterized).
26022604
The library will internally expand the expression after `AND`
2603-
into `password = ``password`` = 1`.
2604-
The MYSQL DBMS will interpret `password = ``password``` as 1 (true),
2605-
and then determine that `1 = 1` is true.
2605+
into <tt>password = &#96;password&#96; = 1</tt> because the library does simple
2606+
text replacement of the second `?`, without noticing that a JavaScript object
2607+
doesn't make sense in the context of this query (a string or number would
2608+
be expected here).
2609+
The MYSQL DBMS will interpret <tt>password = &#96;password&#96;</tt>
2610+
as 1 (true), and then determine that `1 = 1` is true.
26062611
The result: this expression will *always* be true.
26072612
This incorrect escaping of a complex data type
26082613
is enough to completely bypass authentication in some situations.
26092614

26102615
Unfortunately, this last issue can be a challenge to solve:
26112616

26122617
1. The safe solution is to make sure that complex data types
2613-
(types other than numbers and strings) are not expanded by the library
2618+
(types other than numbers and strings) are not expanded by
2619+
application-side libraries
26142620
unless the developer specifically marks them as allowed.
26152621
This may be impractical if the application already depends on this,
26162622
and the library might not provide a way to fully disable the functionality.

0 commit comments

Comments
 (0)