GraphQL API Security with Hasura Cloud
Tags: graphqlsecurity, hasuracloud, bestpractices
Published: 2021-08-09 09:03:43

---
title: GraphQL API Security with Hasura Cloud
published: true
date: 2021-07-28 16:46:17 UTC
tags: GraphQLSecurity,HasuraCloud,BestPractices
canonical_url: https://hasura.io/blog/graphql-api-security-with-hasura-cloud/
---

 ![GraphQL API Security with Hasura Cloud](https://hasura.io/blog/content/images/2021/07/graphql_security_hasura_cloud.png)

Hasura Cloud is a fully managed, globally available, auto scaling version of Hasura that also includes features specifically designed to make it easier for you to run Hasura in production. These features range from the addition of monitoring/analytics features for increased observability to built-in caching for improved performance, to a suite of security features that help you safeguard your production Hasura applications. All of these are hard problems that all GraphQL Servers run into in production - with Hasura Cloud, these features are available out of the box with simple and intuitive configurations!

In this post, I will walk you through the security features available on Hasura Cloud, including a set of new enhancements launched in the latest Cloud release v _ **2.0.3** _. These features help you secure your production application, and safeguard your app against injection attacks, DDoS attacks, excessive data exposure, and more, whether malicious or accidental.

# Global and Role-based API controls under the Security tab [new]

Hasura Cloud has a new Security tab under the API section of the console to make it easy to access API security settings.

![GraphQL API Security with Hasura Cloud](https://lh4.googleusercontent.com/OsZcSWYDQRtBRZsb-uFsSG5KQvILCkhoSHBjX5zIH8N0gV-phlOurtq2e9eKEtbRnlmn-JD_tUALKg1Pw-3HPdGgr-sC36lqylCIDB5RXDE-WXM3P7aahy---JzgaXfXvTn434P4)

We’ll focus our attention on five key security features that Hasura Cloud adds to the production checklist, and describe the use-cases those features are solving for.

## Depth limit

Graph-like querying structures are susceptible to recursive querying patterns, both accidental and malicious. Without checking the level of nesting, it’s possible to generate large and expensive queries. While it is possible to create proxy services to a self-hosted GraphQL server to handle this problem, Hasura Cloud makes this a click-and-set configuration. Using our shapes and sets analogy, we might end up with the following example:

<!--kg-card-begin: markdown-->
```
{
  shapes {
    set {
      name
      shapes { # duplicate reference!
        name
      }
    }
  }
}

```
<!--kg-card-end: markdown-->

Setting a depth limit will surface this problem for us.

<iframe width="200" height="113" src="https://www.youtube.com/embed/MNSBNg3JSqo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

## Node limit [new]

In addition to depth limits, node limits are another “gotcha” to be aware of. Every field in GraphQL is a node, regardless if that’s nested five levels deep in a query structure or at the root level. GraphQL in particular has additional mechanisms that can quickly lead to excessive node usage if left unchecked. For example, creating reusable fragments and aliases is great for code cleanliness, but, when used incorrectly, you could end up with excessive egress from your database.

<!--kg-card-begin: markdown-->
```
{
  set1: shapes {
    name
    set {
      name
    }
  }
  set2: shapes {
    name
    set {
      name
    }
  }
  set3: shapes {
    name
    set {
      name
    }
  }
}

```
<!--kg-card-end: markdown-->

<iframe width="200" height="113" src="https://www.youtube.com/embed/dOMm9CvEmek?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

Setting a limit on the total number of nodes helps ensure terse requests that don’t unintentionally inflate your database bill.

## Rate limiting

Hasura supports a wide variety of workload types, from heavily cached responses to real-time feeds. The majority of use cases will often end up somewhere in-between and having the ability to rate-limit requests is a great way to balance spiking user load. It’s also a vital and effective piece in the mitigation strategy against DDoS attacks or when a single API consumer is flooding your service with unoptimized requests. Rate limiting can also be applied conditionally to matching IPs or request parameters. This allows for throttling suspicious activity without restricting organically spiking usage.

<iframe width="200" height="113" src="https://www.youtube.com/embed/EDsGkByE0vY?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

## Disabling Introspection [new]

The GraphQL specification states that all GraphQL endpoints must be introspectable, which has become the bedrock of much of the powerful tooling in the GraphQL ecosystem. However, persistent and immediately introspectable APIs have been the topic that security experts have included in nearly every formal review of a GraphQL endpoint. The reason behind this critique of an introspectable API is that it falls foul of the OWASP guidance to avoid excessive data exposure/disclosure. Imagine if an introspectable API from a public company now had a root level model for a vertical they’d previously not been associated with, this would lead to significant repercussions in the markets. Fortunately, Hasura Cloud makes disabling introspectable schemas as simple as a click.

<iframe width="200" height="113" src="https://www.youtube.com/embed/WPJ5DtYpy5I?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

## Allow Lists

One method for ensuring only approved content leaves your database is to require approval for the operations that can be used in production. This list of approved methods is then aptly named, the “allow list.” Hasura Cloud makes this a simple process of viewing the previously requested operations, selecting the ones that should be allowed in production, then adding them to the list. This becomes an effective “final-form” of the production application, where you can do a final review of all the operations making requests against the API, then add them to the allow list, thus blocking all non-sanctioned requests to your database.

<iframe width="200" height="113" src="https://www.youtube.com/embed/ePOQMOEZSxI?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>

## Support for SSL certificates on the client

Many of the leading cloud providers offer SSL-based DB connections for the highest security compliance. While not alone in the requirement, Google Cloud Platform (GCP has long required SSL based database authentication – and Hasura Cloud now makes it simple to use Google’s robust database offerings.

Hasura Cloud is able to offer a lot of this functionality as it tightly integrates with the route handling and logging functionality at the server level. [Try these out](https://hasura.info/dev_jesse) on Hasura Cloud and let us know if you have any questions.

Useful reads:

- [Migrating from Hasura CE to Hasura Cloud](https://hasura.io/blog/moving-from-self-hosted-hasura-oss-to-hasura-cloud/)
- [Production Checking for Hasura CE](https://hasura.io/docs/latest/graphql/core/deployment/production-checklist.html)
- [Security and Compliance on Hasura Cloud](https://hasura.io/security/)