Skip to content

blockFieldSuggestion plugin crashes on errors with undefined message #854

@strongpauly

Description

@strongpauly

The blockFieldSuggestion plugin's didEncounterErrors handler calls error.message.replace() without checking if error.message is defined, causing a TypeError when Apollo Server encounters a GraphQL error with an undefined message.

Stack trace:

  TypeError: Cannot read properties of undefined (reading 'replace')
      at Object.didEncounterErrors (node_modules/@escape.tech/graphql-armor/dist/graphql-armor.cjs.dev.js:63:43)
      at node_modules/@apollo/server/src/requestPipeline.ts:757:31
      at Array.map (<anonymous>)
      at didEncounterErrors (node_modules/@apollo/server/src/requestPipeline.ts:756:24)
      at processGraphQLRequest (node_modules/@apollo/server/src/requestPipeline.ts:505:15)

Affected code:

In packages/plugins/block-field-suggestions/src/index.ts, the formatter does:

  error.message.replace(/Did you mean ".+"\?/g, mask).trim();

There is no guard against error.message being undefined or null.

Environment:

  • @escape.tech/graphql-armor: 3.2.0
  • @apollo/server: 5.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions