LogoPhly, boy, phly
the weblog and site of Matthew Weier O'Phinney

Sunday, October 16. 2005

Review: php|architect's Guide to PHP Security

I flew in to San Jose today to visit Zend, and later attend the Zend/PHP Conference and Expo (two days left... register now if you haven't, and have the time to attend; the conference sessions promise to be very interesting).

During the flight, I had plenty of time to go through Ilia's Guide to PHP Security, which I'd ordered several weeks ago, but hadn't had time to read since.

The thing about PHP security, and web security in general, is that there are some very simple rules that have been around for a long time, most important of which is: never trust your users.

Perl developed a special mode, taint mode, to deal with user input -- if input hasn't been filtered and verified, it's considered tainted (and the standard method for doing so is passing the data through a regexp). Additionally, it's considered good practice in perl to 'use strict' and 'use warnings', as these two pragmas will let the developer know when they're succumbing to bad habits.

Ilia takes the lens of security and applies it to the PHP language. His book is a pragmatic look at how to safely handle user input to prevent such things as XSS attacks, SQL injection, and more. Most importantly, he explains what the various dangers are, gives some examples of how to create the attacks -- and then some methods for defending your script from them.

Covered are XSS attacks, SQL injection, code injection (via include files), command injection, sessions, and session hijacking. He also has some tips on being proactive -- building sandboxes and tar pits in which to monitor hacker activity so you can see what you're up against.

I found that much of the theory that Ilia writes about is not new. However, his examples often contained some nuggets of experience I'd never considered. For instance, I have often used ImageMagick, but never considered what would happen if I tried to convert an animated GIF to another format (it creates several files, one for each frame) -- and how that might affect my script (the expected filename will not be present). Nor had I considered that character input may actually come in encoded -- which would often be either invalid for the filters I create, or completely bypass them.

On one particular point, I feel I must congratulate Ilia: he details the complexity of creating secure applications, and also goes to some lengths to show how just about any countermeasure can still be foiled by a determined hacker. 100% secure applications that utilize user input are virtually impossible -- but that doesn't mean we shouldn't strive for that goal.

The book is well written, in a conversational, almost conspiratorial, voice. (Having had the pleasure of attending a session of Ilia's at php|Tropics, I can say that his written voice is very similar to his presentation voice, and very easy to follow.)

However, the book suffers from what appears to me to be quick editing -- there are quite a number of typographical errors throughout (I'd say, on average, one every three pages), and a few areas where large sentences or paragraphs should have been rewritten prior to publication. Layout also had a few issues; on page 87, for instance, the page number was injected into the text of the third paragraph, instead of placed at the page bottom, and many examples started with a single line on the end of one page and continued on the following page (a page break prior would have made these easier to read).

All told, however, these editing and layout issues did not subtract from the message. Ilia's book is a strong wake-up call to any php developer worth his or her salt, and should be a part of any PHP developer's library.

Posted by Matthew Weier O'Phinney in PHP at 18:53 | Comments (0) | Trackbacks (0)

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

 
 
  • Home
  • Resume
  • Blog
  • Phly PEAR Channel
  • Contact Me
  • About this site

ZCE

Zend Education Advisory Board Member

Add to Technorati Favorites

Calendar

Back November '08 Forward
Mon Tue Wed Thu Fri Sat Sun
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Quicksearch

Links

  • PHLY - PHp LibrarY
  • Paul M. Jones
  • Mike Naberezny
  • Shahar Evron
  • Planet PHP
  • Zend Where I now work
  • Garden.org Where I once worked

Archives

November 2008
October 2008
September 2008
Recent...
Older...

Categories

XML Linux
XML Personal
XML Aikido
XML Family
XML Programming
XML Dojo
XML Perl
XML PHP

All categories

Syndicate This Blog

XML RSS 0.91 feed
XML RSS 1.0 feed
XML RSS 2.0 feed
ATOM/XML ATOM 0.3 feed
ATOM/XML ATOM 1.0 feed
XML RSS 2.0 Comments

Show tagged entries

xml best practices
xml books
xml conferences
xml dojo
xml dpc08
xml file_fortune
xml linux
xml mvc
xml oop
xml pear
xml personal
xml php
xml phpworks08
xml programming
xml ubuntu
xml vim
xml webinar
xml zendcon
xml zendcon08
xml zend framework
© 2004 - present, Matthew Weier O'Phinney
matthew-web <at> weierophinney.net