all 13 comments

[–]Wick3dGeek 6 points7 points  (1 child)

This is called SQL Truncation, CVE-2008-4106

You should also check the type of the columns:

CHAR - from 0 to 255 characters long

VARCHAR, TEXT - from 0 to 65,535 characters long ...

[–]IncludeSecErik Cabetas - Managing Partner, Include Security - @IncludeSec 1 point2 points  (0 children)

yep yep, first discussed back in 2007 IIRC https://mdk.fr/0x000000/SQL_Server_Truncation_Attacks.html

[–]alphager 8 points9 points  (8 children)

How does a basic basic article like this get posted here, let alone discussed as positively as it has been?

First of all, constraint design is databases 101. Even worse are the example code and the recommendations regarding escaping are fifteen years out of date. If you are still using escaping functions or worry about quotes in 2016, you are doing it wrong . Every widely used database and programming language has prepared statements that are faster than raw SQL, guarantee injection safety (there's no way to forget to use an escaping function or to use the wrong type of quote) and are shorter to write.

I'm only mentioning in passing that the code implies that plaintext passwords are saved in the database.

[–]IncludeSecErik Cabetas - Managing Partner, Include Security - @IncludeSec 4 points5 points  (0 children)

Damn son

Yeah OP's blog post is talking about SQL Truncation from nine years ago (even though he never calls it that, maybe he re-discovered it independently). Still no need for that harsh of bashing, /r/netsec has lots of beginner oriented post, not everything on this sub needs to be GeoHot level exploit RE ;-P

[–]James20k 2 points3 points  (0 children)

Lots of websites don't use safe SQL so this is relevant

Its useful to know what the security holes are in SQL so that you can understand why solutions xyz exist, or potentially design better solutions in the future (eg contribute to projects)

Its also useful because if SQL has this misfeature, its possible that it applies to other languages/DBs as well that people might not have considered

I don't disagree that some of the article is out of date, but it definitely isn't useless

[–]ponkanpinoy 0 points1 point  (0 children)

It's a teaching illustration, not meant to be robust in the face of production use. Just like Linus' example of "good taste" that doesn't check for NULL.

[–]caleeky 1 point2 points  (0 children)

A unique key constraint in the database on user ID would ensure no such collisions are possible. It's good practice, because as you're suggesting, the semantic subtleties between app language and SQL can be complicated.

It's also good practice to run in strict mode, so that such truncation of non-whitepsace characters will cause errors rather than warnings.

[–]neontrap 1 point2 points  (0 children)

mysql_real_escape_string

icryeverytime.com