2017-09-22 8 views
1

관계를 통해 데이터가 통과하는 것을 방지하기 위해 관계 전체에서 모든 사람이 인증을 수행하고 있습니까?이미 context.user resolver가 설정되어 있어도 GraphQL 관계가 데이터를 누설합니다. 관계를 통한 데이터 노출을 방지하는 방법은 무엇입니까?

예를 들어 사용자가있는 샵이 있습니다.

// 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의 결함입니까? 당신은 어떻게이 주위에 일하고 있습니까?

이것은 python-graphene 스택 btw에 있습니다.

편집 : Btw, exclude_fields을 할 수는 있지만 ShopNode에서 사용자에게 액세스 할 수는 없으므로 ShopNode를 쿼리하는 중요한 정보이므로 필드를 제한하는 것이 좋습니다. .

+0

장고를 사용하고 계신가요? 사용자에게 돌아올 때보기를 보여줄 수 있습니까? –

+0

@MauricioCortazar 장고보기를 사용하지 않습니다. 죄송합니다! –

+0

스키마 * 의미 * –

답변

0

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() 
2

사용자가 올바른 권한을 가지고 있지 않을 때 null을 반환하려면 Shop 유형으로 제어해야합니다. 그렇지 않으면 두 번째 필드에서 Shop에 액세스 한 경우 수표를 복제해야합니다.

+0

어떻게 구현하겠습니까? – Blusky