# 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.&#x20;
* 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:

*

### Writeups:

*

### Checklist:


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://appsecexplained.gitbook.io/appsecexplained/common-vulns/sql-injection-overview/second-order-sqli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
