mardi 4 août 2015

Rails - Controller that does not check for CSRF token

In my rails application, one of the controllers displays public statistics that I want websites hosted on different domains to pull data from. (http://ift.tt/1ML3M9n)

My controller code is given below:

class StatsController < ApplicationController 
require 'ostruct'
skip_before_action :verify_authenticity_token
respond_to :html, :xml, :json, :csv

def index
    @stats = OpenStruct.new
    @stats.users = User.all.count
    @stats.organizations = Organization.all.count
    @stats.donors = Person.all.count
    respond_to do |format|
        format.json {render json: @stats}
    end
end
end

I thought the line skip_before_action :verify_authenticity_token would be enough, but when I try to make requests to this page from the console, I get the following error:

XMLHttpRequest cannot load http://ift.tt/1ML3M9n. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.

How can I fix this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire