[英]Rails form_authenticity_token doesn't match params[:authenticity_token]
在什么情況下form_authenticity_token與params [:authenticity_token]不匹配?
我看到未經驗證的請求進入我的應用程序,所以我重寫了form_tag以打印出一些調試信息。
form_auth_token: #{form_authenticity_token.inspect}
session_csrf_token: #{session['_csrf_token'].inspect}
params: #{params.inspect}
我得到的輸出顯示會話具有與form_auth_token匹配的正確令牌,但提交的參數authenticity_token不匹配:
form_auth_token: "gckttsVeq2XvTBwQX3BaInWCivIhvR/mYBWjs119eb8="
session_csrf_token: "gckttsVeq2XvTBwQX3BaInWCivIhvR/mYBWjs119eb8="
params: {"utf8"=>"✓", "authenticity_token"=>"+5IINl7vEh1jJJwP+RiXXws+4kEwM3fpJsCOn+gZ0AA=" ...
我認為根據定義,params [:authenticity_token]將與form_authenticity_token相同。
一些快速建議:如果您使用rails jquery helpers,rails將自動在POST請求中從HTML文檔的頭部添加csrf-token元標記值。 我會檢查HTML文檔的<head>
標記中的值是什么,看它是否匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.