-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix: Denial-of-service via unbounded query complexity in REST and GraphQL API (GHSA-cmj3-wx7h-ffvg) #10130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mtrezza
merged 12 commits into
parse-community:alpha
from
mtrezza:fix/GHSA-cmj3-wx7h-ffvg-v9
Mar 7, 2026
Merged
fix: Denial-of-service via unbounded query complexity in REST and GraphQL API (GHSA-cmj3-wx7h-ffvg) #10130
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1da8a5d
fix
mtrezza 88fa3aa
graphql
mtrezza e8c0ea4
lint
mtrezza 0078273
sec chk
mtrezza fbb8706
fix https://github.com/parse-community/parse-server/pull/10130#discus…
mtrezza 7d362ae
fix https://github.com/parse-community/parse-server/pull/10130#discus…
mtrezza 059c1a6
fix https://github.com/parse-community/parse-server/pull/10130#discus…
mtrezza ca6659d
test
mtrezza e63fc96
logging
mtrezza c3cc9e4
fix https://github.com/parse-community/parse-server/pull/10130#discus…
mtrezza 6b608c2
coverage
mtrezza 71c1a9f
postgres tests
mtrezza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| 'use strict'; | ||
|
|
||
| const http = require('http'); | ||
| const express = require('express'); | ||
| const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args)); | ||
| require('./helper'); | ||
| const { ParseGraphQLServer } = require('../lib/GraphQL/ParseGraphQLServer'); | ||
|
|
||
| describe('graphql query complexity', () => { | ||
| let httpServer; | ||
| let graphQLServer; | ||
| const headers = { | ||
| 'X-Parse-Application-Id': 'test', | ||
| 'X-Parse-Javascript-Key': 'test', | ||
| 'Content-Type': 'application/json', | ||
| }; | ||
|
|
||
| async function setupGraphQL(serverOptions = {}) { | ||
| if (httpServer) { | ||
| await new Promise(resolve => httpServer.close(resolve)); | ||
| } | ||
| const server = await reconfigureServer(serverOptions); | ||
| const expressApp = express(); | ||
| httpServer = http.createServer(expressApp); | ||
| expressApp.use('/parse', server.app); | ||
| graphQLServer = new ParseGraphQLServer(server, { | ||
| graphQLPath: '/graphql', | ||
| }); | ||
| graphQLServer.applyGraphQL(expressApp); | ||
| await new Promise(resolve => httpServer.listen({ port: 13378 }, resolve)); | ||
| } | ||
|
|
||
| async function graphqlRequest(query, requestHeaders = headers) { | ||
| const response = await fetch('http://localhost:13378/graphql', { | ||
| method: 'POST', | ||
| headers: requestHeaders, | ||
| body: JSON.stringify({ query }), | ||
| }); | ||
| return response.json(); | ||
| } | ||
|
|
||
| // Returns a query with depth 4: users(1) > edges(2) > node(3) > objectId(4) | ||
| function buildDeepQuery() { | ||
| return '{ users { edges { node { objectId } } } }'; | ||
| } | ||
|
|
||
| function buildWideQuery(fieldCount) { | ||
| const fields = Array.from({ length: fieldCount }, (_, i) => `field${i}: objectId`).join('\n '); | ||
| return `{ users { edges { node { ${fields} } } } }`; | ||
| } | ||
|
|
||
| afterEach(async () => { | ||
| if (httpServer) { | ||
| await new Promise(resolve => httpServer.close(resolve)); | ||
| httpServer = null; | ||
| } | ||
| }); | ||
|
|
||
| describe('depth limit', () => { | ||
| it('should reject query exceeding depth limit', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLDepth: 3 }, | ||
| }); | ||
| const result = await graphqlRequest(buildDeepQuery()); | ||
| expect(result.errors).toBeDefined(); | ||
| expect(result.errors[0].message).toMatch( | ||
| /GraphQL query depth of \d+ exceeds maximum allowed depth of 3/ | ||
| ); | ||
| }); | ||
|
|
||
| it('should allow query within depth limit', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLDepth: 10 }, | ||
| }); | ||
| const result = await graphqlRequest(buildDeepQuery()); | ||
| expect(result.errors).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should allow deep query with master key', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLDepth: 3 }, | ||
| }); | ||
| const result = await graphqlRequest(buildDeepQuery(), { | ||
| ...headers, | ||
| 'X-Parse-Master-Key': 'test', | ||
| }); | ||
| expect(result.errors).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should allow unlimited depth when graphQLDepth is -1', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLDepth: -1 }, | ||
| }); | ||
| const result = await graphqlRequest(buildDeepQuery()); | ||
| expect(result.errors).toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('fields limit', () => { | ||
| it('should reject query exceeding fields limit', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLFields: 5 }, | ||
| }); | ||
| const result = await graphqlRequest(buildWideQuery(10)); | ||
| expect(result.errors).toBeDefined(); | ||
| expect(result.errors[0].message).toMatch( | ||
| /Number of GraphQL fields \(\d+\) exceeds maximum allowed \(5\)/ | ||
| ); | ||
| }); | ||
|
|
||
| it('should allow query within fields limit', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLFields: 200 }, | ||
| }); | ||
| const result = await graphqlRequest(buildDeepQuery()); | ||
| expect(result.errors).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should allow wide query with master key', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLFields: 5 }, | ||
| }); | ||
| const result = await graphqlRequest(buildWideQuery(10), { | ||
| ...headers, | ||
| 'X-Parse-Master-Key': 'test', | ||
| }); | ||
| expect(result.errors).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('should count fragment fields at each spread location', async () => { | ||
| // With correct counting: 2 aliases (2) + 2×edges (2) + 2×node (2) + 2×objectId from fragment (2) = 8 | ||
| // With incorrect counting (fragment once): 2 + 2 + 2 + 1 = 7 | ||
| // Set limit to 7 so incorrect counting passes but correct counting rejects | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLFields: 7 }, | ||
| }); | ||
| const result = await graphqlRequest(` | ||
| fragment UserFields on User { objectId } | ||
| { | ||
| a1: users { edges { node { ...UserFields } } } | ||
| a2: users { edges { node { ...UserFields } } } | ||
| } | ||
| `); | ||
| expect(result.errors).toBeDefined(); | ||
| expect(result.errors[0].message).toMatch( | ||
| /Number of GraphQL fields \(\d+\) exceeds maximum allowed \(7\)/ | ||
| ); | ||
| }); | ||
|
|
||
| it('should allow unlimited fields when graphQLFields is -1', async () => { | ||
| await setupGraphQL({ | ||
| requestComplexity: { graphQLFields: -1 }, | ||
| }); | ||
| const result = await graphqlRequest(buildWideQuery(50)); | ||
| expect(result.errors).toBeUndefined(); | ||
| }); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.