Note that there are some explanatory texts on larger screens.

plurals
  1. POSecurity Component and PostLinks
    primarykey
    data
    text
    <p>Using CakePHP 2.3. I turned on the security component, and I noticed an odd behavior with postLinks, where for some reason they are no longer seem to be transmitting data by POST, but instead they are using GET. In the action I'm trying to call, the first thing I do is to ensure that the data was made by POST:</p> <pre><code>if (!$this-&gt;request-&gt;is('post')) { throw new MethodNotAllowedException(); } </code></pre> <p>When the security component is on, this if statement is false. When it is off, the if statement is true. No other changes have been made.</p> <p>The postLink:</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;postLink($this-&gt;Html-&gt;image('icons/resend-icon.png'), array('action' =&gt; 'resend', $invoice['Invoice']['number']), array('escape' =&gt; false, 'class' =&gt; 'hastip', 'title' =&gt; 'Resend'), __('Are you sure you want to resend this invoice?')); ?&gt; </code></pre> <p>As far as I've been able to look, I've found no explanation for this. I would prefer if I could make sure the data is actually being sent by POST, though everything else works if I remove the check for the request is a POST.</p> <p>Edit: I've discovered that if I set $this->Security->csrfCheck = false; and $this->Security->validatePost = false; in the before filter for that particular action, it does not have this problem. I would still like to know why precisely this is though.</p> <p>Edit 2:</p> <p>After more investigation, I discovered the view of the page in question has another form on it, <code>echo $this-&gt;Form-&gt;create('Invoice', array('type' =&gt; 'get'));</code> which should not be affecting the post links in any way (post links are not inside the form, etc.), but if I remove the <code>array('type' =&gt; 'get')</code>, the postLinks start working. I need the other form to be of type get though, as it's a search form, and I need to have the search query string in the URL.</p> <p>Edit 3:</p> <p>I've discovered that moving the search form below the post links also fixes the problem. I tried running the markup through a html validator to make sure nothing was malformed, but it did not report anything.</p> <p>Edit 4: </p> <p>I discovered that the markup being generated for the PostLinks is incorrect -- the hidden inputs used for detecting CSRF are named incorrectly, resulting in it failing CSRF tests. Thus, the request is getting blackholed. I have set up a blackhole callback to redirect http:// to https://, so the page gets redirected, resulting in a new get request for the same page, which then gets rejected by the MethodNotAllowedException. Trying to investigate now why the PostLinks aren't being generated correctly.</p>
    singulars
    1. This table or related slice is empty.
    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