Doubt: Authorization constraints in resolvers or shield permissions
See original GitHub issueQuestion about GraphQL concepts
- Is it right to assume that I only need to care about
auth
andpermissions
on scalar fields only? By this, I mean:
type Customer {
id: ID!
name: String!
sensitiveData: UserSensitiveData!
...
}
type Customer SensitiveData {
id: ID!
customer : Customer !
data1: String! # authorization verification from DB here in resolvers
data2: ... # authorization verification from DB here in resolvers
}
Rules:
export const permissions = shield({
Customer : allow,
CustomerSensitiveData: isUserCustomer
})
EDIT: I now have a feeling/understanding that this could leak fields like id
in related type for an authenticated, but unauthorized access. For instance, id
in Product
is public, so purchasedProducts
in type Customer
, if not verified for authorization, could leak that id
(and other product identifier) to an authenticated customer access trying to access other customer’s resources. So, authorization should be on the edges, not on the nodes.
- How do I ensure that an authorized user is deleting say, wishlisht of its own? (Right now, I am using
$exists
from prisma client inresolvers
to check if the user has that item, then only allow deletion). Should this constraint be somehow placed in the shield rule?
Question about GraphQL Shield
- What are fragments in shield? Are they the one to use when I have to constraint some fields of a type to be public, and some to be authorized (but these could be achieved with field level rule defs, couldnt they?)
- I have checked other questions and found none that matches mine.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Setting Up Authentication and Authorization with Apollo ...
Add an authorization layer to check user permissions before running resolver functions.
Read more >A complete guide to permissions in a GraphQL API
This guide shows you how to use GraphQL directives, GraphQL middleware resolvers, and the GraphQL shield library to implement permissions.
Read more >Authorization · Issue #313 · ardatan/graphql-tools - GitHub
In this case, you have to execute functions which are not specific to Authorization and we have to execute these functions before the...
Read more >3 ways for authorization with GraphQL and Apollo
As you can see, implementing authorization with GraphQL Shield is fairly simple and flexible. One disadvantage is that you need to "duplicate" ...
Read more >Security Guide Red Hat AMQ 6.3 | Red Hat Customer Portal
2.1. JAAS Authentication · 2.1.1. Default JAAS Realm · 2.1.2. Defining JAAS Realms · 2.1.3. JAAS Properties Login Module · 2.1.4. JAAS OSGi...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey 👋,
I am not sure I understand your question entirely. In particular, what are you referring to with
AuthZ
? Maybe the example below could give you some ideas on how to tackle the issue.That’s how I would approach writing permissions. As you can see,
User
only checks whether user is indeed authenticated, whileTicket
also verifies that current user owns it.I hope this helps you solve your problem 🙂
@devautor no worries, I could have guessed that! 🙈 What you could do is set up an interface type and somehow validate the ownership that way, however, I am not entirely sure how would that work.