hasura / hasura/graphql-engine

Hasura permissions custom check returns 200 when custom check condition is not met

Open
#8,411 5 comments 2 reactions 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information
v2.4.0.cli-migrations-v3

### Environment
Local docker container

### What is the expected behaviour?
Get an error in the response that the custom check before select/update has failed

### What is the current behaviour?
Each table has a role `user` with custom check (on insert/select/update/delete) that use `_exists` operator on table `user_permissions` with the `X-Hasura-User-Id` from the jwt token and the right capability flag.
The `user_permissions` table has the columns:
1. user_id (uuid)
2. capability1 (bool)
3. capability2 (bool)
4. capability3 (bool)

So when a user want to access a certain table the capability flag for that table needs to be "true".

The data in the object returned from graphql-engine response is null and there are no errors attached to the response when custom check condition is NOT met

### How to reproduce the issue?

1. Apply select permissions with custom check to a role named `user` in some table
2. Try access that table with `user` role so that the custom check condition is met and data can be retrieved
3. Change the custom check so it will fail and try again.
4. Response data is null with no errors indicating that the custom check failed

### Please provide any traces or logs that could help here.
This is the hasura log when trying to access a table and the custom check fails

`hasura-1 | {"type":"http-log","timestamp":"2022-04-18T14:43:36.994+0000","level":"info","detail":{"operation":{"query_execution_time":8.529125e-3,"user_vars":{"x-hasura-role":"user","x-hasura-team-id":"bfe4c5fb-a26a-45ca-8269-1190f9571393","x-hasura-user-id":"786d486a-bfb9-4367-98c0-6b15a16cdfbd"},"request_id":"126c91e8-4549-45ce-971b-2f6246ab4198","response_size":48,"request_mode":"single","request_read_time":4.666e-6},"request_id":"126c91e8-4549-45ce-971b-2f6246ab4198","http_info":{"status":200,"http_version":"HTTP/1.1","url":"/v1/graphql","ip":"172.19.0.1","method":"POST","content_encoding":"gzip"}}}`

### Screenshots or Screencast
Screen Shot 2022-04-18 at 17 40 46

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the custom-check failure through the /v1/graphql endpoint using the listed user role, table permissions, and user_permissions capability flags. Trace how failed select or update checks are represented in the GraphQL response, then verify that the completed behavior includes an error rather than returning null data without errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql
Domain
api, authorization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.