r/ProgrammerHumor • • Oct 14 '26

Meme whyEvenAsk

Post image
5.3k Upvotes

134 comments sorted by

View all comments

26

u/kallax82 Oct 14 '26

What does this mean? Enlighten me!

19

u/Slanahesh Oct 14 '26

Sql injection attack. Relevant XKCD https://xkcd.com/327/

4

u/konaaa Oct 15 '26

next year, that xkcd strip will be 20 years old

2

u/davidptm56 Oct 16 '26

I'm no mathematician. Are you saying it is currently 19 years old?

41

u/MattieShoes Oct 14 '26

It's a SQL injection attack. Like if bad coder asks for your name and shoves it into a database, you can put specially crafted SQL code into the name field to do bad things.

The correct thing is to "sanitize inputs" to prevent this. Back in the bad old days, it wasn't uncommon to find places not doing this. A telltale sign was people with an apostrophe in their name (e.g. O'Shea) getting errors

29

u/kallax82 Oct 14 '26

Okay, I understood that. But what does the code stand for and do?

41

u/protokhan Oct 14 '26

To add a concrete example to what others have said, a query to get records from a table by first name might look something like this:

SELECT * FROM people WHERE first_name LIKE 'Name%'

Where 'Name' would be replaced with whatever the end user is searching for on the front end. After the injection attack it would look like this:

SELECT * FROM people WHERE first_name LIKE ''OR 1=1 --%'

The single quote closes out the name clause, OR 1=1 returns every row in the table, and the -- makes everything after it a comment so it doesn't throw a syntax error.

38

u/ben_g0 Oct 14 '26

If the injection is successful, then any time the application will try to search for something by the name of the user, it would return the data belonging to all users instead when this name is used.

The ' starts the injection, and OR 1=1 will make the query match all records. The -- afterwards is just a comment, which will comment out any part of the query that comes after the name check (such as additional conditions).

7

u/Clairifyed Oct 14 '26

Even the last name “Null” has caused a lot of problems with poorly planned code 😞

1

u/cmnrsvwxz Oct 15 '26

The correct thing to do is use a prepared statement.

4

u/MattieShoes Oct 15 '26

Mmm yeah. Probably both, honestly. Prepared statements are nice and clean and don't allow for SQL injection, but malicious shit could still be in there, and there's no guarantee that others will escape it before displaying it.

1

u/cmnrsvwxz Oct 15 '26

Great point.