Second-order SQLi

Second-order SQL Injection

Second order SQL injection (also known as Stored SQL Injection) occurs when user input is first stored in the database, and later used without being validated or encoded. The injection opportunity occurs in the second operation, hence the name "second order".

A simple example:

  • A vulnerable webapp allows users to save their usernames.

  • An attacker can provide a malicious payload as their username, e.g. jeremy'); DROP TABLE users;-- -

  • Later, when the application tries to fetch the username for an operation (e.g., greeting a returning user), it executes the malicious payload.

This type of attack can lead to:

  1. Data loss or corruption.

  2. Compromise of the database.

  3. Sensitive data exposure.

  4. Remote code execution.

Other learning resources:



Last updated