GSLC · Question #559
Which of the following can be used as a countermeasure against the SQL injection attack? Each correct answer represents a complete solution. Choose two.
The correct answer is C. mysql_real_escape_string() D. Prepared statement. SQL injection is mitigated by escaping user input with the correct character-set-aware function and by using parameterized queries that separate data from SQL logic.
Question
Which of the following can be used as a countermeasure against the SQL injection attack? Each correct answer represents a complete solution. Choose two.
Options
- Amysql_escape_string()
- Bsession_regenerate_id()
- Cmysql_real_escape_string()
- DPrepared statement
How the community answered
(40 responses)- A13% (5)
- B8% (3)
- C80% (32)
Why each option
SQL injection is mitigated by escaping user input with the correct character-set-aware function and by using parameterized queries that separate data from SQL logic.
mysql_escape_string() is deprecated and does not consider the active connection's character set, meaning multi-byte encoding attacks can bypass its escaping in certain configurations, leaving the application vulnerable.
session_regenerate_id() is a PHP session management function that creates a new session ID to prevent session fixation attacks - it has no effect on database query construction or SQL injection.
mysql_real_escape_string() escapes special characters in user input while accounting for the current database connection's character set, preventing attackers from injecting SQL metacharacters that break query structure.
Prepared statements (parameterized queries) are the most robust defense - they pre-compile the SQL structure and bind user-supplied values as typed parameters, making it structurally impossible for input data to be interpreted as SQL code.
Concept tested: SQL injection prevention using escaping and parameterized queries
Source: https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
Topics
Community Discussion
No community discussion yet for this question.