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
The SQL injection section was *far* larger than any other section.
This splits up the units into much smaller units closer to
the usual unit size.
Signed-off-by: David A. Wheeler <[email protected]>
\>\>Select all the warning signs suggesting that a SQL injection is especially likely:<<
2432
+
2433
+
[x] A SQL statement is being created via string concatenation.
2434
+
2435
+
[x] At least one part of the SQL statement is data that may be from an attacker.
2436
+
2437
+
[x] The SQL statement is executed.
2438
+
2439
+
### SQL Injection: Parameterized Statements
2432
2440
2433
2441
SQL injection vulnerabilities are one of the most common and devastating vulnerabilities, especially in web applications. They are also easy to counter, once you know how to do it.
2434
2442
@@ -2438,7 +2446,7 @@ For our purposes, a *prepared statement* compiles the statement with the databas
2438
2446
2439
2447
For security, the key is to use an API with parameterized statements (including a prepared statement API) and ensure that every untrusted input is sent as a separate parameter. Make sure that you do *not* normally include untrusted input by concatenating untrusted data as a string (including a formatted string) into a request.
2440
2448
2441
-
##### Advantages of parameterized/prepared statements
2449
+
#### Advantages of parameterized/prepared statements
2442
2450
2443
2451
Most programming languages have at least one library that implements parameterized statements and/or prepared statements. Using parameterized statements, including by using prepared statements, has many advantages:
2444
2452
@@ -2448,7 +2456,7 @@ Most programming languages have at least one library that implements parameteriz
2448
2456
2449
2457
3. Many can handle variation in different SQL engines (which is important because different systems often have different syntax rules).
2450
2458
2451
-
##### Example: Prepared statements in Java
2459
+
#### Example: Prepared statements in Java
2452
2460
2453
2461
Here is an example of using prepared statements in Java
2454
2462
using its JDBC interface:
@@ -2483,7 +2491,7 @@ Of course, like any technique, if you use it wrongly then it won’t be secure.
2483
2491
2484
2492
This insecure program uses a prepared statement, but instead of correctly using “**?**” as a value placeholder (which will then be properly escaped), this code directly concatenates data into the query. Unless the data is properly escaped (and it almost certainly is not), this code can quickly lead to a serious vulnerability if this data can be controlled by an attacker.
2485
2493
2486
-
##### Examples: Parameterized and Prepared Statements in some Other Languages
2494
+
#### Examples: Parameterized and Prepared Statements in some Other Languages
2487
2495
2488
2496
Parameterized and prepared statements are widely available, though the
2489
2497
APIs and placeholder syntax vary by programming language, library, and database.
@@ -2538,7 +2546,7 @@ explained in the [PostgreSQL (Command Execution Functions) documentation](https:
2538
2546
2539
2547
The [OWASP Query Parameterization Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Query_Parameterization_Cheat_Sheet.html) and [Bobby Tables website](https://bobby-tables.com/) provide examples for a variety of ecosystems.
\>\>Parameterized statements (including prepared statements) are a valuable countermeasure against SQL injection, but you have to use placeholders for every data value that might possibly be controllable by an attacker. True or False?<<
0 commit comments