Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

datadog-plugin-graphql is not validating if directives is an array #4097

Closed
mabilbao opened this issue Feb 23, 2024 · 5 comments
Closed

datadog-plugin-graphql is not validating if directives is an array #4097

mabilbao opened this issue Feb 23, 2024 · 5 comments
Assignees
Labels
asm-waf bug Something isn't working

Comments

@mabilbao
Copy link

mabilbao commented Feb 23, 2024

Hey guys,

After this PR, I started having an issue with this line (mentioned in a late comment by myself also).

  const directives = info.fieldNodes[0].directives
  for (const directive of directives) {

I am using a product called: KesytoneJS and the schema that it generates does not always return directives. For example:

🚀 ~ getResolverInfo ~ info.fieldNodes[0]: {
  kind: 'Field',
  name: { kind: 'Name', value: 'user' },
  arguments: [ { kind: 'Argument', name: [Object], value: [Object] } ],
  selectionSet: {
    kind: 'SelectionSet',
    selections: [ [Object], [Object], [Object] ],
    loc: Location {
      start: 19,
      end: 108,
      startToken: [Token],
      endToken: [Token],
      source: [Source]
    }
  }
}

Finally, the error I am getting is: TypeError: directives is not iterable.

I keep my project working with version 4.21.0 that doesn't have that change, but now I have a high dependabot issue due to that version is using lodash.pick.
It looks like Lodash doesn't have a patch version yet: GHSA-p6mc-m468-83gw.
It looks like Datadog just removed the dependency in new versions:


Should we validate if directives is effectively iterable before the for?

I've tried to push a fix for this, but I am getting 403 when I push 🥲 I think we should do something like:

  const directives = info.fieldNodes[0].directives
  if (Array.isArray(directives)) {
    for (const directive of directives) {
      const argList = {}
      for (const argument of directive['arguments']) {
        argList[argument.name.value] = argument.value.value
      }

      if (Object.keys(argList).length) {
        resolverVars[directive.name.value] = argList
      }
    }
  }

Thanks in advance!

@mabilbao mabilbao changed the title datadog-plugin-graphql is not validating if Directives is an array datadog-plugin-graphql is not validating if directives is an array Feb 23, 2024
@simon-id simon-id added asm-waf bug Something isn't working labels Feb 23, 2024
@simon-id simon-id self-assigned this Feb 23, 2024
@simon-id
Copy link
Member

Once again, thank you for reporting this issue with detailed infos. We'll look into it asap and update the thread when we have news. Although this issue won't be resolved until next week as it's already friday afternoon for us :/

@mabilbao
Copy link
Author

Once again, thank you for reporting this issue with detailed infos. We'll look into it asap and update the thread when we have news. Although this issue won't be resolved until next week as it's already friday afternoon for us :/

Thank you @simon-id! No rush at all 😄

@uurien
Copy link
Collaborator

uurien commented Feb 29, 2024

PR with the fix has been merged: #4116
It's going to be fixed in the next release.
thanks @mabilbao

@mabilbao
Copy link
Author

PR with the fix has been merged: #4116 It's going to be fixed in the next release. thanks @mabilbao

Thank you so much @uurien! This was super fast 😄

@uurien
Copy link
Collaborator

uurien commented Mar 7, 2024

Hello,
Last release should fix the problem (v5.6.0, v4.30.0, 3.51.0).

I'm closing the issue.
Thanks @mabilbao

@uurien uurien closed this as completed Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asm-waf bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants