Threats, Vulnerabilities, and Mitigations

A login page returns a database error when a tester enters a single quote in the username field, and ' OR '1'='1 bypasses authentication. Which fix addresses the root cause?

Show the answer

Correct answerA. Use parameterized queries

AWhy this is right: Binding input as parameters stops it from being parsed as SQL, which removes the injection flaw at its source.

BWhy not this: Output encoding blocks script injection in rendered pages; it does not change how the database parses the query.

CWhy not this: TLS encrypts traffic in transit; the attacker's injected input still reaches the query unchanged.

DWhy not this: CSP restricts which scripts a browser runs, so it is an XSS defense and has no effect on SQL statements.

The error and the login bypass show that user input is concatenated into a SQL statement. Parameterized queries keep input as data, not code. Output encoding and CSP defend against script injection in browsers, not against altered database queries.