Skip to content

Commit 463b089

Browse files
Complete SQL Injection split
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]>
1 parent 7a1b0bb commit 463b089

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

secure_software_development_fundamentals.md

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,9 +2376,7 @@ This is false. Clearly, if you pick known *insecure* software, you will have a p
23762376

23772377
## Calling Other Programs: Injection and Filenames
23782378

2379-
### SQL Injection
2380-
2381-
#### SQL Injection Vulnerability
2379+
### SQL Injection Vulnerability
23822380

23832381
![image alt text](exploits_of_a_mom.png)
23842382

@@ -2428,7 +2426,17 @@ Again, we want to try to use an approach that is easy to use correctly - it need
24282426

24292427
For databases, there are well-known solutions that are far easier to use securely.
24302428

2431-
#### Usual SQL Injection Solution: Parameterized Statements
2429+
#### Quiz - SQL Injection Vulnerability
2430+
2431+
\>\>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
24322440

24332441
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.
24342442

@@ -2438,7 +2446,7 @@ For our purposes, a *prepared statement* compiles the statement with the databas
24382446

24392447
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.
24402448

2441-
##### Advantages of parameterized/prepared statements
2449+
#### Advantages of parameterized/prepared statements
24422450

24432451
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:
24442452

@@ -2448,7 +2456,7 @@ Most programming languages have at least one library that implements parameteriz
24482456

24492457
3. Many can handle variation in different SQL engines (which is important because different systems often have different syntax rules).
24502458

2451-
##### Example: Prepared statements in Java
2459+
#### Example: Prepared statements in Java
24522460

24532461
Here is an example of using prepared statements in Java
24542462
using its JDBC interface:
@@ -2483,7 +2491,7 @@ Of course, like any technique, if you use it wrongly then it won’t be secure.
24832491

24842492
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.
24852493

2486-
##### Examples: Parameterized and Prepared Statements in some Other Languages
2494+
#### Examples: Parameterized and Prepared Statements in some Other Languages
24872495

24882496
Parameterized and prepared statements are widely available, though the
24892497
APIs and placeholder syntax vary by programming language, library, and database.
@@ -2538,7 +2546,7 @@ explained in the [PostgreSQL (Command Execution Functions) documentation](https:
25382546

25392547
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.
25402548

2541-
#### Quiz 3.2: SQL Injection
2549+
#### Quiz 3.2: SQL Injection: Parameterized Statements
25422550

25432551
\>\>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?<<
25442552

0 commit comments

Comments
 (0)