Answer the question
In order to leave comments, you need to log in
How does CSRF work in yii2?
How does CSRF work in yii2?
Most interested in how the token is verified
Answer the question
In order to leave comments, you need to log in
And look into the source code and see for yourself - how everything is done there? There is nothing complicated there.
Hello! in yii2 it is not necessary to check the token, it will check it itself
if (!$this->enableCsrfValidation || in_array($method, ['GET', 'HEAD', 'OPTIONS'], true)) {
return true;
}
I have a problem that the token that the form passes is not the same as in the meta tag, and a 400 error occurs
"Shit" works. The doc doesn't say anything about it. In principle, there is not much written about it.
I can't tell you how it works, but I can show you how it works.
<?php
/** @var $this yii\web\View */
$this->registerMetaTag(['name' => 'csrf-param', 'content' => Yii::$app->request->csrfParam]);
$this->registerMetaTag(['name' => 'csrf-token', 'content' => Yii::$app->request->getCsrfToken()]);
?>
<form action="#" method="posts">
<!-- inputs -->
<input type="hidden" name="<?= Yii::$app->request->csrfParam ?>" value="<?= Yii::$app->request->getCsrfToken() ?>"/>
<!-- submit -->
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question