Professor Franklin
Accessibility settings

Preferences are saved in this browser when storage is available.

Chapter 6 · Reading 2 of 6

Injections

Security+ SY0-801 · Objectives 4.1

The booking application works for most students. A student whose surname contains an apostrophe gets an error when searching their reservations. Ordinary data has exposed an ambiguity in how the application communicates with its storage layer.

Injection attacks are a type of security vulnerability that occurs when an attacker is able to insert (or "inject") malicious code into a program or query. This malicious code is then executed by the application, potentially leading to unauthorized access, data leakage, and other security breaches. Injection attacks are among the most common and dangerous vulnerabilities in web applications.

Common Types of Injection Attacks

SQL Injection (SQLi): An attacker inserts malicious SQL queries into an input field, which are then executed by the database.

  • Can lead to unauthorized access to data, data manipulation, and even complete control over the database.
  • Defense: Bind the supplied value as a query parameter.

Cross-Site Scripting (XSS): An attacker injects malicious scripts into web pages viewed by other users. These scripts can execute in the context of the user's browser.

  • Can lead to session hijacking, defacement, and redirecting users to malicious sites.
  • Defense: Encode untrusted text for the context in which it will be displayed.

Command Injection: An attacker injects malicious commands into a program that are then executed by the system shell.

  • Can lead to the execution of arbitrary commands on the server, potentially compromising the entire system.
  • Defense: Use a dedicated library operation instead of constructing a shell command from input.

LDAP Injection: An attacker injects malicious LDAP (Lightweight Directory Access Protocol) queries into an input field.

  • Can lead to unauthorized access and manipulation of directory services.
  • Defense: Escape filter values using the directory library’s LDAP encoding rules.

XML Injection: An attacker injects malicious XML content into an input field that is processed by an XML parser.

  • Can lead to XML external entity (XXE) attacks, which can expose sensitive data and allow arbitrary file access.
  • Defense: Disable unnecessary external entity resolution in the XML parser.

Testing the fix

Review the boundary between a query template and user-supplied values. Check that every data-access path uses binding and that identifiers come from an approved set. Use ordinary names containing punctuation in regression tests. Limit the application's database permissions to the operations it needs and avoid exposing internal query errors to users.

Review the repair with two users

Use synthetic records and choose names that include ordinary punctuation and international characters. Ask what the query is supposed to express before any name is supplied. Then check that the implementation sends a fixed query structure and passes the name as a bound value. Repeat the legitimate searches, including empty results and multiple authorized matches. A rule that simply rejects punctuation can silence the original error while excluding legitimate users.

The developer should also check related search and export paths that use the same data. The reviewer can document what was inspected, what changed and how expected behavior was preserved. Even a correctly constructed query needs a separate decision about which reservations this particular student may read.

Query boundary stencil

Inspect the three records, then use the evidence to answer the question.

1. Structure

The application defines the operation.

Adapter A concatenates names into query text

2. Value

The user supplies a data value.

Adapter B binds a name in a value parameter

3. Boundary

Parameter binding keeps the roles distinct.

Both adapters return the same results in routine tests

Apply the reading

A search page passes student names to a database. What design decision belongs in code review?

Compare your reasoning

Confirm that the query structure is fixed and the name is bound as data. Review the database account’s permissions as a second layer.