-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## FragmentSpreadNode is one selection in the AST. The executor resolves it once per spread.\n\nThe MaxAliasesLimiter extension is registered like any other Strawberry extension:\n\n```python\nschema = strawberry.Schema(\n Query,\n extensions=[MaxAliasesLimiter(max_alias_count=20)],\n)\n```\n\nThe limiter exists to bound the cost of GraphQL aliases. Aliases are the primitive that lets a caller dispatch the same resolver multiple times under different output keys: `{ a: user, b: user, c: user }` is three calls to `user`. The published mitigation, named in every GraphQL hardening guide, is to cap the number of aliases the validator will accept before the executor runs.\n\nPre-patch, the walker lived in `strawberry/extensions/max_aliases.py`, and its core function was eleven lines:\n\n```python\ndef count_fields_with_alias(\n selection_set_owner: ExecutableDefinitionNode | FieldNode | InlineFragmentNode,\n) -> int:\n if selection_set_owner.selection_set is None:\n return 0\n\n result = 0\n\n for selection in selection_set_owner.selection_set.selections:\n if isinstance(selection, FieldNode) and selection.alias:\n result += 1\n if (\n isinstance(selection, (FieldNode, InlineFragmentNode))\n and selection.selection_set\n ):\n result += count_fields_with_alias(selection)\n\n return result\n```\n\nThe selection-set loop has two `isinstance` branches. A `FieldNode` carrying an alias contributes 1. A `FieldNode` or `InlineFragmentNode` with its own selection set is recursed into. There is no third branch. A `FragmentSpreadNode` selection passes both `isinstance` checks without matching and contributes 0.\n\nThe call site fed every executable definition in the document into this function:\n\n```python\ndef_that_can_contain_alias = (\n def_\n for def_ in document.definitions\n if isinstance(def_, (ExecutableDefinitionNode))\n)\ntotal_aliases = sum(\n count_fields_with_alias(def_node)\n for def_node in def_that_can_contain_alias\n)\n```\n\n`ExecutableDefinitionNode` is the abstract base class of both `OperationDefinitionNode` and `FragmentDefinitionNode` in `graphql-core`. The walker therefore iterated query operations AND fragment definitions, summing each definition's static alias count exactly once. A fragment definition was counted once. A fragment spread referencing that definition contributed zero.\n\n## What the executor counts\n\nThe executor does not iterate top-level definitions. It begins at the operation, descends into its selection set, and resolves each selection. When it encounters a `FragmentSpreadNode`, it inlines the named fragment's selection set and resolves the fields it contains. Each spread is a full inline. Ten spreads of a fragment containing ten aliased fields produce one hundred resolver calls.\n\nThe cost the extension was named to bound is the cost the executor pays. The walker measured the document. These are not the same number when fragments are involved.\n\n## The bypass\n\nThe following query passes `MaxAliasesLimiter(max_alias_count=20)` on every Strawberry release from 0.172.0 through 0.315.6:\n\n```graphql\nfragment leak on Human {\n a01: email a02: email a03: email a04: email a05: email\n a06: email a07: email a08: email a09: email a10: email\n}\nquery attack {\n s01: user(name: \"x\") { ...leak }\n s02: user(name: \"x\") { ...leak }\n s03: user(name: \"x\") { ...leak }\n s04: user(name: \"x\") { ...leak }\n s05: user(name: \"x\") { ...leak }\n s06: user(name: \"x\") { ...leak }\n s07: user(name: \"x\") { ...leak }\n s08: user(name: \"x\") { ...leak }\n s09: user(name: \"x\") { ...leak }\n s10: user(name: \"x\") { ...leak }\n}\n```\n\nPre-patch arithmetic: the `attack` operation contributes ten outer aliases (`s01` through `s10`), plus ten spreads contributing zero each. The `leak` fragment definition is iterated as an `ExecutableDefinitionNode` and contributes ten inner aliases, counted once. Total: twenty. Equal to the configured cap; the validator passes.\n\nExecutor arithmetic: ten outer resolutions, plus ten spreads expanded to ten resolutions each. Total: one hundred and ten. The limiter's promise to the operator was that the executor would not be asked to resolve more than twenty aliases. The executor is asked to resolve one hundred and ten.\n\nThe amplification factor scales with the number of spreads and the alias count inside the fragment. The cap is the wrong shape to bound either.\n\n## The patch reads the bug\n\nThe fix landed as commit `a69221f` on 2026-05-19 in Strawberry 0.315.7. The diff is short and names both errors at once:\n\n```diff\n+from collections.abc import Mapping\n+\n from graphql import (\n- ExecutableDefinitionNode,\n FieldNode,\n+ FragmentDefinitionNode,\n+ FragmentSpreadNode,\n GraphQLError,\n InlineFragmentNode,\n+ OperationDefinitionNode,\n ValidationContext,\n ValidationRule,\n )\n```\n\nThe call site swaps `ExecutableDefinitionNode` for `OperationDefinitionNode`. Fragment definitions are no longer iterated directly. They only contribute through the spread that names them, inside the operation that contains the spread. The walker collects a `fragments` map before counting:\n\n```python\nfragments = {\n definition.name.value: definition\n for definition in document.definitions\n if isinstance(definition, FragmentDefinitionNode)\n}\n```\n\nAnd `count_fields_with_alias` gains the third branch it was missing:\n\n```python\nif isinstance(selection, FragmentSpreadNode) and fragments:\n fragment_name = selection.name.value\n fragment = fragments.get(fragment_name)\n if fragment is None or fragment_name in visited_fragments:\n continue\n\n result += count_fields_with_alias(\n fragment,\n fragments,\n visited_fragments | {fragment_name},\n )\n```\n\nA `visited_fragments` frozenset is threaded through the recursion. Without it, a fragment that spreads itself, directly or through another fragment, would walk the counter into unbounded recursion the same shape as the executor's would face. The third branch is the count the executor performs. The frozenset is the guard the walker now installs for itself rather than borrowing from the order of validation rules `graphql-core` happens to run.\n\nApply the patched walker to the bypass query: ten outer aliases plus ten spreads at ten each. One hundred and ten. The cap of twenty rejects.\n\n## The same commit closed a quieter one in QueryDepthLimiter\n\nThe pull request that fixed CVE-2026-47707 is titled \"fix fragment issues.\" It changes two files. The CVE names one of them.\n\n`QueryDepthLimiter` is the depth equivalent of MaxAliasesLimiter: shipped in the same `strawberry/extensions/` directory, registered the same way, intended to bound the same class of DoS. Unlike the alias walker, it did handle `FragmentSpreadNode`. It just did not track visited fragments. A circular fragment caused the depth-counting recursion to walk forever:\n\n```diff\n if isinstance(node, FragmentSpreadNode):\n+ fragment_name = node.name.value\n+ if fragment_name in visited_fragments:\n+ return 0\n+\n return determine_depth(\n- node=fragments[node.name.value],\n+ node=fragments[fragment_name],\n ...\n+ visited_fragments=visited_fragments | {fragment_name},\n )\n```\n\n`graphql-core` rejects circular fragments via a separate validation rule. Whether the limiter's recursion blew up before the circular-fragment rule fired depended on the order rules ran. The fix removes that dependency.\n\nTwo extensions in the same directory. Both shipped as DoS mitigations. Both DoS-able. The alias limiter was bypassable; an attacker could trigger the resource exhaustion the limiter was named to prevent. The depth limiter was self-DoS-able; the validator itself recursed indefinitely on a circular fragment, exhausting resources before deciding whether to reject. Same commit, same author, same release.\n\n## gate-narrower-than-sink\n\nThis is what the [gate-narrower-than-sink](https://nefariousplan.com/patterns/gate-narrower-than-sink) pattern looks like when the gate is parse-time and the sink is runtime. The other exhibits in the catalog pair two parsers: [two regexes](https://nefariousplan.com/posts/w3-total-cache-cve-2026-27384-strip-stricter-than-executor) disagreeing on whitespace inside the same template syntax; [two URL parsers](https://nefariousplan.com/posts/starlette-cve-2026-48710-request-url-path-is-not-the-requests-path) disagreeing on what the path of a request is; [a regex character class](https://nefariousplan.com/posts/shell-quote-cve-2026-9277-dot-was-not-every-character) disagreeing with POSIX sh about which bytes need escaping. In every case the gate and the sink ran a matcher over the same syntactic object, the matchers disagreed, and the inputs the sink accepted but the gate did not match flowed through.\n\nStrawberry's pair are an AST walker and an executor. The walker counts at validation time. The executor resolves at runtime. Both operate over the same GraphQL document. They disagreed on what a `FragmentSpreadNode` is. To the pre-patch walker, it was a selection node carrying nothing it knew how to count. To the executor, it is a placeholder for the fragment's selection set, expanded once per occurrence. One selection in the AST. N resolutions at runtime.\n\nThe catalog so far had this pattern only across same-tier parsers. The Strawberry exhibit extends it into the parse-time-gate-against-runtime-sink dimension. Any static analyzer applied to limit a runtime cost carries the same risk: the gate sees one representation, the cost is paid in another, the two grow apart whenever the language has macros, includes, expansions, fragments, or any other mechanism that decouples the lexical form from the executed form.\n\n## What the limiter promised, and what it could see\n\nEvery published GraphQL hardening guide names alias limiting as a DoS mitigation. Apollo's, Hasura's, OWASP's. The mitigation is shipped by Strawberry as `MaxAliasesLimiter`, by `graphene-django` as `MaxAliasesValidator`, by `graphql-armor` as `MaxAliasesRule`. The class names are nearly identical because the mitigation is well-known.\n\nAn operator who registered MaxAliasesLimiter from 0.172.0 onward received the protection the AST walker could express. The protection the documentation implied was a bound on the executor's work. The two were equal when no query used a fragment spread. They diverged on any query that used one.\n\nGraphQL fragments are not exotic syntax. They are the recommended factoring for any selection that recurs across queries, and they are the standard way to express the \"same fields on multiple objects\" shape that alias-abuse DoS exploits. The bypass shape and the mitigation shape converged on the same primitive. The limiter watched only one side of the convergence.","closing_line":"The limiter is named for what it counts. The DoS lives in what it didn't.","hook_md":"GraphQL aliases are a known DoS primitive. Strawberry, the most-installed pure-Python GraphQL server, ships an extension called `MaxAliasesLimiter` to stop them: it walks the query document and counts aliases. The executor resolves aliases at runtime. A fragment spread is one selection in the AST and N resolutions at runtime, and the pre-patch walker did not handle `FragmentSpreadNode` at all. CVE-2026-47707 is the gap between what the walker counts and what the executor pays.","post_id":618,"slug":"strawberry-graphql-cve-2026-47707-limiter-counted-the-ast","title":"CVE-2026-47707: Strawberry's Alias Limiter Counted The AST. The Executor Counted The Spreads.","type":"initial","unreadable_sentence":"FragmentSpreadNode is one selection in the AST. The executor resolves it once per spread. The walker's grammar was strictly contained within the executor's behavior, and the bypass was every alias that lived past the walker's isinstance chain."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCatO6gQAKCRDeZjl4jgkQ JpCQAQDBvqTG0BruIdbdY4yBsMlHOnMCJVlvnObbNrmcitGEDAD7B5zX4o+QydGV muo2NzU98yryf+moxa6wMWxSgQ2KVwk= =CTtG -----END PGP SIGNATURE-----