Securing the returned introspection schema. #4051
Unanswered
nielsbasjes
asked this question in
Q&A
Replies: 1 comment
-
|
I did some more experimenting, this time with implementing a My current code is messy but seems(!!) to work. If a user does not have permission the field is not present in the schema and cannot be queried (i.e. "No such field" kind of error). I ended up with
Is there a better way to do this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary: I'm trying to hide the types and fields a user is not allowed to query when retrieving the schema (both through introspection and /graphql/schema printer).
My Context: Kotlin, Spring security and Spring GraphQL (which uses this library GrahpQL-Java).
I have a test application which has the following:
@PreAuthorize("hasRole('READ_SENSITIVE')")READ_SENSITIVEgets the value and a user without this role gets an error.At this point setting permissions and blocking access works as I want it.
The next step I find a lot harder; I want to hide the parts of the schema the current user is not allowed to see. The intent is that the schema returned does not have any fields where the current user does not have the right permissions for. This also means that different users will in general get a different schema when they ask for it.
I have tried to create a custom instrumentation class and in the
instrumentSchemamethod look at the schema (see rough snippet below). With this I have access to the Field definitions and their DataFetchers ...The hurdle I ran into is that when I finally have access to the DataFetcher of the field the actual DataFetcher implementations consist of mostly (package)private classes and fields.
I have not yet been able to gain access to the underlying method so I can get the
@PreAuthorizeannotation and do the checks I want.What is the correct route to get there?
Or is this something that would need some changes in the core library (like adding a
Boolean isAllowed()kind of method to the top DataFetcher interace)?Experimental snippet:
Beta Was this translation helpful? Give feedback.
All reactions