我的jQuery的AJAX POST请求的作品,而不发送真实性令牌(滑轨) [英] My jquery AJAX POST requests works without sending an Authenticity Token (Rails)

查看:195
本文介绍了我的jQuery的AJAX POST请求的作品,而不发送真实性令牌(滑轨)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有在轨的任何条款,将允许来自该网站的所有AJAX的POST请求传递没有authenticity_token?

我有一个jQuery的POST Ajax调用,调用控制器的方法,但我并没有把任何真实性code它,但调用成功。

我的ApplicationController中确实有'request_forgery_protection',我已经改变了

  config.action_controller.consider_all_requests_local
 

为false,我的环境/ development.rb

我还搜查我的code,以确保我没有超载ajaxSend送出去的真实性令牌。

有没有在游戏中禁用检查某种机制?现在,我不知道如果我的CSRF保护工作或没有。

我用Rails 2.3.5。

更新净度:

 函数voteup(URL,组ID){
      $阿贾克斯({
        键入:POST,
        网址:/组/+组ID +/意见书/ voteup
        数据:URL =+网址,
        数据类型:文本,
        成功:功能(数据){
          VAR计数器=vote_+网址;
          $('#vote_'+ url.cleanify())文本(+数据+)。
        }
      });
    };
 

我有一个链接,然后有一个HREF调用上面的函数:

 < A HREF =JavaScript的:voteup(参数1,参数2)'> ...< / A>
 

解决方案

这里的一个可能的情况是,你使用jQuery序列化一个正常的Rails的形成......,它是包括了序列化的身份验证令牌隐藏字段( Rails的将它们添加到各种形式的)。

看看你的生成来源为你提交表单......很可能你会看到

 <输入名称=authenticity_token类型=隐藏值=somethinghere ....../>
 

其他的事情你可以做的是检查日志,看看是否authenticity_token字段是请求参数。

Is there any provisions in rails that would allow all AJAX POST requests from the site to pass without an authenticity_token?

I have a Jquery POST ajax call that calls a controller method, but I did not put any authenticity code in it and yet the call succeeds.

My ApplicationController does have 'request_forgery_protection' and I've changed

config.action_controller.consider_all_requests_local

to false in my environments/development.rb

I've also searched my code to ensure that I was not overloading ajaxSend to send out authenticity tokens.

Is there some mechanism in play that disables the check? Now I'm not sure if my CSRF protection is working or not.

I'm using Rails 2.3.5.

Update for clarity:

function voteup(url, groupid){
      $.ajax({
        type: "POST",
        url: "/groups/" + groupid + "/submissions/voteup",
        data: "url=" + url,
        dataType: 'text',
        success: function(data){
          var counter = "vote_" + url;
          $('#vote_' + url.cleanify()).text(" " + data + " ");
        }
      });
    };

I have a link which then has a 'href that calls the above function:

<a href='javascript:voteup(param1,param2)'>...</a>

解决方案

A likely scenario here is that you're using jQuery to serialize a normal Rails form... and it is including in that the serialized auth token hidden field (Rails adds them to all forms).

Look at your generated source for the form you're submitting... it's likely you'll see

<input name="authenticity_token" type="hidden" value="somethinghere...." />

The other thing you can do is check the log to see if the authenticity_token field is in the request params.

这篇关于我的jQuery的AJAX POST请求的作品,而不发送真实性令牌(滑轨)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆