SQL injection

SQL injection is an application attack where an adversary types database commands into an open-ended input field that lacks proper input checks, tricking the app into running those commands and exposing or altering data it shouldn't.

Verified for the 2027 AP Cybersecurity examLast updated June 2026

What is SQL injection?

SQL injection is what happens when an app trusts user input too much. Many web applications take input through open-ended fields where you can type any characters you want (EK 5.1.B.1, EK 5.1.B.2). Normally that field is just for your username or a search term. But if the developer never checks that input, an attacker can type actual database commands instead of a name, and the app forwards them straight to the database.

The classic example: an attacker enters ' OR '1'='1 into a login field. Because '1'='1' is always true, the query that was supposed to check your password now returns every record in the table. No password needed. That's a textbook injection attack, and it's exactly the scenario AP Cybersecurity uses to illustrate how application attacks exploit vulnerabilities (LO 5.1.B). The root cause is missing input validation, not a flaw in the database itself.

Why SQL injection matters in AP Cybersecurity

SQL injection lives in Unit 5: Securing Applications and Data, topic 5.1. It's the headline example for learning objective 5.1.B, explaining how application attacks exploit vulnerabilities, and it ties directly to 5.1.A (how adversaries exploit application vulnerabilities to cause loss or damage). It also connects to 5.1.C, the risk side. A successful injection can break all three parts of the CIA triad (EK 5.1.C.1): it can read confidential data, alter integrity, or destroy availability. When the exposed data is regulated (PII, PHI, PCI), the risk score jumps because the data is highly sensitive (EK 5.1.C.2).

Keep studying AP Cybersecurity Unit 5

How SQL injection connects across the course

Input sanitization and data validation (Unit 5)

These are the defenses that stop SQL injection cold. Validation checks that input matches what's expected (a number where a number belongs), and sanitization strips or neutralizes dangerous characters. SQL injection is basically what happens when both are missing.

XSS (Cross-Site Scripting) (Unit 5)

XSS is SQL injection's cousin. Both are injection attacks that abuse unvalidated input, but XSS injects script that runs in another user's browser, while SQL injection injects commands that hit the database. Same root cause, different target.

PII, PHI, and PCI (Unit 5)

These categories of sensitive data are what makes a SQL injection so costly. Dumping a table full of PII or PHI is a confidentiality breach of regulated data, which is exactly the high-risk scenario EK 5.1.C.2 describes.

Directory traversal (Unit 5)

Another application attack in 5.1 that exploits weak input handling. Directory traversal abuses file paths to reach unauthorized files; SQL injection abuses input to reach unauthorized database records. Pairing them helps you sort the family of application attacks.

Is SQL injection on the AP Cybersecurity exam?

Expect SQL injection in multiple-choice questions two ways. First, identification: a stem describes an attacker typing ' OR '1'='1 into a login field and asks what kind of attack it is (answer: SQL injection, an injection-type application attack). Second, classification: you'll be asked which option is an example of an application attack or an injection-type attack, and SQL injection is the right pick. The flip side shows up too. A question describing an app that checks input is a whole number between 1 and 999 is testing data validation, the defense. Know both the attack and the fix, and be ready to name which CIA goal (confidentiality, integrity, availability) gets violated.

SQL injection vs XSS (Cross-Site Scripting)

Both are injection attacks born from unvalidated input, so they get mixed up constantly. The difference is the target. SQL injection sends commands to the back-end database to read or alter stored data. XSS injects scripts that execute in another user's browser. If the attack hits records and tables, it's SQL injection; if it runs code in someone's browser session, it's XSS.

Key things to remember about SQL injection

  • SQL injection is an application attack where an attacker types database commands into an unvalidated input field.

  • The classic payload ' OR '1'='1 makes a login check always evaluate true, returning every record instead of verifying credentials.

  • The root cause is missing input validation, not a broken database, so input validation and sanitization are the defenses.

  • A successful SQL injection can break confidentiality, integrity, or availability, which maps directly to the CIA triad in EK 5.1.C.1.

  • On the AP exam, SQL injection is the go-to example of an injection-type application attack under learning objective 5.1.B.

Frequently asked questions about SQL injection

What is SQL injection in AP Cybersecurity?

It's an application attack where an adversary enters database commands into an open-ended input field that the app fails to validate, causing the app to run those commands. AP Cybersecurity covers it under topic 5.1 and learning objective 5.1.B.

Is SQL injection caused by a weak database?

No. The vulnerability is in the application, not the database. SQL injection succeeds because the developer didn't check user input (EK 5.1.B.2), so adding input validation and sanitization is what stops it.

How is SQL injection different from XSS?

Both are injection attacks from unvalidated input, but SQL injection targets the back-end database to read or alter data, while XSS injects scripts that run in another user's browser. Target equals database means SQL injection; target equals browser means XSS.

What does the `' OR '1'='1` attack actually do?

Typed into a login field, it makes the database query always return true because '1'='1' is always true. Instead of checking a password, the app returns every user record, letting the attacker bypass authentication.

How do I stop SQL injection?

Validate and sanitize user input. Data validation confirms input matches what's expected (like a whole number between 1 and 999), and input sanitization neutralizes dangerous characters before they ever reach the database.

Keep studying AP Cybersecurity

Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.