GRC Careers

HomeResourcesSQL Injection

CS-058 · Application Security

SQL Injection

An attack where untrusted input is interpreted as part of a database query.

Executive Summary

SQL injection is a class of attack in which untrusted input is treated as part of a database query rather than as plain data. When an application builds queries by concatenating user input, an attacker can change the meaning of the query to read, alter, or delete data. It is one of the oldest and most damaging web application flaws, and it is almost entirely preventable with parameterized queries.

What It Is

SQL injection occurs when an application sends user-supplied input to a database in a way that lets the input change the structure of the query, not just its values. The root cause is mixing code and data: when input is concatenated directly into a query string, the database cannot tell where the developer's instructions end and the attacker's input begins. Depending on the application, an attacker may be able to bypass a login, read data belonging to other users, modify or delete records, or in some cases run commands on the database server. Variations include blind injection, where results are inferred indirectly, and injection through any input path the application trusts, not only obvious form fields.

Why It Matters

Databases usually hold the most sensitive assets an organization has, including customer records, credentials, and financial data. A single SQL injection flaw can expose an entire database, which makes it a favorite target for attackers and a frequent cause of large breaches. Beyond data theft, injection can corrupt records or take a service offline. Because the flaw is well understood and highly preventable, an SQL injection in production is often read by auditors and customers as a sign of weak development practices. For professionals, recognizing and eliminating it is a baseline expectation in application security.

How It Works

At a conceptual level, the problem is that the query and the data travel together. When an application builds a query by pasting input directly into a string, input that contains query syntax can be interpreted as instructions. The defense reverses this by keeping code and data strictly separate. With parameterized queries, also called prepared statements, the developer writes the query with placeholders and sends the user input separately as values, so the database always treats it as data and never as executable syntax. Additional layers help: validating input against an expected format, applying least privilege so the database account can do only what the application needs, and avoiding detailed database errors that reveal structure to an attacker.

Architecture Diagram

User submits inputApplication builds a database queryUnsafe: input concatenated into the query stringSafe: input bound as a parameter, kept as dataDatabase returns only the intended result
SQL injection happens when input mixes into query code; parameterized queries keep the two separate so input stays data.

Visual Workflow

Identify every place user input reaches a database query, including hidden and indirect inputs.Replace string-concatenated queries with parameterized queries or prepared statements.Validate input against an expected type and format as a supporting layer.Grant the application database account only the privileges it truly needs.Suppress detailed database errors from users and log them internally instead.Test with both automated tools and manual review, then re-test after changes.

Common Attacks

Common Mistakes

Best Practices

Quick Checklist

Recommended Tools

Static application security testing (SAST)
Flags string-built queries and unsafe input handling in source code
Dynamic application security testing (DAST)
Probes a running application for injectable inputs
Parameterized query library or ORM
Provides safe query construction that separates code from data
Web application firewall (WAF)
Acts as a compensating control to filter obvious injection attempts

Industry Standards

OWASP Top 10
Injection is a longstanding category of critical web application risk
OWASP Application Security Verification Standard (ASVS)
Testable requirements for safe data access and query construction
CWE-89
The Common Weakness Enumeration entry for SQL injection

Career Relevance

SQL injection is core knowledge for application security engineers, penetration testers, and secure code reviewers, who look for it in nearly every web assessment. Developers are expected to prevent it by default through safe query practices, and GRC and audit professionals treat its presence as a meaningful risk signal. For the AI-Governance-Jobs.com audience, it is one of the most common technical interview topics in appsec.

Interview Questions

Related Certifications

GIAC Web Application Penetration Tester (GWAPT) Offensive Security Web Assessor (OSWA) CompTIA Security+

Further Reading

Key Takeaways

Download PDFDownload PNG

FAQ

Are parameterized queries enough on their own?

They are the primary and most effective defense for query construction. In practice you pair them with input validation, least privilege on the database account, and safe error handling for defense in depth.

Does using an ORM make an application immune?

Not automatically. Many ORMs parameterize by default, which helps, but raw or dynamically built queries within an ORM can still be vulnerable. The safe pattern of separating code from data still applies.

Is SQL injection still a real risk today?

Yes. Despite being well understood, it still appears in production applications, especially in older code, custom query building, and inputs developers did not expect to be attacker controlled.

Get all 116 reference sheets
The complete AGJ Cybersecurity Professional Reference Library, print-ready PDFs and PNGs.
Browse the library

Related Careers

Related certifications

GIAC Web Application Penetration Tester (GWAPT)Offensive Security Web Assessor (OSWA)CompTIA Security+

Current openings

Live openings appear on the web version. Browse the job board for current GRC and security roles.
Browse all jobs

Suggested learning path

  1. Ground the basics with CS-001 Cybersecurity
  2. Study this sheet: SQL Injection
  3. Go deeper: OWASP Top 10
  4. Go deeper: Cross-Site Scripting (XSS)
  5. Validate it: work toward GIAC Web Application Penetration Tester (GWAPT)
  6. Find the role: browse current openings

Related sheets

More in Application Security

Share this LinkedIn Facebook X Email