6 SQL injection (and other injections)

 

This chapter covers

  • Learning how string concatenations lead to SQL injection
  • Understanding the consequences of SQL injection
  • Avoiding SQL injection with prepared statements
  • Using an OR (object-relational) mapper
  • Other types of injection attacks

In early March 2021, Ars Technica reported (see the following callout) that 70 GB of data was supposedly stolen from the infamous social media platform Gab. This data included passwords and other user data, private messages, and more. The reason: the code was vulnerable to SQL injection. This allowed an anonymous attacker to access and download this vast amount of data and to make it available to selected researchers.

note

See http://mng.bz/gwAE for the initial report, and http://mng.bz/5QOB for more details on the programming mistake.

6.1 Anatomy of an SQL injection attack

SQL stands for “Structured Query Language” and was invented in the 1970s to provide a language to communicate with a relational database to, among other things, read and write data to it. Even the creators (Donald D. Chamberlin and Raymond F. Boyce) probably could not imagine back then that their brainchild would still be in use almost 50 years later. That websites would send user input to a web server where it would be put in SQL queries that would then be executed against a database was certainly far from everyone’s imagination back then.

6.2 Prepared statements

 
 
 

6.3 Entity Framework Core

 
 
 
 

6.4 XML external entities

 
 
 
 

6.5 Other injections

 
 
 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest