laravel-graphql icon indicating copy to clipboard operation
laravel-graphql copied to clipboard

Mutation exposes data as query string parameters

Open shabaz-ejaz opened this issue 7 years ago • 5 comments

Lets say I have a simple User mutation like this:

mutation updateUsersEmail{updateUser(id:30,email:"[email protected]", password:"my password"){id,email,name}}

When I check the network request that was made it shows the following:

2017-10-24_11h34_54

My password is visible in the query string params. Isn't this a security flaw? My data would be exposed, whereas in a traditional REST approach the data will be hidden in the payload as it will be using a POST request.

shabaz-ejaz avatar Oct 24 '17 10:10 shabaz-ejaz

You dont have to use the GET method, you also can use the POST method as well.

kevinvdburgt avatar Oct 27 '17 00:10 kevinvdburgt

Do you have an example of how to use this with POST? I'd be interested to know how this works as GraphQL utlilizes the url a lot.

shabaz-ejaz avatar Jan 25 '18 09:01 shabaz-ejaz

I have tested this with POSTMAN. I ran the exact same mutation with a POST request, and it still exposes the parameters as GET variables.

When I test this by doing dd($_GET) I get the following:

image

When I test with dd($_POST) I get nothing.

So what's happening here is it is not sending the actual params as POST payload data, it always sends them as query string params which is very wrong if you want to be posting sensitive data.

So how do we actually send the data as POST payload data?

shabaz-ejaz avatar Jan 25 '18 09:01 shabaz-ejaz

GraphQl doesn't have restrictions on HTTP methods. You are sending the mutation over query strings, so you will get those in $_GET always If you want to get data in $_POST, you need to use the body/payload. Example: screen shot 2018-01-31 at 5 00 01 pm

I recommend you to use Insomnia tool, it has some options to write graphql query easily

If you want to make restrictions on the HTTP methods you will need to create your own routing layer.

faiverson avatar Jan 31 '18 20:01 faiverson

To create your own layer/filter, you can set a new controller in the package options and then use something like: if($route->named('graphql.query')) if($route->named('graphql.query.post')) There are an option also to split queries and mutations in different urls hope this help!

faiverson avatar Jan 31 '18 20:01 faiverson