How to lose data in CakePHP

by timtrice on 20 February 2009

I finally sat down to figure out why scripts for my hurricane website were acting up.  All I knew is for some reason certain yearly archives were not displaying via the pages or by direct linking.  My initial thought was that, for some reason, the for loop in my view was skipping iterations.  After crossing that out I used debug in the controller to see yet again much of the data was not pulling from the database.  Of course, I found that the issues lied in the tables themselves.  Somehow my database went from over 35,000 records of hurricane data to just a small inconspicuous few.

I spent a couple of hours correcting the information (though am still missing all of 2008’s hurricane data) to realize the problem was so freaking simple that I forgot to properly prepare my website prior to publishing.  I had scaffolded most of the controllers that held the information.  And because I did not remove that scaffolding, it allowed anyone who was familiar with CakePHP to edit and delete any and/or all of my records.

It’s a stupid mistake.  A very stupid mistake.  A lazy, thoughtless rush to go live that I did not run through my checklist as I should have.  Though this should not be confined to CakePHP programmers, all should understand the importance of even the smallest details going unchecked.  By allowing the scaffold variable in my controllers I was essentially giving anyone the permission to access domain.com/controller/delete and by overcoming the sole obstacle, a javascript verification box completely delete my records.  It’s easy to forget to remove that one variable line in the controller.  But absolutely costs in the long run.  Luckily my backups came in handy and I was able to restore the data and fix the issues in no time at all. Unfortunately for me I’ll be spending a few hours this weekend retrieving old data I did not have backed up.

Before going live, check all possible scenarios.  Should this instance occur again, I or you may not be so fortunate!

{ 2 comments… read them below or add one }

ian villanueva 13 March 2009 at 4:44 am

What an experience. Luckily i have not implemented scaffolding to my site. The site i developed is already live but i still have implemented some security hehe..

Thanks for the advice.

Reply

Clint 29 June 2009 at 3:12 pm

Hi Tim. Thanks for the article. I noticed you mentioned that you did not run through your checklist before making the app live. Ive been looking for a cakephp pre-production checklist but cant seem to find one. Would you be able to post yours.

Thanks!

Clint

Reply

Leave a Comment

Previous post:

Next post:

On Facebook On Twitter On YouTube On LinkedIn Get my free RSS feed Contact me