Repository navigation
fix(graphql): enforce query depth limit, alias caps, complexity budget and disable introspection in production - #944
Open
mopxam-art wants to merge 1 commit into
Conversation
…t and disable introspection in production (closes Heliobond#922)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The GraphQL endpoint lacked query depth validation, alias fan-out bounds, and complexity analysis, allowing deeply nested selections or wide alias fan-out attacks to trigger excessive resolver executions and memory pressure. Additionally, schema introspection was unconditionally open across all environments.
What
src/graphql/validation.ts:createDepthLimitRule: bounds nested field and fragment selection depth (default: 6, configurable viaGRAPHQL_MAX_DEPTH).createAliasLimitRule: caps total field aliases (default: 15,GRAPHQL_MAX_ALIASES) and root query selections (default: 10,GRAPHQL_MAX_ROOT_FIELDS).createComplexityLimitRule: calculates execution budget factoring in list multipliers likeprojects(limit: N)(default budget: 500,GRAPHQL_MAX_COMPLEXITY).createIntrospectionControlRule: disables schema introspection (__schema,__type) in production environments while keeping standard__typenamequeries fully functional./graphqlhandler insrc/index.tsand exported helpers fromsrc/graphql/schema.ts.Verified
src/__tests__/graphql-depth-complexity.test.ts(114 passing) covering depth boundaries, alias caps, complexity limits, and introspection controls.npm test).npx tsc --noEmit) and linter pass with 0 errors.npm run build) succeeded.Closes #922
Payout coordinate:
USDC (EVM / Base / Arbitrum / ERC20): 0x387c064ccf729a4846b62e95dc6b70e4d4c41e73