ruby-on-rails – Uploadify和rails 3真实性令牌
发布时间:2020-12-17 02:50:56 所属栏目:百科 来源:网络整理
导读:我正在尝试使用uploadify( http://www.uploadify.com)在rails 3应用程序中使用文件上传进度条,我陷入了真实性令牌.我当前的uploadify配置看起来像 script type="text/javascript" charset="utf-8" $(document).ready(function() { $("#zip_input").uploadify
我正在尝试使用uploadify(
http://www.uploadify.com)在rails 3应用程序中使用文件上传进度条,我陷入了真实性令牌.我当前的uploadify配置看起来像
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $("#zip_input").uploadify({ 'uploader': '/flash/uploadify.swf','script': $("#upload").attr('action'),'scriptData': { 'format': 'json','authenticity_token': encodeURIComponent('<%= form_authenticity_token if protect_against_forgery? %>') },'fileDataName': "world[zip]",//'scriptAccess': 'always',// Incomment this,if for some reason it doesn't work 'auto': true,'fileDesc': 'Zip files only','fileExt': '*.zip','width': 120,'height': 24,'cancelImg': '/images/cancel.png','onComplete': function(event,data) { $.getScript(location.href) },// We assume that we can refresh the list by doing a js get on the current page 'displayData': 'speed' }); }); </script> 但我从rails获得此响应: Started POST "/worlds" for 127.0.0.1 at 2010-04-22 12:39:44 ActionController::InvalidAuthenticityToken (ActionController::InvalidAuthenticityToken): Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms) Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (6.6ms) Rendered /opt/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0.beta3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.2ms) 这似乎是因为我没有发送身份验证cookie以及请求.有谁知道我怎么能得到我应该发送的值,以及如何让rails从HTTP POST读取它而不是试图将其作为cookie发现? 解决方法
跳过真实性令牌检查并不理想,因为它打开了XSS攻击向量.
此处描述了另一种实现此功能的方法: http://metautonomo.us/2010/07/09/uploadify-and-rails-3/ 请注意,您可能需要对网址进行双重编码.在示例中,使用rails’u’以及encodeURLComponent().但是,如果您设置了更多花哨/ rails3类型并从页眉中的元标记中获取会话数据/真实性令牌,则需要两次调用encodeURLComponent(). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |