Skip to content

Impossible to support CORS and non-CORS simultaneously? #17

@jamesarosen

Description

@jamesarosen

I have a single app. I want to accept same-origin requests on /foo and cross-origin requests on /bar.

If I do this:

app.use Rack::CorsGateOriginProcessor

app.use Rack::Cors do
  allow do
    resource /bar, credentials: true, methods: :any
  end
end

Rack::CorsGate

Then env['rack.cors'] will be a miss for requests to /foo. That, in turn, will lead to Rack::CorsGate returning a 403.

Shouldn't the logic be more like

def is_allowed(env, origin, method)
  return true if @allow_safe && ['GET', 'HEAD'].include?(method.upcase)
  return true if !@strict && origin.nil?
  return true if same_origin_request?(env) # CorsGate doesn't apply to same-origin requests
  env['rack.cors'].hit?
end

Or am I completely missing how this is supposed to work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions