4 ms·
I think this illustrates fairly clearly one of the problems that I encounter in web app code all the time: prevention of SQL injection attacks is covered last.
by IgorPartola 17y ago
I think this illustrates fairly clearly one of the problems that I encounter in web app code all the time: prevention of SQL injection attacks is covered last. This makes novice developers think that it is an optional step or something that can be put off until the functional portion of the code is done. Instead it should be taught as soon as databases are discussed. Better yet, don't even give the student the option to write queries with unescaped data. Instead teach them that you have to use prepared statements, etc. and that's the only way to use databases. I would rather see secure code that's a bit obtuse, than a half baked concise code that leaves gaping holes or, worse yet, relies on silliness like PHP's magic quotes.
- moron4hire 17y agoThe number of new hires (all but one, and that kid actually turned out to be a college dropout. Unfortunately the company got rid of him even though he knew his stuff because he lied about having a 4 year degree) that I've had to teach what a prepared statement was has been really rather ludicrous. In a basic CRUD web app, there should be no reason to be building string-based queries, ever.
- IgorPartola 17y agoThe only case I can make for not using them is that in PHP the MySQL prepared statements API is very cumbersome. At my job, we use an ORM PHP abstraction model that could really benefit from prepared statements, but because of the difficulty of getting a simple associate array of data out of an executed prepared statement, it is nearly impossible for us to convert it to use them. But yes, the benefits clearly outweigh the drawbacks: you get security and performance.
- moron4hire 17y agoNot really an excuse. Layers of abstraction are all about hiding difficulties with using APIs. If PHPs API for accessing prepared statements is cumbersome, then write a wrapper around it that solves the problem once. Hell, I even did it for ADO.NET. ADO.NET is not that hard to use, but a surprising number of developers get a lot of the details wrong, such as when to open and close a connection (i.e. NOT once for every query) and when to dispose objects (at least at some point in the object's lifetime, please!). So, I wrote an ADO.NET wrapper that handles all of that stuff, providing an incredibly thin, simplistic interface. It's been very useful to me, and hopefully other people can find it useful, http://sqlsiphon.codeplex.com http://sqlsiphon.codeplex.com
- ikhare 17y agoI do agree here. As I mentioned the first version of the class was both security and programming. The projects were intermingled giving students A great overview. Unfortunately in the 10 weeks of the quarter it's hard to cover both in great depth giving only a cursory understanding of both. There is a separate great intro to security class cs155 (which I also TAed). I believe the professors were thinking of creating a class entirely on web security at some point. I will add however that as security gets baked into frameworks, students are not at least pickng up bad habbits. Wow this is hard to write on an iPhone :-)
- IgorPartola 17y agoWell, I can certainly appreciate a separate security based course. However, my point that preventing SQL injections should not be viewed as security. Just like you shouldn't write code that takes as input other code and blindly runs it on the server; or serves any file on the server without any sort of checks. Using prepared statements, or if you can't, at least manually escaping user data, is part of writing functional code. A program that does not do this is not functional and as much as writing down an example that shows how to do it breeds bad code.