hasura / hasura/graphql-engine

Allow "Bearer" JWT in HASURA_GRAPHQL_JWT_SECRET CustomHeader

Open
#9,949 2 comments 1 reaction 0 assignees View on GitHub
k/enhancement
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Is your proposal related to a problem?

Yes. I'm in the process of setting up JWT authentication for my hasura instance and i want to expose the GraphQL- and REST-endpoints through a Google ESPV2 API Gateway.

The ESPV2 expects a "Bearer" JWT token, which it will validate before propagating the request to the hasura endpoint. ESPv2 then sends the following headers to hasura:

- `authorization` (a new JWT created by ESPV2 that is unrelated to the original JWT)
- `x-forwarded-authorization` (the complete original `authorization` starting with `Bearer`)
- `x-endpoint-api-userinfo` (only the payload part of the JWT, which is not accepted by hasura as it expects a JWT header as well)

When using a CustomHeader in `HASURA_GRAPHQL_JWT_SECRET`, i set the `name` to `x-forwarded-authorization`.

```
{"type": "RS256", "header": { "type": "CustomHeader", "name": "x-forwarded-authorization"}, "jwk_url": "https://auth.test.com/.well-known/jwks"}
```

I'm now facing the issue, that hasura ONLY accepts the token without the `Bearer` scheme in case of the CustomHeader type.

Error (with `Bearer`):
```
Schema introspection query failed:
Could not verify JWT: JWSError (JSONDecodeError "Not valid base64url")
```

### Describe the solution you'd like

It would be great if hasura either accepted a `Bearer` JWT token on CustomHeader types or i could specify a scheme like
```
{"type": "RS256", "header": { "type": "CustomHeader", "scheme": "Bearer", "name": "x-forwarded-authorization"}, "jwk_url": "https://auth.test.com/.well-known/jwks"}
```

### Describe alternatives you've considered

I was trying to use the `x-endpoint-api-userinfo` header as described above, but hasura can not validate it since it's missing the headers. Error:

```
Schema introspection query failed:
Could not verify JWT: JWSError (CompactDecodeError Invalid number of parts: Expected 3 parts; got 1)
```

Contributor guide

Open the contributing guide

Research direction

The issue points to HASURA_GRAPHQL_JWT_SECRET CustomHeader handling and the GraphQL/REST authentication entry points, but names no files or tests. Start by locating that configuration path and the JWT verification flow; done means CustomHeader tokens using the Bearer scheme are accepted or a scheme option is implemented and covered by the relevant tests.

Written by the indexing model from the issue text.

Assessment

Domain
api, authentication, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.