You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the process of getting this text ready to transfer
to the "real" course I found these nits in the SQL injection
section, so let's get them fixed now.
Signed-off-by: David A. Wheeler <[email protected]>
Copy file name to clipboardExpand all lines: secure_software_development_fundamentals.md
+8-7Lines changed: 8 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2372,7 +2372,7 @@ The intent is clear; if **search_lastname** has the value **Fred**, then the dat
2372
2372
2373
2373
There are many ways to trigger SQL injection attacks; attackers can insert single quotes (used to surround constant character data), semicolons (which act as command separators), “**--**” which is a comment token, and so on. This is not a complete list; different database systems interpret different characters differently. For example, double quotes are often metacharacters, but with different meanings. Even different versions of the *same* database system, or different configurations, can cause changes to how the characters are interpreted. We already know we should not create a list of “bad” characters, because that is a denylist. We could create an allowlist of characters we know are not metacharacters and then escape the rest, but this process is hard to do correctly for SQL.
2374
2374
2375
-
Don't concatenate strings to create a DBMS query, because that is insecure by default. That includes using format strings, string interpolations, string templates, and all other mechanism that simply concatenate text. For example, the same vulnerabilities happen if you use Python formatted string literals (f-strings such as <tt>f'{year}-{month}'</tt>), Python's `.format` method, JavaScript's template strings (<tt>`${year}-${month}`</tt>), PHP's string interpolations (<tt>"${year}-${month}"</tt>), Ruby string interpolation (<tt>"#{year}-#{month}"</tt>), Go (string) templates, or any other string-based template or formatting language, Remember, we want to try to use a routine that is easy to use securely, and all of these are dangerous by default when used to create commands like SQL comamnds.
2375
+
Don't concatenate strings to create a DBMS query, because that is insecure by default. That includes using format strings, string interpolations, string templates, and all other mechanism that simply concatenate text. For example, the same vulnerabilities happen if you use Python formatted string literals (f-strings such as <tt>f'{year}-{month}'</tt>), Python's `.format` method, JavaScript's template strings (<tt>`${year}-${month}`</tt>), PHP's string interpolations (<tt>"${year}-${month}"</tt>), Ruby string interpolation (<tt>"#{year}-#{month}"</tt>), Go (string) templates, or any other string-based template or formatting language. Remember, we want to try to use a routine that is easy to use securely, and all of these are dangerous by default when used to create commands like SQL commands.
2376
2376
2377
2377
Many developers try to fix this in an unwise way by calling an escape routine on every value, e.g., like this:
2378
2378
@@ -2393,7 +2393,7 @@ but experience shows that the mistake *will* happen.
2393
2393
2394
2394
🔔 SQL injection is a special case of injection attacks, and we have already noted that injection attacks are so common and dangerous that they are 2017 OWASP Top 10 #1. SQL injection specifically is such a common cause of security vulnerabilities that just SQL injection is 2021 CWE Top 25 #6 and 2019 CWE Top 25 #6. SQL injection is also identified as [CWE-89](https://cwe.mitre.org/data/definitions/89.html), *Improper Neutralization of Special Elements used in an SQL Command (‘SQL Injection’)*.
2395
2395
2396
-
Remember, we want to try to use an approach that is easy to use correctly - it needs to be secure by default.
2396
+
Again, we want to try to use an approach that is easy to use correctly - it needs to be secure by default.
2397
2397
2398
2398
For databases, there are well-known solutions that are far easier to use securely.
2399
2399
@@ -2459,7 +2459,7 @@ APIs and placeholder syntax vary by programming language, library, and database.
2459
2459
Here we'll see some examples.
2460
2460
2461
2461
In Python there are several libraries that interface to databases.
2462
-
Many of them implement the Python Database API Specification v2.0,
2462
+
Many of them implement the Python Database API Specification v2.0
2463
2463
([PEP 249](https://peps.python.org/pep-0249/)),
2464
2464
whose `execute` and `executemany` methods implement parameterized statements.
2465
2465
The library's placeholder syntax is reported by its `paramstyle` attribute.
@@ -2519,7 +2519,7 @@ parameterized statements are processed directly
2519
2519
within the database management system (DBMS),
2520
2520
aka "DBMS-side" parameter processing.
2521
2521
This approach is often called "server-side" since many DBMSs use a
2522
-
client/server architecture where the client connect over a network
2522
+
client/server architecture where the client connects over a network
2523
2523
to a server-side DBMS.
2524
2524
There are many advantages to DBMS-side parameter processing.
2525
2525
The DBMS has the current information on escaping rules
@@ -2529,6 +2529,7 @@ and expected data types.
2529
2529
Perhaps most importantly, the DBMS developers will typically have
2530
2530
security experts review this part of the DBMS system.
2531
2531
However, DBMS-side parameter processing can require more effort to
2532
+
implement, so some libraries use
2532
2533
"application-side" parameter processing instead.
2533
2534
2534
2535
"Application-side" parameter processing occurs when the parameter escaping
@@ -2569,8 +2570,8 @@ This weakness can lead to vulnerabilities. For example:
2569
2570
complex types into a library that cannot always handle them securely.
2570
2571
For example, the widely-used Node.js MySQL library
2571
2572
[mysqljs/mysql](https://github.com/mysqljs/mysql)
2572
-
as of early 2022 is exploitable through its parameterized library
2573
-
if a JavaScript object can be sent as a parameter to it.
2573
+
as of early 2022 is often exploitable through its parameterized library
2574
+
*if* a JavaScript object can be sent as a parameter to it
2574
2575
(see
2575
2576
[Finding an Authorization Bypass on my Own Website](https://maxwelldulin.com/BlogPost?post=9185867776) by Maxwell Dulin (ꓘ)).
2576
2577
@@ -2586,7 +2587,7 @@ The library will internally expand the expression after `AND`
2586
2587
into `password = ``password`` = 1`.
2587
2588
The MYSQL DBMS will interpret `password = ``password``` as 1 (true),
2588
2589
and then determine that `1 = 1` is true.
2589
-
Thus result: this expression will *always* true.
2590
+
The result: this expression will *always* be true.
2590
2591
This incorrect escaping of a complex data type
2591
2592
is enough to completely bypass authentication in some situations.
0 commit comments