SQL Injection

Securityintermediate

// Definition

An attack where untrusted input is concatenated into a SQL query, letting an attacker exfiltrate or modify data. Mitigated with parameterised queries and ORM usage. Tested with crafted payloads at every input that reaches the database.

// Why it matters

SQLi lets attacker input alter the query it lands in — reading, modifying, or destroying data, or bypassing auth entirely. QA's role is to probe every input that could reach a query (filters, search, login, sort params) with breaking characters, and to confirm the app uses parameterised queries rather than string-built SQL.

// How to test

// Classic auth-bypass probe — must NOT log in
cy.request({
  method: 'POST',
  url: '/api/login',
  body: { username: "admin' OR '1'='1", password: 'x' },
  failOnStatusCode: false,
}).its('status').should('eq', 401)

// Error-based probe — a single quote must not 500 with a SQL error
cy.request({ url: `/api/search?q=%27`, failOnStatusCode: false })
  .then((res) => expect(res.status).to.not.eq(500))

// Common mistakes

  • Testing the login form but not search, sort, filter, or export params
  • Treating a generic 500 as "handled" when it leaks a SQL error body
  • Assuming an ORM makes you immune (raw fragments and LIKE builders still bite)

// Related terms

Learn more · Non-Functional Testing Overview

Chapter 3 · Lesson 2: Common Vulnerability Categories — XSS, SQL Injection, CSRF