나는 다음과 같은 나뭇 가지 템플릿 콘텐츠로 Symfony2 security documentation를 통해이 로그인 양식을 가지고 :Symfony2, 로그인 폼 - CSRF 보호
<form action="{{ path('login_check') }}" method="post">
<div class="input form">
<label for="username">Account name or E-mail:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" />
</div>
<div class="input form">
<label for="password">Password:</label>
<input type="password" id="password" name="_password" required="required" />
</div>
<input type="hidden" name="_token" value="{{ csrf_token("intention") }}">
<button type="submit">Log In</button>
</form>
그리고이 양식에 CSRF 보호를 추가 할. 보시다시피,이 라인을 <input type="hidden" name="_token" value="{{ csrf_token("intention") }}">
에 추가했는데,이 보호 기능을 활성화하기에 충분하다면 정말로 확신 할 수 없습니다.
내 컨트롤러는 문서에 같은 형태를 가지고, 그래서 다음과 같습니다
<?php
// src/Acme/SecurityBundle/Controller/SecurityController.php;
namespace Acme\SecurityBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
class SecurityController extends Controller
{
public function loginAction()
{
$request = $this->getRequest();
$session = $request->getSession();
// get the login error if there is one
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
$error = $request->attributes->get(
SecurityContext::AUTHENTICATION_ERROR
);
} else {
$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
$session->remove(SecurityContext::AUTHENTICATION_ERROR);
}
return $this->render(
'AcmeSecurityBundle:Security:login.html.twig',
array(
// last username entered by the user
'last_username' => $session->get(SecurityContext::LAST_USERNAME),
'error' => $error,
)
);
}
}
그래서 단지 충분히 가치 {{ csrf_token("intention") }}
하나 개의 숨겨진 입력을 붙여 넣거나 내가 컨트롤러에 무언가를 추가해야입니까?
양식 "form_login"을 호출해야합니까? – Sekai
@Sekai 식별 로그인 양식의 구성 항목입니다. 이 항목에서 로그인 작업을위한 경로 또는이 대답에서 볼 수있는 것처럼 csrf 공급자에 대한 옵션을 설정합니다. –
그래, 동의하지만 양식 (임의의 문자를 추가)에서 토큰을 조작하고 양식을 제출하면 성공했다. 보호 기능은 어떻게 작동합니까? – Sekai