我使用一些JavaScript稱爲jpegcam(用回形針,以下these directions),並在不同場合它的創建故障CSRF令牌。這是應用這個問題的唯一地方。不好的令牌在中間有'+'字符。導軌 - 警告:無法驗證CSRF令牌真實性
本節中的JS是問題webcam.set_api_url('<%= upload_users_path %>' + '?' + csrf_param + "=" + encodeURI(encodeURI(csrf_token)));
警告消息:
Started POST "https://stackoverflow.com/users/upload?authenticity_token=N0x/rDOgyC6AutbXzx8sZXLwDnB9zQ+NwWefXTpiSfE=" for 127.0.0.1 at 2013- 06-04 01:06:34 -0400
...
Parameters: {"authenticity_token"=>"N0x/rDOgyC6AutbXzx8sZXLwDnB9zQ NwWefXTpiSfE="}
WARNING: Can't verify CSRF token authenticity
...
Completed 401 Unauthorized in 15ms
JS(在頁面視圖中)看起來是這樣的:
<script type="text/javascript">
function onload_complete(msg) {
// fetch the CSRF meta tag data
var csrf_param = $('meta[name=csrf-param]').attr('content');
var csrf_token = $('meta[name=csrf-token]').attr('content');
// reset the api URL appending the auth token parameter
webcam.set_api_url('<%= upload_users_path %>' + '?' + csrf_param + "=" + encodeURI(encodeURI(csrf_token)));
}
...
</script>
感謝您的建議!它看起來像'webcam.set_api_url('<%= upload_users_path%>'+'?'+ csrf_param +「=」+ encodeURI(encodeURI(csrf_token)))這一行的問題;'只需將帶有加號的壞標記以某種方式混合。 –