Custom scalar in input is missing '@stringValue' or '@numberValue' directive, or equivalent

Issue ID: graphql-data-input-custom-scalar-directive-needed

Average severity: Critical

Description

A custom scalar is defined and used in an input position, but it does not declare a recognized type constraint directive, such as @stringValue, @numberValue, or an equivalent directive supported by your validation framework.

For more details, see the GraphQL constraints specification.

Possible exploit scenario

Custom scalars are frequently introduced to express domain-specific types. However, without an associated constraint or validation directive, a custom scalar typically does not provide:

  • Enforceable or enforcable bounds (such as length or range)
  • Format constraints (pattern)
  • Consistent validation semantics across resolvers
  • Does not provide deterministic guarantees to API consumers

In such cases, the custom scalar effectively behaves as a renamed built-in scalar (commonly a String), providing no enforceable contract improvement and creating a false sense of security

A type constraint directive is a GraphQL directive that declares a family of constraints applicable to a scalar category, for example:

  • @stringValue:
    • Length
    • Pattern
    • Character restrictions (as supported)
  • @numberValue:
    • Minimum or maximum values (and optionally precision rules, as supported), or equivalents provided by the chosen validation framework

Using a recognized type constraint directive allows expressing the expected serialization shape, explicit contract-level validation expectations, and other allowed characteristics of the scalar. This makes the API contract clearer, provides cross-service consistency, strengthens data governance controls, and allows automated auditing and conformance validation.

Because unconstrained custom scalars undermine the security and reliability benefits they are intended to provide — especially for input validation — this is a critical issue.

Remediation

Include a recognized type constraint directive to all custom scalars in input position to further narrow down accepted properties. We recommend that you:

  • Ensure the directive family matches the scalar category (string or numeric)
  • Define at least maximum bounds (maxLength, max, or equivalent) to mitigate abuse
  • Standardize type constraint directives across teams and subgraphs to avoid inconsistent validation semantics