Skip to content

Commit e194503

Browse files
rakeshkky0x777
andcommitted
restrict env variables start with HASURA_GRAPHQL_ for headers configuration in actions, event triggers & remote schemas (hasura#5519)
* restrict env variables start with HASURA_GRAPHQL_ for headers definition in actions & event triggers * update CHANGELOG.md * Apply suggestions from code review Co-authored-by: Vamshi Surabhi <[email protected]>
1 parent 10b827d commit e194503

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
## Next release
44

5+
### Breaking change
6+
7+
Headers from environment variables starting with `HASURA_GRAPHQL_` are not allowed
8+
in event triggers, actions & remote schemas.
9+
10+
If you do have such headers configured, then you must update the header configuration before upgrading.
11+
512
### Bug fixes and improvements
613

714
(Add entries here in the order of: server, console, cli, docs, others)
815

16+
- server: disallow headers from env variables starting with `HASURA_GRAPHQL_` in actions, event triggers & remote schemas (#5519)
17+
**WARNING**: This might break certain deployments. See `Breaking change` section above.
918
- server: bugfix to allow HASURA_GRAPHQL_QUERY_PLAN_CACHE_SIZE of 0 (#5363)
1019
- server: support only a bounded plan cache, with a default size of 4000 (closes #5363)
1120
- server: add logs for action handlers
@@ -39,7 +48,7 @@
3948
- server: have haskell runtime release blocks of memory back to the OS eagerly (related to #3388)
4049
- server: unlock locked scheduled events on graceful shutdown (#4928)
4150
- server: disable prepared statements for mutations as we end up with single-use objects which result in excessive memory consumption for mutation heavy workloads (#5255)
42-
- server: include scheduled event metadata (`created_at`,`scheduled_time`,`id`, etc) along with the configured payload in the request body to the webhook.
51+
- server: include scheduled event metadata (`created_at`,`scheduled_time`,`id`, etc) along with the configured payload in the request body to the webhook.
4352
**WARNING:** This is breaking for beta versions as the payload is now inside a key called `payload`.
4453
- console: allow configuring statement timeout on console RawSQL page (close #4998) (#5045)
4554
- console: support tracking partitioned tables (close #5071) (#5258)

server/src-lib/Hasura/RQL/DDL/Headers.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import Hasura.RQL.Types.Error
88
import Language.Haskell.TH.Syntax (Lift)
99

1010
import qualified Data.CaseInsensitive as CI
11-
import qualified Data.Text as T
1211
import qualified Data.Environment as Env
12+
import qualified Data.Text as T
1313
import qualified Network.HTTP.Types as HTTP
1414

1515

@@ -35,7 +35,10 @@ instance FromJSON HeaderConf where
3535
case (value, valueFromEnv ) of
3636
(Nothing, Nothing) -> fail "expecting value or value_from_env keys"
3737
(Just val, Nothing) -> return $ HeaderConf name (HVValue val)
38-
(Nothing, Just val) -> return $ HeaderConf name (HVEnv val)
38+
(Nothing, Just val) -> do
39+
when (T.isPrefixOf "HASURA_GRAPHQL_" val) $
40+
fail $ "env variables starting with \"HASURA_GRAPHQL_\" are not allowed in value_from_env: " <> T.unpack val
41+
return $ HeaderConf name (HVEnv val)
3942
(Just _, Just _) -> fail "expecting only one of value or value_from_env keys"
4043
parseJSON _ = fail "expecting object for headers"
4144

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
description: Define an action with headers configuration
2+
url: /v1/query
3+
status: 400
4+
query:
5+
type: create_action
6+
args:
7+
name: create_user_1
8+
definition:
9+
kind: synchronous
10+
arguments:
11+
- name: name
12+
type: String!
13+
output_type: User!
14+
handler: http://127.0.0.1:5593/create-user
15+
headers:
16+
- name: x-client-id
17+
value_from_env: HASURA_GRAPHQL_CLIENT_NAME
18+
response:
19+
path: $.definition.headers[0]
20+
error: 'env variables starting with "HASURA_GRAPHQL_" are not allowed in value_from_env: HASURA_GRAPHQL_CLIENT_NAME'
21+
code: parse-failed

server/tests-py/test_actions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ def dir(cls):
455455
def test_recreate_permission(self, hge_ctx):
456456
check_query_f(hge_ctx, self.dir() + '/recreate_permission.yaml')
457457

458+
def test_create_with_headers(self, hge_ctx):
459+
check_query_f(hge_ctx, self.dir() + '/create_with_headers.yaml')
460+
458461
# Test case for bug reported at https://github.com/hasura/graphql-engine/issues/5166
459462
@pytest.mark.usefixtures('per_class_tests_db_state')
460463
class TestActionIntrospection:

0 commit comments

Comments
 (0)