LoginSignup
0
0

More than 3 years have passed since last update.

Rails ActionController::InvalidAuthenticityTokenが出た理由

Last updated at Posted at 2021-03-23

結論

application.html.erbファイルのリファクタリング時に、tokenの埋め込みコードだと知らずにあやまって消してしていた。

間違え

application.html.erb
- <%= csrf_meta_tags %>
- <%= csp_meta_tag %>

正しい

application.html.erb
+ <%= csrf_meta_tags %>
+ <%= csp_meta_tag %>

 最後に

あの2行のコードが、トークンに関するコードだという事がわかった。

参考
https://github.com/rails/rails/blob/main/actionpack/lib/action_controller/metal/request_forgery_protection.rb#L14
https://makicamel.hatenablog.com/entry/2019/03/06/230344
https://stackoverflow.com/questions/42795288/rails-how-to-implement-protect-from-forgery-in-rails-api-mode

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0