15 Jul 08 _ CakePHP 1.2 RC2 + Security Component


By casey
in CakePHP, Casey's Corner

I’ve been wrangling with the Cake’s Security Component for the past day, not having the best time with it. If you’ve been trying to use it, you may have noticed that there seems to be near-total lack of documentation on it. Not cool.

So I was trying to use it to make some simple HTTP Authentication requests for a WebTree site of ours. It turns out that whenever the Security Component is initialized in a controller, it requires that all POST-ed data in that controller be validated through the Security Component. For this to work correctly, and not spit you out into a blank page “black hole,” you have to use the Form Helper for every form that needs to be submitted, making sure to use $form->end().

It looks like the Form Helper builds a Hash number based on the name of the fields included in the form and the Security Salt that you set in the config/core.php.

When the form is submitted, a function, __validatePost(), runs automatically, there is currently no way to turn it off, and tries to make the same hash value as all the fields present in the Controller’s $data variable. If the two hash values are the same, we know that no extra data is being submitted directly to the controller, and we proceed with the normal course of things. If they don’t match, we trigger the Black Hole callback function, and go down that route.

Except that in the current RC2 release (7296), there is a bug in the Security Component that will ensure that these two hashes will never be equal.

The problem is in line 662 of /cake/libs/controller/components/security.php:

$check = md5(urlencode(Security::hash(serialize($field) . Configure::read('Security.salt'))));

Should be:

$check = urlencode(Security::hash(serialize($field) . Configure::read('Security.salt')));

Take out the md5() function. Form Helper’s security function that generates the form’s hash value does not include the extra md5 hashing function. It looks like this was fixed in the nightly build.

This will alleviate some of your potential issues using the Security Component. However, if you just want to use some aspects of the component, such as HTTP Auth, there is no way to disable the POST validation, much to my chagrin. Maybe it will change in the future.

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine


5 Responses to “CakePHP 1.2 RC2 + Security Component”

  1. Jeremy Hicks Says:

    I’ve got this same problem. As soon as I add Security to the component array, I get the blank page back when trying to add or update. I’m doing this in my AppController. I want to use requireSecure so that all my pages have to use SSL. I’m using a newer version of Cake and I verified that the line of code you specified has the required change and yet I still have this problem.

  2. casey Says:

    One thing you can do to try to trac down this problem is checking that the data submitted your controller is the same as the data seen by your form helper.

    Also, make sure that you’re not using $form->secure(), even though you think you would use it. You should only have one [__Token] and one [__key] field in your HTML.

    At this point, though, I’ve thought about copying the Security Component from the cake core into my app/controllers/components, and removing the whole amount of code dedicated to the posted data check. That way I can get the benefits of all the other stuff (like forcing SSL) without that annoying check.

  3. Zach Wilson Says:

    Casey,

    I’m having a similar issue, however, the trigger now seems to be using the form helpers input on multiple checkbox’s. My best guess is that the hash isn’t taking into account fields that are using the data[Model][fieldname][] syntax. Unfortunately, I haven’t been able to _fix_ this yet.

    There does seem to be a bug for this:
    https://trac.cakephp.org/ticket/5129#comment:description

    I hope this gets fixed very soon. It’s kill me for an element of a project i’m working on.

    If you have any more insights, i’d be happy to hear.

  4. Kjell Says:

    I can confirm this bug.

    Took me a while till i found the reason (this post) and by debugging it manually (what a pain).

    But i have to report that the fix posted here doesn’t work. In my revision and in the CakePHP trunk the md5() function isn’t called. So nothing to remove.

    I was unable to fix it myself and so i am too hoping that the mentioned ticket is closed soon. This issue makes the whole Component useless. :(

    BTW. i encountered this problem because i had radio buttons in my form. Probably really “just” a traversing issue.

  5. archF6 Says:

    I was having terrible blackhole problem for hours — every AJAX form submission was being invalidated. Your post saved me (using echo $form->end(); to end the form!). So thanks. A lot.


Leave a Reply

  • guitar modification parts
  • butcher paper roll dispenser
  • makers of dog kennels
  • credit card debt relief program
  • billet grills
  • studio rta the bug computer desk
  • shark cordless cyclonic hand vacuum
  • toastmaster parts toaster
  • men's suits shirts barney
  • saucony shoes outlet stores
  • 1 2 decorative square post caps
  • fruit of the loom union suits
  • maine snowmobile insurance requirements
  • boyne mountain grand lodge and spa
  • triple pet natural toothpaste
  • used kids dirt bikes for sale
  • 30 inch slide in electric range
  • create pdf word embed fonts
  • wholesale jelly jars
  • water as fuel denny klein
  • couch replacement pillows
  • coleman bayside elite replacement parts
  • sponge bob crabby patty candy
  • wholesale winter gloves hats
  • best at home treatment for blackheads
  • tub refinishing pgh pa
  • tile shower seat vintage
  • caught wearing high heels split skirt
  • kawasaki kx85 parts and exploded view
  • india and business dress
  • kid's camp crafts
  • cuff bracelets wholesale
  • golf gps systems reviews
  • wholesale patio pool furniture
  • crystal on the plaza
  • global travel shoes
  • spectrum products tanning bed
  • 84 wide wooden window blinds
  • consigning my lilly pulitzer clothes
  • no smoking rooms in boston hotels
  • aubrey organics skin cleanser
  • home decor liquidators furniture and flooring
  • hair regrowth products reviews
  • black bean corn citrus vinegar
  • jt paintball gear
  • how to create finger nail designs
  • popup tent cleaning
  • knife sound editing
  • hippie chick costumes
  • miniature surveillance cameras detection
  • hd high def video edit
  • recycle styrofoam cups
  • bamboo patio door blinds
  • money order promise rings
  • resurfacing bathtubs
  • mens star earrings
  • spray face foundation
  • remote home thermostats
  • phoenix skin rejuvenation
  • shower enclosures walls
  • kawasaki 440 aircraft engine parts
  • women's clothing sleep shirts
  • material requirements planning mrp systems
  • cryoserver back email compliance archiving message
  • home flea infestation
  • cuisinart 9-speed hand mixer brushed chrome
  • wholesale military surgical caps
  • nike drawstring backpack lavender
  • acutane colon problems
  • mercedes 320 wagon tires
  • ucla womens basketball camps
  • vida international fruta
  • kids camp crafts
  • compliance corporate email
  • good feet store onalaska wi
  • coach purse party
  • women's shoulder handbags
  • diy exterior patio blinds
  • pivot tub shower enclosures
  • dog harness and collar
  • shoi racing helmets
  • free shawl knit patterns
  • thyme essential oil price
  • tubeless bicycle wheels road
  • black edition magazine man swimsuit
  • 5 star car wax
  • italian charm bracelets wholesale
  • sleep t shirts
  • audio cards upside down
  • dell 5100cn colour network laser printer
  • fj cruiser trailer hitch receivers
  • sell structured settlement payment
  • organizational monitor stands
  • prom decorations and costumes
  • cats on behavior medication
  • golf palm computer gps system
  • budget wedding planning checklist
  • movie theater popcorn maker canada
  • water pump 3-inch suction hose
  • invest in stocks cheap
  • nike max air inline skates
  • star wars galactic heroes bedding comforter
  • airsoft outfitters gear
  • cheap new chevy trucks
  • discounted airfares cheapest airfares erfurt
  • floral furniture throws
  • schutt baseball equipment
  • acrobat distiller settings for news print
  • 2.4 to 3.8 s10 truck conversion
  • westgate villia resorts
  • fuzzy bunny slippers adult
  • shock doctor mouth pieces
  • midwest family vacations
  • red kap highland uniform shirts
  • play euchre free online
  • rockport shoes rosemont
  • elo entuitive touchscreen drivers
  • decorative garden pond fountains
  • kids online cake decorating games
  • america west airlines dividend miles program
  • in kind giving from popcorn company
  • camera ccd industrial
  • outdoor furniture pool harrows
  • raymond waites spring garland
  • lil boosie new mixtapes
  • household and cleaning forum
  • video piggy 1.3.0 crack