Skip to content

Harden query parsing - #28521

Merged
ComfortablyCoding merged 46 commits into
mainfrom
harden-query-parsing
Nov 16, 2026
Merged

ComfortablyCoding merged 46 commits into
mainfrom
harden-query-parsing

Conversation

@br41nslug

@br41nslug br41nslug commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

What's Changed

Bounded the work that parsing a single query can cause, and reworked a number of patterns whose
worst-case cost grew faster than the length of their input.

Query parameters

  • Added node-count and depth limits to filter and deep, rejected with the existing
    InvalidQueryError, which names the limit it hit and its configured value. The allowance is spent
    across a whole query, so a filter nested under deep draws on what is left rather than starting
    over.
  • Held $CURRENT_USER, $CURRENT_ROLE, $CURRENT_ROLES and $CURRENT_POLICIES paths in a filter to
    MAX_RELATIONAL_DEPTH, the same bound as the fields they are fetched as.

GraphQL

  • Added a limitSelections validation rule that counts the fields an operation selects once its
    fragments are expanded, and rejects it past GRAPHQL_QUERY_SELECTION_LIMIT. It runs over HTTP and
    WebSocket, for the operation being executed.
  • Fixed a union fragment spread under more than one m2a member losing the fields of all but one, and
    an alias under an m2a member landing at the wrong deep path.
  • Aliases and arguments are written into deep in place instead of merging into a fresh copy of
    everything already under the path.

Environment variables

Variable Default Bounds
QUERY_FILTER_MAX_NODES 10000 total filter/deep nodes across a query
QUERY_FILTER_MAX_DEPTH 50 nesting depth of a filter, and of deep
GRAPHQL_QUERY_SELECTION_LIMIT 10000 fields an operation selects once its fragments are expanded

Set any of them to Infinity to opt out. An unusable value is logged once and the default used.

WebSocket

  • Enforced MAX_PAYLOAD_SIZE on incoming messages. A larger message closes the connection with
    1009; before this, only ws's own 100MB cap applied.
  • Wrapped the whole message handler, so an error thrown while handling a message is reported to the
    client instead of escaping as an unhandled rejection that takes the process down.

Linear-time parsing

  • Reworked the patterns in adjustDate, generateJoi's _ends_with family, XMP metadata parsing,
    deep-map-filter, use-prompts and the release-notes generator, and made get() iterative.
    adjustDate and get() also take a hard cap on input length and path depth.
  • Enabled regexp/no-super-linear-backtracking as an error repo-wide.

Tested Scenarios

  • Updated and ran tests.

Review Notes / Questions / Concerns

  • QUERY_FILTER_MAX_NODES is the one that will bind: every object, array and value counts, so an
    _in over 9997 values is rejected.
  • Repeated fragment spreads are no longer deduplicated, so { ...F ...F } costs F twice against
    GRAPHQL_QUERY_SELECTION_LIMIT. The count matches exactly what the resolvers build.

Checklist

Leave unchecked where not applicable

  • Tests added/updated
  • Documentation PR created in directus/docs#871
  • OpenAPI updated
  • SDK (@directus/sdk) updated to reflect the changes
  • Types (@directus/types) updated to reflect the changes
  • GraphQL schema updated to reflect the changes
  • System data (@directus/system-data) updated for changes to system collections/fields/relations
  • Database migration added for schema/system changes
  • Environment variables documented for new/changed config
  • App translations added for new user-facing strings
  • Security implications apply

Fixes CMS-3036
Fixes CMS-3045
Fixes CMS-3047
Fixes CMS-3046
Fixes CMS-3044

@linear-code

linear-code Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

@ComfortablyCoding
ComfortablyCoding merged commit 00c6b7b into main Nov 16, 2026
107 of 113 checks passed
@ComfortablyCoding
ComfortablyCoding deleted the harden-query-parsing branch November 16, 2026 15:34
@github-actions github-actions Bot added this to the Next Release milestone Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants