Skip to content

Commit 151fa23

Browse files
Version Packages (#66)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent a015d3e commit 151fa23

File tree

4 files changed

+320
-6
lines changed

4 files changed

+320
-6
lines changed

.changeset/calm-chicken-lie.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/graphql-armor/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @escape.tech/graphql-armor
22

3+
## 1.0.1
4+
5+
### Patch Changes
6+
7+
- 2609ed4: Readme
8+
39
## 1.0.0
410

511
### Major Changes

packages/graphql-armor/README.md

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
# GraphQL Armor 🛡️
2+
3+
*This project is young so there might be bugs but we are very reactive so feel free to open issues.*
4+
5+
GraphQL Armor is a dead-simple yet highly customizable security middleware for various GraphQL server engines.
6+
7+
![GraphQL-Armor banner](https://raw.githubusercontent.com/Escape-Technologies/graphql-armor/main/packages/docs/banner.png)
8+
9+
[![CI](https://github.com/Escape-Technologies/graphql-armor/actions/workflows/ci.yaml/badge.svg)](https://github.com/Escape-Technologies/graphql-armor/actions/workflows/ci.yaml) [![release](https://github.com/Escape-Technologies/graphql-armor/actions/workflows/release.yaml/badge.svg)](https://github.com/Escape-Technologies/graphql-armor/actions/workflows/release.yaml) ![npm](https://img.shields.io/npm/v/@escape.tech/graphql-armor)
10+
11+
## Contents
12+
13+
- [Contents](#contents)
14+
- [Supported GraphQL Engines](#supported-graphql-engines)
15+
- [Getting Started](#getting-started)
16+
- [Apollo Server](#apollo-server)
17+
- [GraphQL Yoga](#graphql-yoga)
18+
- [Envelop](#envelop)
19+
- [Getting Started with configuration](#getting-started-with-configuration)
20+
- [Per plugin configuration](#per-plugin-configuration)
21+
- [Stacktraces (Apollo Only)](#stacktraces-apollo-only)
22+
- [Batched queries (Apollo Only)](#batched-queries-apollo-only)
23+
- [Character Limit](#character-limit)
24+
- [Cost Analysis](#cost-analysis)
25+
- [Field Suggestion](#field-suggestion)
26+
- [Aliases Limit](#aliases-limit)
27+
- [Directives Limit](#directives-limit)
28+
- [Depth Limit](#depth-limit)
29+
- [Contributing](#contributing)
30+
31+
## Supported GraphQL Engines
32+
33+
We support the following engines :
34+
35+
- [Apollo Server](https://www.apollographql.com/)
36+
- [GraphQL Yoga](https://www.graphql-yoga.com/)
37+
38+
We additionnaly support the following engines through the [Envelop](https://www.envelop.dev/) plugin system :
39+
40+
- GraphQL-Helix
41+
- Node.js HTTP
42+
- GraphQL-WS
43+
- GraphQL-SSE
44+
- Azure Functions
45+
- Cloudflare Workers
46+
- Google Cloud Functions
47+
- Lambda AWS
48+
- type-graphql
49+
- nexus
50+
- express-graphql
51+
52+
See [here](https://www.envelop.dev/docs/integrations) for more information about Envelop compatibility.
53+
54+
## Getting Started
55+
56+
Refer to the [Examples directory](https://github.com/Escape-Technologies/graphql-armor/tree/main/examples) for specific implementation examples. (such as NestJS with Apollo Server)
57+
58+
### Apollo Server
59+
60+
```typescript
61+
import { ApolloArmor } from '@escape.tech/graphql-armor';
62+
63+
const armor = new ApolloArmor();
64+
65+
const server = new ApolloServer({
66+
typeDefs,
67+
resolvers,
68+
...armor.protect()
69+
});
70+
```
71+
72+
If you already have some plugins or validation rules, proceed this way:
73+
74+
```typescript
75+
import { ApolloArmor } from '@escape.tech/graphql-armor';
76+
77+
const armor = new ApolloArmor();
78+
const protection = armor.protect()
79+
80+
const server = new ApolloServer({
81+
typeDefs,
82+
resolvers,
83+
...protection,
84+
plugins: [...protection.plugins, myPlugin1, myPlugin2 ]
85+
validationRules: [, ...protection.validationRules, myRule1, myRule2 ]
86+
});
87+
```
88+
89+
### GraphQL Yoga
90+
91+
```typescript
92+
import { EnvelopArmor } from '@escape.tech/graphql-armor';
93+
94+
const armor = new EnvelopArmor();
95+
const protection = armor.protect()
96+
97+
async function main() {
98+
const server = createServer({
99+
schema,
100+
plugins: [...protection.plugins],
101+
});
102+
await server.start();
103+
}
104+
105+
main();
106+
```
107+
108+
### Envelop
109+
110+
```typescript
111+
import { EnvelopArmor } from '@escape.tech/graphql-armor';
112+
113+
const armor = new EnvelopArmor();
114+
const protection = armor.protect()
115+
116+
const getEnveloped = envelop({
117+
plugins: [otherPlugins, ...protection.plugins],
118+
});
119+
```
120+
121+
## Getting Started with configuration
122+
123+
GraphQL Armor is fully configurable in a per-plugin fashion.
124+
125+
View the [per plugin configuration section](#per-plugin-configure) for more information about how to configure each plugin separately.
126+
127+
```typescript
128+
import { ApolloArmor } from '@escape.tech/graphql-armor';
129+
130+
const armor = new ApolloArmor({
131+
costAnalysis: {
132+
maxCost: 1000,
133+
},
134+
characterLimit: {
135+
maxLength: 15000,
136+
}
137+
}
138+
});
139+
```
140+
141+
## Per plugin configuration
142+
143+
The provided values are the default values.
144+
145+
This section describes how to configure each plugin individually.
146+
147+
- [Stacktraces (Apollo Only)](#stacktraces-apollo-only)
148+
- [Batched queries (Apollo Only)](#batched-queries-apollo-only)
149+
- [Character Limit](#character-limit)
150+
- [Cost Analysis](#cost-analysis)
151+
- [Field Suggestion](#field-suggestion)
152+
- [Aliases Limit](#aliases-limit)
153+
- [Directives Limit](#directives-limit)
154+
- [Depth Limit](#depth-limit)
155+
156+
### Stacktraces (Apollo Only)
157+
158+
This plugin is for Apollo Server only, and is enabled by default.
159+
160+
Stacktraces are managed by the Apollo configuration parameter `debug` which may have `true` as a default value in some setups. GraphQL Armor changes this default value to `false`.
161+
162+
For rolling back to Apollo's default parameter, you can use the following code:
163+
164+
```typescript
165+
import { ApolloArmor } from '@escape.tech/graphql-armor';
166+
167+
const armor = new ApolloArmor();
168+
const server = new ApolloServer({
169+
typeDefs,
170+
resolvers,
171+
...armor.protect(),
172+
debug: true // Ignore Armor's recommandation
173+
});
174+
```
175+
176+
### Batched queries (Apollo Only)
177+
178+
This plugin is for Apollo Server only, and is enabled by default.
179+
180+
Batched queries are enabled by default, which makes DoS attacks easier by stacking expensive requests. We make them disabled by default.
181+
182+
For rolling back to Apollo's default parameter, you can use the following code:
183+
184+
```typescript
185+
import { ApolloArmor } from '@escape.tech/graphql-armor';
186+
187+
const armor = new ApolloArmor();
188+
const server = new ApolloServer({
189+
typeDefs,
190+
resolvers,
191+
...armor.protect(),
192+
allowBatchedHttpRequests: true // Ignore Armor's recommandations
193+
});
194+
```
195+
196+
### Character Limit
197+
198+
This plugin is enabled by default.
199+
200+
It enforces a character limit on your GraphQL queries.
201+
202+
The limit is not applied to the whole HTTP body - multipart form data/file upload will still work.
203+
204+
Configuration
205+
206+
```typescript
207+
{
208+
characterLimit: {
209+
enabled: true,
210+
maxLength: 15000,
211+
}
212+
}
213+
```
214+
215+
### Cost Analysis
216+
217+
This plugin is enabled by default.
218+
219+
It analyzes incoming GraphQL queries and applies a cost analysis algorithm to prevent resource overload by blocking too expensive requests (DoS attack attempts).
220+
221+
The cost computation is quite simple (and naive) at the moment but there are plans to make it evolve toward a extensive plugin with many features.
222+
223+
Configuration
224+
225+
```typescript
226+
{
227+
costAnalysis: {
228+
enabled: true,
229+
maxCost: 5000, // maximum cost of a request before it is rejected
230+
objectCost: 2, // cost of retrieving an object
231+
scalarCost: 1, // cost of retrieving a scalar
232+
depthCostFactor: 1.5, // multiplicative cost of depth
233+
ignoreIntrospection: true, // by default, introspection queries are ignored.
234+
}
235+
}
236+
```
237+
238+
### Field Suggestion
239+
240+
This plugin is enabled by default.
241+
242+
It will prevent suggesting fields in case of an erroneous request. Suggestions can lead to the leak of your schema even with disabled introspection, which can be very detrimental in case of a private API. One could use [GraphDNA](https://github.com/Escape-Technologies/graphdna) to recover an API schema even with disabled introspection, as long as field suggestions are enabled.
243+
244+
Example of such a suggestion :
245+
246+
`Cannot query field "sta" on type "Media". Did you mean "stats", "staff", or "status"?`
247+
248+
```typescript
249+
{
250+
blockFieldSuggestion: {
251+
enabled: true,
252+
}
253+
}
254+
```
255+
256+
### Aliases Limit
257+
258+
This plugin is enabled by default.
259+
260+
Put a limit on the number of aliases.
261+
262+
```typescript
263+
{
264+
maxAliases: {
265+
enabled: true,
266+
n: 15,
267+
}
268+
}
269+
```
270+
271+
### Directives Limit
272+
273+
This plugin is enabled by default.
274+
275+
Put a limit on the number of directives.
276+
277+
```typescript
278+
{
279+
maxDirectives: {
280+
enabled: true,
281+
n: 50,
282+
}
283+
}
284+
```
285+
286+
### Depth Limit
287+
288+
This plugin is enabled by default.
289+
290+
Put a depth limit to the request.
291+
292+
```typescript
293+
{
294+
maxDepth: {
295+
enabled: true,
296+
n: 6,
297+
}
298+
}
299+
```
300+
301+
## Contributing
302+
303+
Ensure you have read the [Contributing Guide](https://github.com/Escape-Technologies/graphql-armor/blob/main/CONTRIBUTING.md) before contributing.
304+
305+
To setup your project, make sure you run the `install-dev.sh` script.
306+
307+
```bash
308+
git clone git@github.com:Escape-Technologies/graphql-armor.git
309+
cd graphql-armor
310+
bash ./install-dev.sh
311+
```
312+
313+
We are using yarn as our package manager and [the workspaces monorepo setup](https://classic.yarnpkg.com/lang/en/docs/workspaces/). Please read the associated documentation and feel free to open issues if you encounter problems when developing on our project!

packages/graphql-armor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@escape.tech/graphql-armor",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Dead-simple, yet highly customizable security middleware for Apollo GraphQL servers shield",
55
"keywords": [
66
"apollo",

0 commit comments

Comments
 (0)