Skip to content

fix(graphql): prevent GraphQL injection in fetchTypeDetails#321

Open
spidershield-contrib wants to merge 1 commit intocloudflare:mainfrom
spidershield-contrib:fix/graphql-injection
Open

fix(graphql): prevent GraphQL injection in fetchTypeDetails#321
spidershield-contrib wants to merge 1 commit intocloudflare:mainfrom
spidershield-contrib:fix/graphql-injection

Conversation

@spidershield-contrib
Copy link

Summary

Fixes #320

Uses a GraphQL variable ($typeName) instead of string interpolation to pass the type name to __type() in fetchTypeDetails(). This prevents injection of arbitrary GraphQL syntax through crafted type names.

Changes

File Change
apps/graphql/src/tools/graphql.tools.ts Replace "${typeName}" interpolation with $typeName variable; pass variable via request body

Before / After

Before (vulnerable):

query TypeDetails {
    __type(name: "${typeName}") {

After (safe):

query TypeDetails($typeName: String!) {
    __type(name: $typeName) {

Test Plan

  • npx tsc --noEmit -p apps/graphql/tsconfig.json — zero errors
  • Verify type detail queries still return correct results for valid type names

The typeName parameter was interpolated directly into a GraphQL query
string via template literal, allowing injection of arbitrary GraphQL
syntax through crafted type names (e.g., a name containing `")`).

Use a GraphQL variable ($typeName) instead of string interpolation
so the value is properly handled by the GraphQL engine as data,
not as part of the query structure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: GraphQL injection in fetchTypeDetails via string interpolation

1 participant