--> -->
#blog2navi() *Laravel5.6.9以上に移行すると419エラーが出る [#z51f51c1] * 概要 [#g836e1a5] 手元のシステムはLaravel5.4で動いていました。~ これを最新の6.xに移行したとき、頻繁に419 Session Expireエラーが出るようになった話です。~ ~ * 原因 [#o9a65ca1] 原因は、&inlinecode{Session::regenerate()};でした。~ セッションIDの再生成はセキュリティの観点から推奨される処理です。 このregenerate()ですが、Laravel5.6.9から、実行時にCSRF TOKENも再生性されるようになりました。 このregenerate()ですが、Laravel5.6.9から、実行時にCSRF TOKENも再生成されるようになりました。 ~[[regenerate the token on session regeneration:https://github.com/laravel/framework/commit/20e84191d5ef21eb5c015908c11eabf8e81d6212#diff-4f459c17aeff1731e066a607e3db9484]] 件のシステムは画面遷移時にほぼ毎回&inlinecode{Session::regenerate()}を実施していたため、エラーで&inlinecode{redirect()->back()}で戻った際などにTOKENが再利用される場合、419エラーが発生していたのでした。~ ソースを見ると、 件のシステムは画面遷移時にほぼ毎回&inlinecode{Session::regenerate()};を実施していたため、エラーで&inlinecode{redirect()->back()};で戻った際などにTOKENが再利用される場合、419エラーが発生していたのでした。~ regenerate処理の[[ソース:https://github.com/laravel/framework/blob/6.x/src/Illuminate/Session/Store.php]]を見ると、 #code(PHP,noline,nooutline){{{ /** * Generate a new session identifier. * * @param bool $destroy * @return bool */ public function regenerate($destroy = false) { return tap($this->migrate($destroy), function () { $this->regenerateToken(); }); } /** * Generate a new session identifier. * * @param bool $destroy * @return bool */ public function regenerate($destroy = false) { return tap($this->migrate($destroy), function () { $this->regenerateToken(); }); } }}} となっていて、migrate()実施毎にトークンを作り直しているので、「Session::regenerate()」を「Session::migrate()」とすることで回避しました。~ 一応publicですが[[マニュアル:https://laravel.com/docs/6.x/session]]には載っていないので、一応自己責任で・・・。 となっていて、migrate()実施後にトークンを作り直しているので、「Session::regenerate()」を「Session::migrate()」とすることで回避しました。~ アクセス修飾子は public ですが[[マニュアル:https://laravel.com/docs/6.x/session]]には載っていないので、一応自己責任で・・・。 #htmlinsert(twitterbutton.html) RIGHT:Category: [[[Linux>日記/Category/Linux]]] - 16:24:18 ---- RIGHT:&blog2trackback(); #comment(above) #blog2navi()