GHSA-224P-V68G-5G8F
Vulnerability from github – Published: 2025-08-26 18:45 – Updated: 2025-08-26 18:45Summary
A query depth restriction using the max-depth can be bypassed if ignoreIntrospection is enabled (which is the default configuration) by naming your query/fragment __schema.
Details
In the countDepth function, we have the following code that calculates the depth of a used fragment:
} else if (node.kind == Kind.FRAGMENT_SPREAD) {
if (this.visitedFragments.has(node.name.value)) {
return this.visitedFragments.get(node.name.value) ?? 0;
} else {
this.visitedFragments.set(node.name.value, -1);
}
const fragment = this.context.getFragment(node.name.value);
if (fragment) {
let fragmentDepth;
if (this.config.flattenFragments) {
fragmentDepth = this.countDepth(fragment, parentDepth);
} else {
fragmentDepth = this.countDepth(fragment, parentDepth + 1);
}
depth = Math.max(depth, fragmentDepth);
if (this.visitedFragments.get(node.name.value) === -1) {
this.visitedFragments.set(node.name.value, fragmentDepth);
}
}
}
which will calculate the depth of the fragment used in the current node, store the value in this.visitedFragments and re-use it in the future to avoid re-calculating the depth for the same fragment.
The issue arises when the same fragment is used multiple times, at different depths. The current caching takes into account the depth of the first occurrence, which means if the fragment is re-used later in a higher depth, this cached value is not updated.
So, for example, sending the following query with a max depth of 6:
query {
books {
author {
...Test
}
}
books {
author {
books {
author {
...Test
}
}
}
}
}
fragment Test on Author {
books {
title
}
}
The first use of Test fragment does not exceed the defined limit, and this depth will be cached.
In the second use, the fragment is reused in a greater depth, but the countDepth function will still use the depth cached, without accounting for the increased depth.
PoC
Max depth: 6
query {
books {
author {
...Test
}
}
books {
author {
books {
author {
...Test
}
}
}
}
}
fragment Test on Author {
books {
title
}
}
Impact
This issue affects applications using the GraphQL Armor Depth Limit plugin.
Fix
This is fixed in PR#824. We now store only the additional depth contributed by the fragment and add it to the parent depth where the fragment is used (parentDepth).
{
"affected": [
{
"database_specific": {
"last_known_affected_version_range": "\u003c= 2.4.1"
},
"package": {
"ecosystem": "npm",
"name": "@escape.tech/graphql-armor-max-depth"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "2.4.2"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [],
"database_specific": {
"cwe_ids": [
"CWE-400"
],
"github_reviewed": true,
"github_reviewed_at": "2025-08-26T18:45:55Z",
"nvd_published_at": null,
"severity": "MODERATE"
},
"details": "### Summary\nA query depth restriction using the max-depth can be bypassed if `ignoreIntrospection` is enabled (which is the default configuration) by naming your query/fragment `__schema`.\n\n### Details\nIn the `countDepth` function, we have the following code that calculates the depth of a used fragment:\n\n```typescript\n } else if (node.kind == Kind.FRAGMENT_SPREAD) {\n if (this.visitedFragments.has(node.name.value)) {\n return this.visitedFragments.get(node.name.value) ?? 0;\n } else {\n this.visitedFragments.set(node.name.value, -1);\n }\n const fragment = this.context.getFragment(node.name.value);\n if (fragment) {\n let fragmentDepth;\n if (this.config.flattenFragments) {\n fragmentDepth = this.countDepth(fragment, parentDepth);\n } else {\n fragmentDepth = this.countDepth(fragment, parentDepth + 1);\n }\n depth = Math.max(depth, fragmentDepth);\n if (this.visitedFragments.get(node.name.value) === -1) {\n this.visitedFragments.set(node.name.value, fragmentDepth);\n }\n }\n }\n```\n\nwhich will calculate the depth of the fragment used in the current node, store the value in `this.visitedFragments` and re-use it in the future to avoid re-calculating the depth for the same fragment.\n\nThe issue arises when the same fragment is used multiple times, **at different depths**. The current caching takes into account the depth of the first occurrence, which means if the fragment is re-used later in a higher depth, this cached value is not updated.\n\nSo, for example, sending the following query with a max depth of `6`:\n\n```graphql\nquery {\n books {\n author {\n ...Test\n }\n }\n books {\n author {\n books {\n author {\n ...Test\n }\n }\n }\n }\n}\nfragment Test on Author {\n books {\n title\n }\n}\n```\n\nThe first use of `Test` fragment does not exceed the defined limit, and this depth will be cached.\n\nIn the second use, the fragment is reused in a greater depth, but the `countDepth` function will still use the depth cached, without accounting for the increased depth.\n\n### PoC\n\nMax depth: `6`\n\n```graphql\nquery {\n books {\n author {\n ...Test\n }\n }\n books {\n author {\n books {\n author {\n ...Test\n }\n }\n }\n }\n}\nfragment Test on Author {\n books {\n title\n }\n}\n```\n\n### Impact\n\nThis issue affects applications using the GraphQL Armor Depth Limit plugin.\n\n### Fix\n\nThis is fixed in [PR#824](https://github.com/Escape-Technologies/graphql-armor/pull/824). We now store only the additional depth contributed by the fragment and add it to the parent depth where the fragment is used (`parentDepth`).",
"id": "GHSA-224p-v68g-5g8f",
"modified": "2025-08-26T18:45:55Z",
"published": "2025-08-26T18:45:55Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/Escape-Technologies/graphql-armor/security/advisories/GHSA-224p-v68g-5g8f"
},
{
"type": "WEB",
"url": "https://github.com/Escape-Technologies/graphql-armor/pull/824"
},
{
"type": "WEB",
"url": "https://github.com/Escape-Technologies/graphql-armor/commit/998986109f8c2313bd61325ddfe7f5dcd48f9232"
},
{
"type": "PACKAGE",
"url": "https://github.com/Escape-Technologies/graphql-armor"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L",
"type": "CVSS_V3"
}
],
"summary": "GraphQL Armor Max-Depth Plugin Bypass via fragment caching"
}
Sightings
| Author | Source | Type | Date | Other |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.