Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it so you can opt out of object authorization #3446

Merged
merged 1 commit into from
Apr 30, 2021

Conversation

rmosolgo
Copy link
Owner

@rmosolgo rmosolgo commented Apr 19, 2021

Fixes #3429

I can't say I recommend it, but if it's really adding up, this makes it possible (and tested) to override Schema::Object.authorized_new and bypass authorization.

I also investigated an option for disabling built-in authorization at runtime, but I found it put too much complexity in the code (https://github.com/rmosolgo/graphql-ruby/compare/skip-built-in-auth).

Instead, this approach consolidates tracing and logic in .authorized_new, then tests to confirm that it can be overridden (including for DynamicFields, which implements __typename).

So, with this PR, you could opt out by adding:

class Types::BaseObject 
  # Normally, GraphQL-Ruby calls `.authorized?` before initializing this, 
  # but we want to bypass that 
  def self.authorized_new(obj, ctx)
    new(obj, ctx)
  end 
end 

and

class MySchema < GraphQL::Schema
  # Add a custom introspection module which will avoid `.authorized?` checks 
  # for __typename and __type(name: ...) fields
  module Introspection 
     class DynamicFields < GraphQL::Introspection::DynamicFields 
       def self.authorized_new(obj, ctx)
         new(obj, ctx)
       end 
     end 
   end 
   
   introspection(Introspection)
   
   # ... 
 end 

@bbugh
Copy link
Contributor

bbugh commented Apr 28, 2021

Seems good to me!

@rmosolgo rmosolgo merged commit 5ab3e5e into master Apr 30, 2021
@rmosolgo rmosolgo deleted the authorized-work-around branch November 9, 2021 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow disabling authorization checks if they are not used
2 participants