If i understand correctly, to authorize a query or mutation in hasura using JWT, there are a few requirements that needs to be fulfilled in the request itself, which is:
- The JWT itself, presented in the request header
Authorization: Bearer <token here>
- x-hasura-role, presented in the request header (optional)
x-hasura-role: user
- The actual query or mutation, presented in the request body
myQuery {
id
name
another_field
}
When the request is then sent to the hasura endpoint, the hasura GraphQL engine will then try to
- Validate the JWT
- Check if the value of
x-hasura-role
that is set in the request header exists inside thex-hasura-allowed-role
claims of the jwt - If all conditions are met, then the GraphQL engine will check whether the role that is assigned from the value of
x-hasura-role
header have the permission to execute the query from the request body
To my understanding, this means that someone can 'forge' a request to the hasura GraphQL engine by setting the value of x-hasura-role
to something else that exists inside the x-hasura-allowed-roles
claim of the JWT. For example, if the x-hasura-allowed-roles
claim is something like this
{
...
'x-hasura-allowed-roles': ['role1','role2'],
'x-hasura-default-role': 'role1',
'x-hasura-user-id': username
}
}
then it means someone who is supposedly only assigned to role1 can execute a query that is restricted to role2 only just by setting the x-hasura-role
header in the request to x-hasura-role: role2
Is my understanding correct? If it is, what is the best way to avoid this situation, as it seems like a security vulnerability? Do I just limit the x-hasura-allowed-roles
claim of the jwt to ONLY the role assigned to each user based on my authentication service?