Skip to content

application/json should only mandate 200 for _well-formed_ GraphQL-over-HTTP requests #241

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

Merged
merged 6 commits into from
Apr 1, 2023

Conversation

benjie
Copy link
Member

@benjie benjie commented Feb 14, 2023

Reviewing @enisdenjo's GraphQL-over-HTTP audits, I realise that I made a mistake when drafting this specification. In my head, each time I wrote "request" I meant "GraphQL-over-HTTP request", i.e. one that roughly conforms to:

type GraphQLOverHTTPRequest = {
  query: string;
  operationName?: string | null;
  variables?: Record<string, any> | null;
  extensions?: Record<string, any> | null;
}

However this was not explicitly stated in enough places, the end result being that we now effectively state that if you send garbage at a GraphQL legacy server it should return a 200 back at you. This was not my intent - my intent that 200 should only be used if the request conformed to the TypeScript shape above - query doesn't have to be parseable, and doesn't have to validate against your schema, but it does have to be present and it does have to be a string. If you can't even parse the JSON body of a request, you should definitely be returning a 400 Bad Request not a 200 Okay.

I've performed some edits to make this clearer, and have also copied the examples from application/graphql-response+json to application/json and corrected them for that location. I've also moved a few notes around where they would have been repeated otherwise, and made a few other small edits in line with accomplishing the above.

cc @graphql/http-maintainers

Copy link
Member

@spawnia spawnia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good change overall

Copy link
Member

@enisdenjo enisdenjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, often GQL servers are in situations where they don't do the parsing themselves (fastify or express does it for you) and therefore have limited control.

Also related to graphql/graphql-http#47.

@benjie
Copy link
Member Author

benjie commented Mar 7, 2023

@Shane32 I've updated the text you commented on and added a Note: - do you think this adds clarity, or the Note: should be omitted?

@Shane32
Copy link
Contributor

Shane32 commented Mar 7, 2023

@Shane32 I've updated the text you commented on and added a Note: - do you think this adds clarity, or the Note: should be omitted?

I don’t mind the extra clarity. Personally, it’s second nature to me to always ensure query arguments and sql parameters are correctly encoded ever since the days of Classic ASP, but judging from the amount of sql injection attacks over the years, a little extra clarity here is probably a good thing.

FYI, another option is to revert the change, and instead add a note stating that parameters are not double encoded but were restated for clarity.

@benjie
Copy link
Member Author

benjie commented Mar 21, 2023

@graphql/http-maintainers Does anyone want me to hold off on merging this?

Copy link
Contributor

@Shane32 Shane32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I just noted a typographical changes you may wish to make. Feel free to dismiss if not applicable.

@enisdenjo
Copy link
Member

Changes to the audit suite are already merged in graphql-http graphql/graphql-http#62.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants