Class GoodFaithIntrospection

java.lang.Object
graphql.introspection.GoodFaithIntrospection

@PublicApi @NullMarked public class GoodFaithIntrospection extends Object
Good Faith Introspection ensures that introspection queries are not abused to cause denial of service.

There are attack vectors where a crafted introspection query can cause the engine to spend too much time producing introspection data. This is especially true on large schemas with lots of types and fields.

Schemas form a cyclic graph and hence it's possible to send in introspection queries that can reference those cycles and in large schemas this can be expensive and perhaps a "denial of service".

When enabled, the validation layer enforces that:

  • Only one __schema and one __type field can appear per operation
  • The __Type fields fields, inputFields, interfaces, and possibleTypes can each only appear once (preventing cyclic traversals)
  • The query complexity is limited to GOOD_FAITH_MAX_FIELDS_COUNT fields and GOOD_FAITH_MAX_DEPTH_COUNT depth
This allows the standard and common introspection queries to work so tooling such as graphiql can work.
  • Field Details

    • GOOD_FAITH_INTROSPECTION_DISABLED

      public static final String GOOD_FAITH_INTROSPECTION_DISABLED
      Placing a boolean value under this key in the per request GraphQLContext will enable or disable Good Faith Introspection on that request.
      See Also:
    • GOOD_FAITH_MAX_FIELDS_COUNT

      public static final int GOOD_FAITH_MAX_FIELDS_COUNT
      This is the maximum number of executable fields that can be in a good faith introspection query
      See Also:
    • GOOD_FAITH_MAX_DEPTH_COUNT

      public static final int GOOD_FAITH_MAX_DEPTH_COUNT
      This is the maximum depth a good faith introspection query can be
      See Also:
  • Constructor Details

    • GoodFaithIntrospection

      public GoodFaithIntrospection()
  • Method Details

    • isEnabledJvmWide

      public static boolean isEnabledJvmWide()
      Returns:
      true if good faith introspection is enabled
    • enabledJvmWide

      public static boolean enabledJvmWide(boolean flag)
      This allows you to disable good faith introspection, which is on by default.
      Parameters:
      flag - the desired state
      Returns:
      the previous state
    • isEnabled

      public static boolean isEnabled(GraphQLContext graphQLContext)
      Checks whether Good Faith Introspection is enabled for the given request context.
      Parameters:
      graphQLContext - the per-request context
      Returns:
      true if good faith introspection checks should be applied
    • goodFaithLimits

      public static QueryComplexityLimits goodFaithLimits(QueryComplexityLimits existing)
      Returns query complexity limits that are the minimum of the existing limits and the good faith introspection limits. This ensures introspection queries are bounded without overriding tighter user-specified limits.
      Parameters:
      existing - the existing complexity limits (may be null, in which case defaults are used)
      Returns:
      complexity limits with good faith bounds applied