문제

CSRF 공격을 피하기 위해 보안 구성 요소를 사용하려고하고 FormHelper를 사용하여 포스트 링크를 사용하여 티켓을 만드는 경우 실패합니다.

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

이것이 가능하거나 CakePHP가 FormHelper의 create () 및 end () 메서드를 사용 하여이 기능을 허용하는지 확실하지 않습니다.

CakePHP 문서 는 그게 전용입니다.FormHelper를 사용하는 것은 필수적이지만 훨씬 더 지정하지는 않습니다.

도움이 되었습니까?

해결책

보안 구성 요소가 활성화되어 있고 모든 양식에 대해 FormHelper 메소드를 사용하면이 문제에 대해 걱정할 필요가 없습니다.또한 아무 것도 구성 할 필요가 없습니다.그것은 상자에서 작동합니다.

CSRF의 경우 다음 옵션을 사용할 수 있습니다.

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.
.

모든 것을 가지고있는 경우 양식의 HTML에 CSRF 토큰이 표시됩니다.원하는 추가 옵션을 설정할 수는 있지만 사용자를 위해 꽤 많이 작동합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top