Azure / data-api-builder

Data API builder provides modern REST and GraphQL endpoints to your Azure Databases and on-prem stores.
https://aka.ms/dab/docs
MIT License
919 stars 189 forks source link

Verify if Engine returns 4xx status code properly, or just 200 with sub status code instead #1075

Open tarazou9 opened 1 year ago

tarazou9 commented 1 year ago

In the case of missing "X-MS-CLIENT-PRINCIPAL" or query entity requires role more than anonymous, it's currently returning hot chocolate error, which is 500 with Error Code AUTH_NOT_AUTHENTICATED, it should return 403 instead.

Below are the current status code the Engine is returning after testing. image

seantleonard commented 1 year ago

Is this for GraphQL? We've utilized this working spec for GraphQL over HTTP to help guide our approach to response codes that might not be handled by Hot Chocolate: https://github.com/graphql/graphql-over-http/blob/main/spec/GraphQLOverHTTP.md#body

michaelstaib commented 1 year ago

Hot Chocolate 13 is fully compliant with the new graphql over HTTP spec. Hot Chocolate 12 supports the legacy spec version which will become invalid with the watershed 1st January 2025.

With 13 you can switch between the legacy mode and the new spec.

Mathos1432 commented 1 year ago

We're seeing cases where DAB returns 500 and inside the body is the AUTH_NOT_AUTHENTICATED code. We're wondering if this is expected or if it should instead be returning a 403 directly?

Response Status Code: InternalServerError, Error: {"errors":[{"message":"The current user is not authorized to access this resource.","locations":[{"line":2,"column":5}],"path":["markets"],"extensions":{"code":"AUTH_NOT_AUTHENTICATED"}}]}

seantleonard commented 1 year ago

@mathos1432 From HotChocolate v12, it looks like 500 is returned when there is only an Error field in the GraphQL response. Do you have an example of the request that returns that auth error?