How to skip SPF validation in 'griddler-sendgrid' gem?

122 Views Asked by At

I am using gem 'griddler' with gem 'griddler-sendgrid' in my ruby on rails app for incoming mails.

It is working fine on staging server but getting issue with production server. There is no issue in my configuration, I have confirmed this with sendgrid support. They told me to use only DKIM validation and remove SPF check from validations.

I have checked both gem for that but didn't find anything relevant to that.

Here is my gem configuration details:

ruby '2.2.3'

gem 'rails', '4.1.2'

gem 'griddler', '1.4.0'

gem 'griddler-sendgrid', '1.0.0'

Can someone suggest me how can I skip SPF check validation in gem 'griddler-sendgrid'?

Thanks in advance!

1

There are 1 best solutions below

0
On

Tried getting emails_controller.rb from github ?

https://github.com/thoughtbot/griddler

"fix ArgumentError with verify_authenticity_token on Rails API"

I've added protect_from_forgery with: :null_session

I think that null_session should be used in API controllers with no use for the session. It provides an empty session during request.

https://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection/ClassMethods.html

In a controllers folder griddler add a new file from the Griddler github, or try the code below.

/controllers/griddler/emails_controller.rb

class Griddler::EmailsController < ActionController::Base

  skip_before_action :verify_authenticity_token, raise: false
  protect_from_forgery with: :null_session

  def create
    normalized_params.each do |p|
      process_email email_class.new(p)
    end

    head :ok
  end

  private

  delegate :processor_class, :email_class, :processor_method, :email_service, to: :griddler_configuration

  private :processor_class, :email_class, :processor_method, :email_service

  def normalized_params
    Array.wrap(email_service.normalize_params(params))
  end

  def process_email(email)
    processor_class.new(email).public_send(processor_method)
  end

  def griddler_configuration
    Griddler.configuration
  end
end

Not fully sure with the whole solution, but hope it will help to get some more direction.