PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to make CakePHP validation more secure?

 April 22, 2022     cakephp, cakephp-2.3, validation     No comments   

Issue

Recently I finished tutorial about create simple blog using CakePHP - here is link: http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html Creating validation form is very easy and fast, but I noticed one issue with that.

File named post.ctp contains:

  echo $this->Form->create('Post');
  echo $this->Form->input('title');

And it generates form to end user with this input:

<input id="PostTitle" type="text" required="required" maxlength="50" name="data[Post][title]">

Someone who is using Firefox Firebug can change the html code before submit form from: name="data[Post][title]" to: name="data[Post][author]". The result of this will update column named "author", not "title", and also allowing to update database with empty data for "title".

In the folder named "Model" validation rule in Post.php doesn't prevents that:

class Post extends AppModel {

public $validate = array(
    'title' => array(
        'rule' => 'notEmpty'
    ),
    'body' => array(
        'rule' => 'notEmpty'
    )
);

}

How to secure my application and not allow someone to update other columns in database?


Solution

Cake's security component includes form tampering protection. You will need to add the security component in your controller(s):

public $components = array('Security');


Answered By - Bill Rollins
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing