Can't verify CSRF token authenticity in rails

后端 未结 3 1897
挽巷
挽巷 2020-12-09 22:03

I am using PaypalAdaptive. It sends ipn_notification properly. ipnNotification action method is as following -

def ipn_notification
    ipn = PaypalAdaptive         


        
相关标签:
3条回答
  • 2020-12-09 22:23

    In your controller:

    skip_before_filter :verify_authenticity_token, :only => [:ipn_notification]
    

    For people reading to quickly and distribute -1 (skipping an important part: it's not a POST call from the client...):

    • yes it skips a security BUT... Read after...

    • yes, it's the only way for external website POST requests

    • yes it's safe: you obviously check params and keys when receiving a call from Paypal or alike.

    0 讨论(0)
  • 2020-12-09 22:25

    Add the following line in your application.js

    //= require jquery_ujs
    

    And try.

    0 讨论(0)
  • 2020-12-09 22:42

    The correct solution for this problem without compromising security

    In your ajax request send the csrf token value as header.

    var csrfToken = $("meta[name='csrf-token']").attr("content");
    $.ajaxSetup({
      headers: {
        'X-CSRF-Token': csrfToken
      }
    });
    
    0 讨论(0)
提交回复
热议问题