CompTIA Security+ SY0-701 · Threats, Vulnerabilities, and Mitigations · medium
A security analyst discovers that an internal billing portal executes raw database queries built as "SELECT * FROM invoices WHERE id = '" + userInput + "'". Which remediation directly neutralizes SQL Injection (SQLi) on this endpoint?
Published · Last updated · checked before publication — how we verify questions
Options
Answer: A. Refactoring the query to use prepared statements with bound parameters
Prepared statements with bound parameters are the direct fix for SQL injection because they separate code from data. The query structure, such as SELECT * FROM invoices WHERE id = ?, is sent to the database and compiled first, and the user-supplied value is bound afterward as a literal. Even if an attacker enters something like ' OR '1'='1, the database treats it as an ordinary string to compare against the id column, never as SQL syntax. The root cause in the scenario is string concatenation of untrusted input into a command, so the remediation must remove that concatenation. The common trap is picking a control that sounds like general web hardening, such as encryption or cookie protections, which addresses a different attack class. On the exam, match the control to the vulnerability: injection flaws are fixed by input validation and parameterized queries, not by transport or session controls. Stored procedures that avoid dynamic SQL and least-privilege database accounts are complementary defenses, but parameterization is the direct fix.
Why the other options are wrong
- B. Enabling HTTP Strict Transport Security (HSTS) on the TLS load balancer — HSTS forces browsers to use HTTPS, which protects against downgrade and eavesdropping attacks on data in transit. A SQL injection payload sent over an encrypted connection still reaches the application and is concatenated into the query unchanged.
- C. Adding the HttpOnly and SameSite=Strict flags to session cookies — HttpOnly prevents JavaScript from reading session cookies and SameSite restricts cross-site cookie sending, so they reduce XSS cookie theft and CSRF. They have no effect on how the server builds its SQL query from user input.
- D. Increasing the database connection pool timeout and read-replica count — Connection pool timeouts and read replicas are performance and availability settings for the database tier. They do nothing to change how untrusted input is interpreted, so the concatenated query stays injectable.
More Threats, Vulnerabilities, and Mitigations questions
- Which two characteristics distinguish an Adversary-in-the-Middle (AitM) reverse-proxy phishing kit from a traditional…
- Which two indicators should a vulnerability management team combine with a vulnerability's base CVSS score to…
- A developer discovers that a C++ network daemon copies a 512-byte user packet into a fixed 128-byte stack array using…
- An attacker compromises a niche trade-association website frequently visited by defense contractors, injecting an…
- A web application allows authenticated users to fetch profile avatars by passing a URL parameter…
All Threats, Vulnerabilities, and Mitigations questions and the topic overview →
CompTIA and Security+ are trademarks of the Computing Technology Industry Association. PrepIQ Hub is not affiliated with, endorsed by, or sponsored by CompTIA.