每个人如何进行跨关系的身份验证以防止数据通过关系被遍历?
例如,我们有一个有用户的商店。
// Returns error as i've set custom resolver to allow only context.user.is_shop_owner
{
shops {
name
users {
email
...
}
}
}此查询通常会被自定义解析器(如context.user.is_shop_owner )阻塞,因此无法从根查询执行此查询。
但是,如果恶意用户遍历关系以到达用户对象,则可以获得敏感的用户数据。
// Data exposed un-intendedly due to relation traversal. How to prevent this?
{
products {
name
price
shop {
users { ... } // boom, exposed
}
}
}这是graphql中的一个缺陷吗?,你们是如何处理这个的?
这是在蟒蛇-石墨烯堆栈上。
编辑:顺便说一句,我知道我们可以做exclude_fields,但是那样我就不能从ShopNode访问用户了,这是ShopNode的一个重要信息,所以限制字段可能不是个好主意。(编辑)
发布于 2017-10-10 04:26:40
最后,我为每个节点设置自定义解析器,以基于context.user阻止要限制访问权限的关系。请参考下面的代码来回答我上面的问题。
class ProductNode(DjangoObjectType):
class Meta:
model = Product
interfaces = (graphene.relay.Node)
# Exclude nodes where you do not need any access at all
exclude_fields = ['users']
# For nodes where you need specific/limited access, define custom resolvers.
# This prevents the relation traversal loophole
def resolve_shop(self, args, context, info):
""" Allow access to nodes only for staff or shop owner and manager """
if get_is_staff_user(context.user, self):
return self.shop
Operations.raise_forbidden_access_error()发布于 2017-09-22 17:47:19
这可能应该控制在Shop类型中,以便在用户没有正确的权限时返回null。否则,如果从第二个字段访问Shop,则必须重复检查。
https://stackoverflow.com/questions/46364232
复制相似问题