What this quiz covers
This quiz focuses on Sql Injection And Mitigations, giving you a quick way to practice the rules, question types, and explanations that matter most for Cyber Security.
A login handler executes SELECT user_id FROM users WHERE username = ? AND password_hash = ? through a database prepared-statement API. Both placeholders are bound as strings. An attacker submits admin' OR '1'='1 as the username.
Assuming the database driver performs genuine parameter binding, what is the most accurate result?
Cyber Security Quiz
Practice Sql Injection And Mitigations in Cyber Security with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.
This quiz focuses on Sql Injection And Mitigations, giving you a quick way to practice the rules, question types, and explanations that matter most for Cyber Security.
Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.
A login handler executes SELECT user_id FROM users WHERE username = ? AND password_hash = ? through a database prepared-statement API. Both placeholders are bound as strings. An attacker submits admin' OR '1'='1 as the username.
Assuming the database driver performs genuine parameter binding, what is the most accurate result?
?) tell the database engine exactly where data values will go. When admin' OR '1'='1 is bound as a string parameter, the driver transmits it to the database as a literal data value — not as SQL text to be parsed. The database compares the entire string admin' OR '1'='1 against stored usernames character-for-character. No account has that exact username, so authentication fails. This is why C is correct: the SQL-looking characters lose all syntactic meaning because query structure was already finalized.
A describes classic SQL injection, but that attack only works when input is concatenated directly into a query string — not when prepared statements are used correctly. The scenario explicitly states genuine parameter binding, making A factually wrong for this context.
B introduces a common misconception: that input sanitization (stripping apostrophes or comment characters) is what makes prepared statements safe. It isn't. Parameterization works independently of character filtering; the driver's binding mechanism is the protection, not preprocessing.
D is a subtle trap suggesting prepared statements can't handle quoted strings safely. This is false — string parameters are among the clearest cases where binding works perfectly, since the driver handles escaping automatically and completely.
Your study tip: whenever a question says "genuine parameter binding," that phrase is your signal that the query structure is immutable — no injected syntax can escape the data context.A development team uses an object-relational mapper (ORM). Most queries use typed methods, but one endpoint calls a raw-query feature with where("email = '" + request.email + "'"). The team argues that the ORM automatically protects all database access.
Which change most appropriately addresses the endpoint's risk?
where("email = ?", request.email) or an equivalent binding syntax). This separates the SQL structure from the data value, so the database engine treats the email as a literal string — never as executable SQL — regardless of what characters it contains.
Choice B is a classic trap: HTML-encoding neutralizes characters like < and > for web output, but SQL injection uses characters like ', --, and ;. HTML encoding does nothing to stop SQL injection. Choice C is factually wrong — dropping raw string fragments into a query does not trigger automatic parameterization; the ORM passes the pre-built fragment directly to the database engine, injected content and all. Choice D fails because email validation via simple pattern matching is not a security boundary. An attacker can craft inputs that satisfy basic rules (containing @ and .) while still embedding malicious SQL fragments after or around those characters.
Your study takeaway: parameterization is the only reliable defense against SQL injection. Any time user input is concatenated into a query string — even inside an ORM, even after validation — treat it as a vulnerability.An endpoint accepts a list of product IDs and currently creates SELECT * FROM products WHERE product_id IN ( followed by the comma-joined request strings and ). The number of IDs varies with each request.
Which implementation best preserves variable-length functionality while mitigating SQL injection?
1,2,3 as a single placeholder inside IN (?), relying on the database driver to split and interpret the comma-separated value correctly.IN (...) clauses is that the number of placeholders must match the number of values, which requires a bit of extra logic compared to single-value queries.
Answer A is correct because it generates exactly one ? placeholder per validated list element, then binds each value individually. The database driver treats each bound value as pure data — never as executable SQL — regardless of its content. Handling the empty-list edge case separately is also important, since IN () is invalid SQL that could cause unintended errors or behavior.
Answer B exploits a common misconception: that you can bind an entire comma-separated string as a single placeholder inside IN (?). Database drivers don't split or interpret that string — the query would either fail or match nothing, and it is not a valid injection defense.
Answer C is dangerous because escaping apostrophes alone is insufficient. Numeric-looking inputs like 1 OR 1=1 require no apostrophes whatsoever, meaning injection payloads can still manipulate query logic without any string delimiters.
Answer D is a classic blocklist/denylist trap. Filtering out spaces, semicolons, comments, and UNION keywords relies on anticipating every possible attack pattern — an impossible task. Attackers routinely bypass blocklists using encoding, case variation, or alternative syntax.
Study tip: Any time you see an answer involving escaping, filtering, or keyword blocklisting, treat it with suspicion. Parameterized queries with bound parameters are almost always the correct defense for injection vulnerabilities on security exams.An application calls a stored procedure using a bound parameter: CALL FindCustomer(?). Inside the procedure, the implementation constructs SELECT * FROM customers WHERE last_name = ' followed by the procedure argument and then executes the resulting string dynamically.
Which assessment and remediation are most accurate?
SELECT * FROM customers WHERE last_name = ' + argument and executes it dynamically. At that moment, an attacker's input like ' OR '1'='1 is evaluated as live SQL syntax. The correct answer is B because it accurately diagnoses the root cause — dynamic string construction inside the procedure — and prescribes the right fix: use static SQL (where the query structure never changes) or properly bind the value within the dynamic statement itself.
A is wrong because it assumes the application-layer binding creates end-to-end protection. It doesn't. Binding only protects the specific execution point where it's applied. C is wrong because permissions control access, not code execution safety. The procedure itself can still be exploited, and the injected query runs under whatever privileges the procedure holds. D is wrong because SQL injection is far broader than stacked statements. Attackers can manipulate logic with OR 1=1, extract data with UNION SELECT, or cause errors — all within a single statement. Disabling multiple statements addresses one narrow vector while leaving the vulnerability wide open.
Your study tip: always ask "where is the SQL string assembled?" — that's where injection risk lives, not where the data entered the system.A product search executes SELECT product_id FROM products WHERE name LIKE ? and binds the value formed by placing % before and after the user's search term. A user enters %, causing the search to return nearly every product.
Which explanation best distinguishes the observed behavior from SQL injection?
LIKE wildcards can broaden matching semantics. (correct answer)? placeholder, meaning the database engine parses and compiles the SQL before any user data is substituted. The user's % is treated purely as a string value — it never touches the query's logical structure. B is correct because it accurately captures both truths simultaneously: no SQL injection occurred (the structure is intact), and the % wildcard still meaningfully broadens the LIKE match, returning far more rows than intended. This is a real vulnerability — just not SQL injection. It's better categorized as improper input validation.
A is wrong because it claims the user "modifies the parsed SQL structure," which is precisely what parameterization prevents. The parsing happens before the value is ever bound — this is the entire point of prepared statements.
C is wrong because it misidentifies the application's own % additions as the source of injection. Those additions are part of the developer's intended pattern-building logic, not user-controlled SQL manipulation.
D is wrong in the opposite direction — it overcorrects into a false sense of safety. Bound % values absolutely can affect query results through LIKE semantics; they just can't alter SQL structure. Claiming they're "ignored" is factually incorrect.
As a study tip: when you see parameterized queries, remember that security ≠ correctness. A query can be injection-safe but still behave unexpectedly due to unvalidated wildcard characters.A database driver has been configured to reject queries containing multiple statements. The application nevertheless constructs SELECT order_id FROM orders WHERE customer = ' followed by an untrusted request value and a closing apostrophe.
What security effect does disabling multiple statements provide in this scenario?
; DROP TABLE orders--, but it says nothing about what the attacker can do within the one statement that is still permitted.
In this scenario, the application still concatenates untrusted input directly into the query string inside a string literal context. An attacker can close the apostrophe, inject conditions like ' OR '1'='1, and completely alter the WHERE predicate — all within a single statement. The database driver happily executes it because no second statement was detected. This is exactly what C describes: stacked-query attacks are limited, but single-statement predicate manipulation remains fully exploitable.
A is wrong because it assumes injection requires a second statement to "affect the query's meaning." That's false — injecting ' OR 1=1-- rewrites the predicate of the original single statement without stacking anything. B is wrong because the restriction on multiple statements has nothing to do with data types like numeric or date fields; that's a separate concern about parameterization, which this scenario explicitly hasn't implemented. D describes parameterized queries — binding untrusted input as a value — which is not what disabling multiple statements does. These are two completely different mechanisms.
The study tip here: never conflate one defense with complete protection. Exam questions frequently describe a partial control and ask you to identify its residual risk. Always trace the full attack path — if unsanitized string concatenation survives, injection survives with it.An API retrieves active accounts using the query SELECT id, name FROM accounts WHERE active = ? ORDER BY ?. The application binds true to the first placeholder and the client-supplied value created_at to the second. In testing, the database either reports an error or returns rows without the expected sorting.
Which change most securely provides client-selectable sorting while preserving the intended query behavior?
active value.ORDER BY.created_at is bound to the second placeholder.
The safest solution is option B: maintain an explicit server-side allowlist that maps client-supplied keys (like "created_at") to hard-coded column names, then concatenate only that pre-approved, internally controlled string into the query. The user's raw input never touches the SQL — only your code's own trusted constant does. Data values like active = true continue to use binding normally. This eliminates injection risk while delivering the correct behavior.
Option A is dangerous because stripping quotes and semicolons is an incomplete denylist approach. Attackers can often bypass such filters using alternate syntax, comments, or encoding tricks — there's always something you forget to block. Option C sounds clever but doesn't work in practice: databases parse placeholders as string literals, not identifiers, so casting a bound value to a column name is either unsupported or still injectable depending on implementation. Option D applies string-escaping to what should be an identifier, not a string. Escaping prevents quote injection inside string literals — it offers no reliable protection when the value is placed structurally in a query without quotes.
Study tip: Whenever you see "user controls a column name or sort order," your instinct should be "allowlist + concatenate the mapped constant, not the raw input." Parameterization handles values; allowlists handle structure.A legacy endpoint obtains an accountId from a request. A strict parser accepts only decimal digits, converts the result to a bounded integer, and the application concatenates that integer into SELECT balance FROM accounts WHERE account_id = followed by its decimal representation.
Which review finding is the most precise?
A profile service safely inserts display names with INSERT INTO profiles(display_name) VALUES (?). A separate reporting job later reads each display name and concatenates it into SELECT event_id FROM events WHERE actor_name = ' followed by the stored value. Reports are generated only by administrators.
What is the best security conclusion?
INSERT, the reporting job retrieves that stored value and concatenates it directly into a new SQL query string. If an attacker registered a display name like ' OR '1'='1, it would sit harmlessly in the database — but the moment the reporting job builds its SELECT query using string concatenation, that stored value becomes live SQL. The parameterization of the original insert offers zero protection for this second query. Answer C is correct because the fix must happen at the point of execution: the reporting job must treat the retrieved value as untrusted input and use a parameterized query or prepared statement.
A is wrong because it conflates where data was safely stored with where it is safely used. Parameterization protects only the query it belongs to — it doesn't sanitize the data itself for future use. B is wrong because access controls don't neutralize injection vulnerabilities; administrators can still trigger malicious logic, and restricting who runs a query doesn't fix how the query is constructed. D is wrong because output encoding addresses rendering in a browser (XSS prevention), not SQL injection — and the claim that database-stored values "cannot become SQL instructions" is simply false.
Your study tip: whenever you see data traveling from one query into a different query later, mentally flag it as a second-order injection risk — parameterize at every execution point, not just the first.A public application concatenates request values into SQL statements. Its web application firewall blocks common strings such as UNION SELECT, apostrophe-based tautologies, and SQL comment markers. Security testing finds no successful payloads using the firewall's current rule set.
Which recommendation most directly addresses the underlying SQL injection risk?