SQL injection

Overview
SQL injection is a type of attack. The attack uses vulnerabilities in an application's input validation or data typing.

When successful, the attack allows the attacker to inject data into an existing SQL query. The attacker may then be able to fetch private data, cause a denial of service or cause other unintended responses. In the worst case, the injected code would allow the attacker to gain full control of the system by exploiting multiple vulnerabilities in the database server, system utilities and operating system.

For an overview of SQL injection attacks, review Wikipedia's SQL Injection page.

Example
The following code snippet would allow an attacker to execute their own SQL commands (and is a syntax error in Oracle). For example, to fetch the email addresses of registered wiki users, the attacker would use a GET string of

The preferred way to run the above query would be:

SQL Injection and MediaWiki
MediaWiki has a custom SQL generation interface which has proven to be effective for eliminating SQL injection vulnerabilities. The SQL generation interface also provides DBMS abstraction and features such as table prefixes.

To keep MediaWiki safe from SQL injection:
 * avoid using direct SQL queries at all costs;
 * review Manual:Database access and use the functions provided in Database.php; and
 * read the The Open Web Application Security Project's page on SQL injection (http://www.owasp.org/index.php/SQL_Injection).