Domanda

Sto cercando di utilizzare il componente Security per evitare attacchi CSRF e se utilizzo il formhelper per creare il ticket utilizzando un postlink, come questo, fallisce:

<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $user['User']['id']),  array('class' => 'button mini'), __('Are you sure?', $user['User']['id'])); ?>
.

Non sono sicuro che questo sia possibile o CakePHP consentire solo questa funzione utilizzando i metodi Crea () e End () di Formhelper.

Documentazione di cakephp solo dice che èè obbligatorio usare il formhelper ma non specifica molto di più.

È stato utile?

Soluzione

Quando si ha abilitato il componente di sicurezza e si utilizzano i metodi di formhelper per tutti i moduli che non devi preoccuparti di questo.Inoltre, non devi configurare nulla.Funziona fuori dalla scatola.

Per CSRF è possibile utilizzare le seguenti opzioni:

property SecurityComponent::$csrfCheck
Whether to use CSRF protected forms. Set to false to disable CSRF protection on forms.

property SecurityComponent::$csrfExpires
The duration from when a CSRF token is created that it will expire on. Each form/page request will generate a new token that can only be submitted once unless it expires. Can be any value compatible with strtotime(). The default is +30 minutes.

property SecurityComponent::$csrfUseOnce
Controls whether or not CSRF tokens are use and burn. Set to false to not generate new tokens on each request. One token will be reused until it expires. This reduces the chances of users getting invalid requests because of token consumption. It has the side effect of making CSRF less secure, as tokens are reusable.
.

Se hai tutto su di te dovrebbe vedere i token CSRF nell'Html del modulo.Puoi impostare ulteriori opzioni che ti piace, ma funzionerà praticamente fuori dalla scatola per te.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top