Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP: Proper way to delete a record securely
    primarykey
    data
    text
    <p>I have this in my Controller.</p> <pre><code>public function delete($id) { if($this-&gt;request-&gt;is('get')) { throw new MethodNotAllowedException(); } $this-&gt;Memberlist-&gt;id = $id; if (!$this-&gt;Memberlist-&gt;exists()) { throw new NotFoundException(__('Invalid list.')); } if ($this-&gt;Memberlist-&gt;delete()) { $this-&gt;Session-&gt;setFlash(__('List deleted.'), 'success'); return $this-&gt;redirect(array('action'=&gt;'index')); } $this-&gt;Session-&gt;setFlash(__('List was not deleted.'), 'error'); return $this-&gt;redirect(array('action'=&gt;'index')); } </code></pre> <p>My Model looks like this: (belongsTo)</p> <pre><code>&lt;?php class Memberlist extends AppModel { public $name = 'Memberlist'; public $belongsTo = array( 'Account' =&gt; array( 'className' =&gt; 'Account', 'foreignKey' =&gt; 'account_id' ) ); </code></pre> <p>In one of my views, I have something like this:</p> <pre><code>echo $this-&gt;Form-&gt;postLink('Delete', array('action' =&gt; 'delete', $list['Memberlist']['id']), array('class'=&gt;'btn-mini btn', 'confirm' =&gt; 'Are you sure?')); </code></pre> <p>Which creates a HTML like this:</p> <pre><code>&lt;form id="post_4fe15efc0d284" method="post" style="display:none;" name="post_4fe15efc0d284" action="/Grid/memberlists/delete/9"&gt; &lt;input type="hidden" value="POST" name="_method"&gt; &lt;input id="Token1627936788" type="hidden" value="8756f7ad21f3ab93dd6fb9a4861e3aed4496f3f9" name="data[_Token][key]"&gt; &lt;div style="display:none;"&gt; &lt;/form&gt; &lt;a class="btn-mini btn" onclick="if (confirm('Are you sure?')) { document.post_4fe15efc0d284.submit(); } event.returnValue = false; return false;" href="#"&gt;Delete&lt;/a&gt; </code></pre> <p>The problem is that when I update the <code>ID</code> found in <code>action="/Grid/memberlists/delete/9"</code> using Firebug (or any developer tool), I can pretty much delete anything! Even from a different account. Even though I have the Security Component turned on.</p> <p>What would be the proper way to do this? I am thinking of checking the <code>account_id</code> against the account_id of the currently logged-in user. But I am just curious if CakePHP has something out-of-the-box that fixes this issue?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload