Skip to content

Commit 2397daa

Browse files
authored
Introduce built-in armor security features (#6630)
1 parent a003f78 commit 2397daa

File tree

8 files changed

+199
-183
lines changed

8 files changed

+199
-183
lines changed

packages/web/docs/src/content/gateway/other-features/security/_meta.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
'csrf-prevention': 'CSRF Prevention',
55
'rate-limiting': 'Rate Limiting',
66
'demand-control': 'Demand Control',
7-
'disable-introspection': 'Introspection',
7+
'disable-introspection': 'Disable Introspection',
88
https: 'HTTPS',
99
'hmac-signature': 'HMAC Signature',
1010
'aws-sigv4': 'AWS Signature V4',

packages/web/docs/src/content/gateway/other-features/security/block-field-suggestions.mdx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,37 @@ import { Callout } from '@theguild/components'
77
# Block Field Suggestions
88

99
This is a feature that allows you to prevent **returning field suggestions** and **leaking your
10-
schema** to unauthorized actors provided by
11-
[GraphQL Armor](https://escape.tech/graphql-armor/docs/plugins/block-field-suggestions/)
10+
schema** to unauthorized actors. In production, this can lead to leaking schema information even if
11+
the introspection is disabled.
1212

13-
In production, this can lead to Schema leak even if the introspection is disabled.
13+
## Basic Configuration
1414

15-
## How to use?
15+
<Callout type="info">
16+
Powered by [GraphQL
17+
Armor](https://escape.tech/graphql-armor/docs/plugins/block-field-suggestions/).
18+
</Callout>
1619

17-
Install the plugin:
20+
Hive Gateway ships with the basic "block field suggestion" security feature. You can enable it by
21+
setting the `blockFieldSuggestions` option to `true`.
22+
23+
```ts filename="gateway.config.ts"
24+
import { defineConfig } from '@graphql-hive/gateway'
25+
26+
export const gatewayConfig = defineConfig({
27+
blockFieldSuggestions: true
28+
})
29+
```
30+
31+
## Advanced Configuration
32+
33+
The built-in configuration options are limited and should be enough for most use-cases. However, if
34+
you need more control, you can configure more by installing the
35+
[GraphQL Armor Block Field Suggestions plugin](https://escape.tech/graphql-armor/docs/plugins/block-field-suggestions/).
1836

1937
```sh npm2yarn
2038
npm install @escape.tech/graphql-armor-block-field-suggestions
2139
```
2240

23-
Then, add it to your plugins:
24-
2541
```ts filename="gateway.config.ts"
2642
import { blockFieldSuggestionsPlugin } from '@escape.tech/graphql-armor-block-field-suggestions'
2743
import { defineConfig } from '@graphql-hive/gateway'

packages/web/docs/src/content/gateway/other-features/security/character-limit.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ searchable: false
44

55
import { Callout } from '@theguild/components'
66

7-
# Character Limit
7+
# Character Limit Plugin
88

99
**Limit** number of **characters** in a GraphQL query document.
1010

packages/web/docs/src/content/gateway/other-features/security/disable-introspection.mdx

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ searchable: false
66

77
import { Callout } from '@theguild/components'
88

9-
# Introspection
9+
# Disable Introspection
1010

1111
A powerful feature of GraphQL is schema introspection. This feature is used by GraphiQL for
1212
exploring the schema and also by tooling such as
@@ -16,15 +16,23 @@ client/frontend code.
1616
GraphQL schema introspection is also a feature that allows clients to ask a GraphQL server what
1717
GraphQL features it supports (e.g. defer/stream or subscriptions).
1818

19-
## Disabling Introspection
19+
However, you may want to not expose your schema to the outside world. You can disable schema
20+
introspection with the `disableIntrospection` option.
2021

21-
<Callout>
22-
If your goal is to avoid unknown actors from reverse-engineering your GraphQL
23-
schema and executing arbitrary operations, it is highly recommended to use
24-
persisted operations.
22+
```ts filename="gateway.config.ts"
23+
import { defineConfig } from '@graphql-hive/gateway'
2524

26-
[Learn more about persisted operations.](/docs/gateway/persisted-documents)
25+
export const gatewayConfig = defineConfig({
26+
disableIntrospection: {
27+
disableIf: () => true
28+
}
29+
})
30+
```
2731

32+
<Callout>
33+
If your goal is to avoid unknown actors from reverse-engineering your GraphQL schema and executing
34+
arbitrary operations, it is highly recommended to use [persisted
35+
operations](/docs/gateway/persisted-documents).
2836
</Callout>
2937

3038
## Disable Introspection based on the GraphQL Request
@@ -33,7 +41,7 @@ Sometimes you want to allow introspectition for certain users. You can access th
3341
and determine based on that whether introspection should be enabled or not. E.g. you can check the
3442
headers.
3543

36-
```ts filename="gateway.config.ts" {7}
44+
```ts filename="gateway.config.ts" {6}
3745
import { defineConfig } from '@graphql-hive/gateway'
3846

3947
export const gatewayConfig = defineConfig({
@@ -45,45 +53,28 @@ export const gatewayConfig = defineConfig({
4553
})
4654
```
4755

48-
## Disabling Field Suggestions
49-
50-
<Callout>
51-
The [`graphql-armor`](https://github.com/Escape-Technologies/graphql-armor) plugin is a security layer that help you protect your GraphQL server from malicious queries.
52-
It allows you to configure various security features such as character limit or blocking field suggestions.
53-
For more information about `graphql-armor` features, you can refer to the [documentation for the plugin](/docs/gateway/other-features/security/block-field-suggestions).
54-
55-
Here is an example of how to use `graphql-armor` to disable introspection and block field
56-
suggestions.
57-
58-
</Callout>
56+
## Blocking Field Suggestions
5957

6058
When executing invalid GraphQL operation the GraphQL engine will try to construct smart suggestions
6159
that hint typos in the executed GraphQL document. This can be considered a security issue, as it can
6260
leak information about the GraphQL schema, even if introspection is disabled.
6361

64-
<Callout>
65-
If your goal is to avoid unknown actors from reverse-engineering your GraphQL
66-
schema and executing arbitrary operations, it is highly recommended to use
67-
persisted operations.
68-
69-
[Learn more about persisted operations.](/docs/gateway/persisted-documents)
62+
Tools like [Clairvoyance](https://github.com/nikitastupin/clairvoyance) can exploit the smart
63+
suggestions and brute-force obtaining the GraphQL schema even if the introspection has been
64+
disabled.
7065

71-
</Callout>
66+
[Enabling the `blockFieldSuggestions` option](/docs/gateway/other-features/security/block-field-suggestions)
67+
will disable these smart suggestions and therefore prevent schema leaking.
7268

73-
Disabling the "did you mean x" suggestion feature can be achieved via the
74-
`blockFieldSuggestionsPlugin` from
75-
[`graphql-armor`](https://github.com/Escape-Technologies/graphql-armor).
69+
Combined with the `disableIntrospection` option, you can make your schema more secure.
7670

77-
```sh npm2yarn
78-
npm i @escape.tech/graphql-armor-block-field-suggestions
79-
```
80-
81-
```ts filename="Disabling the 'did you mean x' suggestion feature with a plugin" {2, 7}
82-
import { blockFieldSuggestionsPlugin } from '@escape.tech/graphql-armor-block-field-suggestions'
83-
import { defineConfig, useDisableIntrospection } from '@graphql-hive/gateway'
71+
```ts filename="gateway.config.ts" {7}
72+
import { defineConfig } from '@graphql-hive/gateway'
8473

8574
export const gatewayConfig = defineConfig({
86-
disableIntrospection: true,
87-
plugins: pluginCtx => [blockFieldSuggestionsPlugin()]
75+
disableIntrospection: {
76+
disableIf: () => true
77+
},
78+
blockFieldSuggestions: true
8879
})
8980
```

0 commit comments

Comments
 (0)