Safeguard
Security Guides•

Public or first party GraphQL API: which security controls apply?

A GraphQL API for your own apps can use allowlists and no introspection. A public one cannot. Compare controls for each case and pick a baseline.

Safeguard Security Team
4 min read

Which controls fit depends on who writes the queries. If your own apps are the sole callers, lock operations with trusted documents and turn introspection off in production. If outside developers write queries, you cannot allowlist them, so rely on limits, cost controls, authentication and strict authorization instead.

The key question

Ask one thing first: do you know every query that will be sent? The GraphQL security guide ties several recommendations to that. Trusted documents suit APIs that serve first party clients, and nobody else. Operations are written in development, submitted to the server's allowlist at build time with an ID, and in production the client sends the ID alone. The guide notes this cannot work for public APIs, because third party operations are not known in advance.

The same guide says introspection can be forbidden in non development environments for APIs serving first party clients, and cautions that disabling it is a form of security through obscurity and not enough alone.

Comparison

ControlFirst party APIPublic API
Trusted documents allowlistStrongly suitedNot possible
IntrospectionOff in productionOften on by design, consider restricting to approved callers
Depth limitYesYes
Breadth, alias and batch limitsYesYes
Pagination capsYesYes
Query cost analysisOptionalOften needed
Rate limiting in business logicYesYes, tuned per client
Field and object authorizationRequiredRequired
Error maskingYesYes
AuthenticationRequiredRequired, per client keys

Demand control for a public API

With an open set of queries, the guide lists the layered options: paginated list fields, depth limiting, breadth and batch limiting, rate limiting and query complexity analysis. It advises a separate, smaller limit for how deeply lists can be nested, since nested lists can multiply the data returned. It also says rate limits are generally better applied in the business logic layer, because a count of network requests misses the cost of each query.

For cases where a legitimate client needs a deep query and a low blanket limit is impractical, the guide suggests relying on rate limiting or complexity analysis. See the earlier post on choosing between depth, amount and cost limits.

A baseline for each case

First party API

  1. Authenticate every request.
  2. Extract and publish trusted documents at build time.
  3. Reject unknown operations in production.
  4. Disable introspection and mask errors.
  5. Keep depth, pagination and batch limits anyway.
  6. Authorize every field and object.

Public API

  1. Issue per client credentials and apply per client limits.
  2. Apply depth, breadth, alias and batch limits.
  3. Cap page sizes.
  4. Add cost analysis if some fields are expensive.
  5. Consider restricting introspection to approved callers, and publish a schema document instead.
  6. Mask errors and field suggestions.
  7. Authorize every field and object.

What stays the same

Whoever calls the API, authorization does not change. The GraphQL project recommends putting authorization logic in the business logic layer, validating and sanitizing argument values, and keeping a single source of truth. An allowlist reduces the query shapes an attacker can use, but each allowed query still needs proper access checks.

Try it yourself

Click through it at your own pace, or open it full screen.

Look at which controls an API scan reports on and compare them with the baseline above.

Quick check

Can a public GraphQL API use trusted documents?

No. The GraphQL security guide says outside clients write operations you cannot know ahead of time. Use limits, cost analysis and authorization.

Is disabling introspection enough for a first party API?

No. It helps, but the guide says an allowlist and authorization give stronger protection.

Safeguard scans your dependencies and SBOMs for known vulnerabilities, including GraphQL server libraries, and shows which are reachable. A free scan is at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.