Information Security Basics

As a countermeasure against SQL injection, why are prepared statements with placeholders (parameterized queries) considered more fundamental than removing dangerous characters from the input?

  1. ABecause the input is encrypted before being passed to the database, so attackers cannot read it
  2. BBecause the browser checks the kinds of characters entered, so malicious strings never reach the server
  3. CBecause the structure of the SQL statement is fixed first and the input is passed afterward only as values, so whatever characters the input contains, it is never interpreted as part of the command
Show answer and explanation

Answer: C. Because the structure of the SQL statement is fixed first and the input is passed afterward only as values, so whatever characters the input contains, it is never interpreted as part of the command

With a prepared statement, an SQL statement whose values are replaced by symbols (placeholders), such as "SELECT … WHERE id = ? AND password = ?", is first passed to the database to fix its structure, and the input is then attached only as values (binding). The input is treated as data from start to finish, so even if it contains quotation marks it never becomes part of a command, such as one that adds a condition. Removing or escaping dangerous characters requires handling every detailed rule for each database type and character encoding without omission, and a single gap lets the attack succeed. Checks of input in the browser can be bypassed if the attacker sends requests directly without going through a browser, so they serve convenience and are not a security measure. In addition, giving the account used to connect to the database the minimum privileges keeps damage small.

  • A. Prepared statements do not encrypt input. The key point is handling the values separately from the SQL statement structure.
  • B. Browser-side checks can be bypassed by sending requests directly, so they are not a countermeasure.
  • C. Correct. The statement structure is fixed first and the input is handled only as values, so it is never interpreted as a command.
Practice this topic Back to topic

Related calculators

Books on Information Security Basics Ad

As an Amazon Associate I earn from qualifying purchases.

More Information Security Basics questions

  1. A bulletin-board web application had a vulnerability in which scripts contained in text posted by users were executed in other visitors' browsers. Which combination correctly gives the name of this vulnerability and its fundamental countermeasure?
  2. A web application has a vulnerability in which, if a logged-in user opens a trap page prepared by an attacker, the user's browser sends requests to the legitimate site that the user did not intend, such as transferring money or changing settings. Which is an appropriate countermeasure?
  3. A web application reads and displays a file by joining a file name given in a URL parameter to the name of its public folder. If a value containing ../ is given as the file name, configuration files and other files outside the public folder can be read. Which combination correctly gives the name of this attack and a countermeasure?
  4. If a web application keeps using the same session ID before and after login, an attacker may get the user to use a session ID the attacker prepared in advance and then, after the user logs in, impersonate the user with that ID. What is the most appropriate countermeasure against this attack?
  5. Which statement correctly describes a DDoS attack?