断続的なRails5 ActionController :: InvalidAuthenticityToken

ybakos

コンテキスト:Herokuでホストされ、約800人のユーザーがいる本番環境のRailsアプリ。

  • Ruby 2.4.2
  • Rails 5.1.4
  • Devise 4.3.0

何らかの理由で、いくつかのユーザーがエラーを経験するのを見ました:

ActionController::InvalidAuthenticityToken

[GEM_ROOT]/gems/actionpack-5.1.4/lib/action_controller/metal/request_forgery_protection.rb:195

へのリクエストの場合POST /students/:id/registrations

これは断続的であり、エラーが発生するユーザーはほとんどいません。

クライアントはiPad上のSafari11.0です。

ApplicationController:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :authenticate_user!, unless: :devise_controller?
  before_action :restrict_from_students, unless: :devise_controller?
  # ...
end

RegistrationsController:

class RegistrationsController < ApplicationController
  skip_before_action :restrict_from_students, only: :create
  # ...
end

これを引き起こすシナリオ(リクエストの再POST、認証タイムアウトだが送信、JSの欠如)はありますか?再現できないようです。

ybakos

ゴム製のアヒルのおかげで、私は問題を再現しました。

  1. サインアウト
  2. キャッシュされたアプリのUIに「戻る」。
  3. ボタンをクリックして、POSTリクエストを生成します。
  4. 例外を観察します。

ここでの解決策はrescue_from、ユーザーをサインインページにリダイレクトするために使用することです。

ラバーダックありがとう!

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Rails5のActionController :: InvalidAuthenticityToken

分類Dev

Intermittent Rails 5 ActionController::InvalidAuthenticityToken

分類Dev

ActionController :: InvalidAuthenticityToken

分類Dev

Rails 5 ActionController :: InvalidAuthenticityTokenエラー

分類Dev

Rails 5 ActionController :: InvalidAuthenticityToken on Production Enviroment Nginx

分類Dev

通常のActionController :: InvalidAuthenticityToken例外-Rails

分類Dev

Rails上のrubyのActionController :: InvalidAuthenticityToken

分類Dev

ActionController :: InvalidAuthenticityToken Rails 5 / Devise / Audited / PaperTrail gem

分類Dev

Rails6の別のActionController :: InvalidAuthenticityToken

分類Dev

Rails4 ActionController :: InvalidAuthenticityTokenエラー

分類Dev

Rails 5.0.0beta3:開発中のActionController :: InvalidAuthenticityToken

分類Dev

SessionsController#destroyのActionController :: InvalidAuthenticityToken

分類Dev

Rails 5 InvalidAuthenticityToken Coffeescript

分類Dev

Api :: V1 :: UsersController#createのActionController InvalidAuthenticityToken

分類Dev

ActiveAdmin :: Devise :: SessionsController#createのActionController :: InvalidAuthenticityToken

分類Dev

Rails 6 - InvalidAuthenticityToken on Heroku

分類Dev

ActionController :: InvalidAuthenticityTokenで失敗する足場テスト

分類Dev

パスワードの更新時のActionController :: InvalidAuthenticityToken

分類Dev

webpack jquery ajax rails 5 InvalidAuthenticityToken

分類Dev

nginxを使用してhttpsリクエストを他のnginx(http)にプロキシし、rails(http)にプロキシする場合のActionController :: InvalidAuthenticityToken

分類Dev

rails 4.2.0 ActionController :: UrlGenerationError

分類Dev

Rails6-HerokuのInvalidAuthenticityToken

分類Dev

SSLを使用したNginxの背後にあるRails5のInvalidAuthenticityToken

分類Dev

Rails5のRubyで「ActionController :: RoutingError(初期化されていない定数someController)」エラーを修正する方法

分類Dev

Railsの処理ActionController :: BadRequest

分類Dev

Rails 5 InvalidAuthenticityToken、ただしトークンが存在する

分類Dev

Rails 5 ActionController :: ParameterMissingを処理する方法

分類Dev

Rails 4.2 InvalidAuthenticityTokenエラー、ただし本番環境でのみ

分類Dev

RailsアプリケーションのHTTPS-InvalidAuthenticityToken

Related 関連記事

  1. 1

    Rails5のActionController :: InvalidAuthenticityToken

  2. 2

    Intermittent Rails 5 ActionController::InvalidAuthenticityToken

  3. 3

    ActionController :: InvalidAuthenticityToken

  4. 4

    Rails 5 ActionController :: InvalidAuthenticityTokenエラー

  5. 5

    Rails 5 ActionController :: InvalidAuthenticityToken on Production Enviroment Nginx

  6. 6

    通常のActionController :: InvalidAuthenticityToken例外-Rails

  7. 7

    Rails上のrubyのActionController :: InvalidAuthenticityToken

  8. 8

    ActionController :: InvalidAuthenticityToken Rails 5 / Devise / Audited / PaperTrail gem

  9. 9

    Rails6の別のActionController :: InvalidAuthenticityToken

  10. 10

    Rails4 ActionController :: InvalidAuthenticityTokenエラー

  11. 11

    Rails 5.0.0beta3:開発中のActionController :: InvalidAuthenticityToken

  12. 12

    SessionsController#destroyのActionController :: InvalidAuthenticityToken

  13. 13

    Rails 5 InvalidAuthenticityToken Coffeescript

  14. 14

    Api :: V1 :: UsersController#createのActionController InvalidAuthenticityToken

  15. 15

    ActiveAdmin :: Devise :: SessionsController#createのActionController :: InvalidAuthenticityToken

  16. 16

    Rails 6 - InvalidAuthenticityToken on Heroku

  17. 17

    ActionController :: InvalidAuthenticityTokenで失敗する足場テスト

  18. 18

    パスワードの更新時のActionController :: InvalidAuthenticityToken

  19. 19

    webpack jquery ajax rails 5 InvalidAuthenticityToken

  20. 20

    nginxを使用してhttpsリクエストを他のnginx(http)にプロキシし、rails(http)にプロキシする場合のActionController :: InvalidAuthenticityToken

  21. 21

    rails 4.2.0 ActionController :: UrlGenerationError

  22. 22

    Rails6-HerokuのInvalidAuthenticityToken

  23. 23

    SSLを使用したNginxの背後にあるRails5のInvalidAuthenticityToken

  24. 24

    Rails5のRubyで「ActionController :: RoutingError(初期化されていない定数someController)」エラーを修正する方法

  25. 25

    Railsの処理ActionController :: BadRequest

  26. 26

    Rails 5 InvalidAuthenticityToken、ただしトークンが存在する

  27. 27

    Rails 5 ActionController :: ParameterMissingを処理する方法

  28. 28

    Rails 4.2 InvalidAuthenticityTokenエラー、ただし本番環境でのみ

  29. 29

    RailsアプリケーションのHTTPS-InvalidAuthenticityToken

ホットタグ

アーカイブ