Question 201 · 385 in bank
Refer to the exhibit. The code fetches the latest order from the purchases table for a specific user. An engineer needs to pass query parameters to the execute function to prevent an SQL injection attack. Which code snippet must be placed in the blank in the code to meet this requirement?
Show answer
Answer: B
Explanation
B is a parameterization method, better for SQL Injection; C is a ecaping method, better for XSS according to the DevCore study guide Moreover C has a syntax error Moreover ChatGPT sais B: This code is using Python to execute a SQL query against a database using parameterized queries to prevent SQL injection attacks. Specifically, it is selecting the orders column from the purchases table where the username column matches the username variable. The username variable is passed in as a parameter in a dictionary format using the % operator to substitute the value into the query string. This approach is recommended for preventing SQL injection attacks because it ensures that user input is treated as data rather than as part of the SQL statement itself.
Source: Adapted from community discussion — ldlpi







