Skip to content

GraphQL: Sanitizing GQL document #1261

Open
@ameyagholkar

Description

@ameyagholkar

Describe the bug

Disclaimer: I'm not sure if this is a bug or something that's missing. Ramping up on dd-trace, so if I'm missing something please don't hesitate to let me know 😄

We have straightforward setup for dd-trace where it's initialized in our Apollo server entrypoint. We're using apollo-server-express. Tracing worked out the box with graphQL spans being initialized and showing up correctly in the DataDog webUI.

In our testing, we did observe that there might be cases where we'd potentially need to sanitize the graphQL document by scrubbing PII data. These are only applicable to cases where we'd make one-off queries/mutations from an browser based apollo client.

For example; we'd like to scrub out the clear text password in this mutation.

mutation AuthenticateUser {
  authenticate(input: { username: 'foo', password: 'bar' } ) {
    userId
    name
  }
}

I've been trying to figure out what's the best place to intercept the trace and sanitize the document but I couldn't find one. Adding an apollo-server plugin to hook into request lifecycle doesn't let me get access to the underlying graphql plugin's spans. I'm assuming this is by design since I'm dealing with the server context in the plugin and not the underlying graphql's context.

I know of and have used the execute hook from the graphql plugin and it seems like a good place to do such modifications but there seem to be no hooks for parse and validate.

So, is there a way around this OR are implementing parse and validate hooks the best bet? If I'm missing something here, do let me know 👍🏼

Environment

graphQL

  • Operation system:
    • macOS
  • Node version:
    • v12.18.3
  • Tracer version:
    • v0.30.3
  • Agent version:
    • v7.25.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions