
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@escape.tech/graphql-armor
Advanced tools
Dead-simple, yet highly customizable security middleware for Apollo GraphQL servers shield
GraphQL Armor is a dead-simple yet highly customizable security middleware for various GraphQL server engines.
We support the following engines :
We additionnaly support the following engines through the Envelop plugin system :
See here for more information about Envelop compatibility.
# npm
npm install -S @escape.tech/graphql-armor
# yarn
yarn add @escape.tech/graphql-armor
Refer to the Examples directory for specific implementation examples. (such as NestJS with Apollo Server)
import { ApolloArmor } from '@escape.tech/graphql-armor';
const armor = new ApolloArmor();
const server = new ApolloServer({
typeDefs,
resolvers,
...armor.protect()
});
If you already have some plugins or validation rules, proceed this way:
import { ApolloArmor } from '@escape.tech/graphql-armor';
const armor = new ApolloArmor();
const protection = armor.protect()
const server = new ApolloServer({
typeDefs,
resolvers,
...protection,
plugins: [...protection.plugins, myPlugin1, myPlugin2 ]
validationRules: [, ...protection.validationRules, myRule1, myRule2 ]
});
import { EnvelopArmor } from '@escape.tech/graphql-armor';
const armor = new EnvelopArmor();
const protection = armor.protect()
async function main() {
const server = createServer({
schema,
plugins: [...protection.plugins],
});
await server.start();
}
main();
import { EnvelopArmorPlugin } from '@escape.tech/graphql-armor';
async function main() {
const server = createServer({
schema,
plugins: [EnvelopArmorPlugin()],
});
await server.start();
}
main();
import { EnvelopArmor } from '@escape.tech/graphql-armor';
const armor = new EnvelopArmor();
const protection = armor.protect()
const getEnveloped = envelop({
plugins: [otherPlugins, ...protection.plugins],
});
import { EnvelopArmorPlugin } from '@escape.tech/graphql-armor';
const getEnveloped = envelop({
plugins: [otherPlugins, EnvelopArmorPlugin()],
});
GraphQL Armor is fully configurable in a per-plugin fashion.
View the per plugin configuration section for more information about how to configure each plugin separately.
import { ApolloArmor } from '@escape.tech/graphql-armor';
const armor = new ApolloArmor({
costLimit: {
maxCost: 1000,
},
characterLimit: {
maxLength: 15000,
}
}
});
The provided values are the default values.
This section describes how to configure each plugin individually.
This plugin is for Apollo Server only, and is enabled by default.
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
.
For rolling back to Apollo's default parameter, you can use the following code:
import { ApolloArmor } from '@escape.tech/graphql-armor';
const armor = new ApolloArmor();
const server = new ApolloServer({
typeDefs,
resolvers,
...armor.protect(),
debug: true // Ignore Armor's recommandation
});
This plugin is for Apollo Server only, and is enabled by default.
Batched queries are enabled by default, which makes DoS attacks easier by stacking expensive requests. We make them disabled by default.
For rolling back to Apollo's default parameter, you can use the following code:
import { ApolloArmor } from '@escape.tech/graphql-armor';
const armor = new ApolloArmor();
const server = new ApolloServer({
typeDefs,
resolvers,
...armor.protect(),
allowBatchedHttpRequests: true // Ignore Armor's recommandations
});
This plugin is enabled by default.
It enforces a character limit on your GraphQL queries.
The limit is not applied to the whole HTTP body - multipart form data/file upload will still work.
Configuration
{
characterLimit: {
// enabled: true,
maxLength: 15000,
}
}
This plugin is enabled by default.
It analyzes incoming GraphQL queries and applies a cost analysis algorithm to prevent resource overload by blocking too expensive requests (DoS attack attempts).
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.
Configuration
{
costLimit: {
// enabled: true,
maxCost: 5000, // maximum cost of a request before it is rejected
objectCost: 2, // cost of retrieving an object
scalarCost: 1, // cost of retrieving a scalar
depthCostFactor: 1.5, // multiplicative cost of depth
ignoreIntrospection: true, // by default, introspection queries are ignored.
}
}
This plugin is enabled by default.
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 to recover an API schema even with disabled introspection, as long as field suggestions are enabled.
Example of such a suggestion:
Cannot query field "sta" on type "Media". Did you mean "stats", "staff", or "status"?
{
blockFieldSuggestion: {
// enabled: true,
}
}
This plugin is enabled by default.
Put a limit on the number of aliases.
{
maxAliases: {
// enabled: true,
n: 15,
}
}
This plugin is enabled by default.
Put a limit on the number of directives.
{
maxDirectives: {
// enabled: true,
n: 50,
}
}
This plugin is enabled by default.
Put a depth limit to the request.
{
maxDepth: {
// enabled: true,
n: 6,
}
}
Ensure you have read the Contributing Guide before contributing.
To setup your project, make sure you run the install-dev.sh
script.
git clone git@github.com:Escape-Technologies/graphql-armor.git
cd graphql-armor
bash ./install-dev.sh
We are using yarn as our package manager and the workspaces monorepo setup. Please read the associated documentation and feel free to open issues if you encounter problems when developing on our project!
This project is young so there might be bugs but we are very reactive so feel free to open issues.
FAQs
Dead-simple, yet highly customizable security middleware for Apollo GraphQL servers shield
The npm package @escape.tech/graphql-armor receives a total of 165,770 weekly downloads. As such, @escape.tech/graphql-armor popularity was classified as popular.
We found that @escape.tech/graphql-armor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.