fix(graphql): prevent prototype pollution via GraphQL field name#7902
Open
zbrydon wants to merge 2 commits intoDataDog:masterfrom
Open
fix(graphql): prevent prototype pollution via GraphQL field name#7902zbrydon wants to merge 2 commits intoDataDog:masterfrom
zbrydon wants to merge 2 commits intoDataDog:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a prototype pollution bug in the GraphQL instrumentation where a crafted query using
__proto__as a field name could mutateObject.prototypevia thefieldsobject used to track resolver spans.Additionally hardens
pathToArrayto only include path segments that are strings or numbers, preventing non-string/non-number keys (such as those arising from a pollution attempt) from being passed into the trace serialisation pipeline - which would cause aDecodeErrorin the msgpack agent.Changes
fields: Object.create(null)- The execution context'sfieldsmap is now created with a null prototype, so assigning__proto__as a key stores it as a plain data property rather than triggering prototype mutation.pathToArraykey guard - Path segments are now only included in the flattened path if they are astringornumber, preventing unexpected key types from reaching span tags and the trace serialisation layer.__proto__as a field name does not crash the instrumentation and that the result data has a null prototype (confirmingObject.create(null)is in effect).Motivation
Fixing the error I encountered:
Without this fix, a GraphQL query such as
{ __proto__: hello }could silently polluteObject.prototypeduring execution tracing, potentially affecting all objects in the process. Even with theObject.create(null)fix alone, the__proto__key would still flow through to the msgpack serialiser and cause aDecodeError: The type of key must be string or number but objectwhen the trace was submitted to the agent.