graphql-python / graphql-python/graphene-django

CSRF cookie being set regardless of whether csrf middleware is used

Open
#1,065 0 comments 3 reactions 0 assignees View on GitHub
🐛bug
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

My project does not use CSRF middleware:

```python
MIDDLEWARE = [
# 'django.middleware.csrf.CsrfViewMiddleware'
}
```

And the view is set as exempt from CSRF:

```python
urlpatterns = [
path("graphql", csrf_exempt(GraphQLView.as_view())),
]
```

But despite this, a CSRF token is still *always* set when using the `/graphql` endpoint:

```python
]>
```

Only requests that go via graphene_django have this problem. Checking the source code shows that the problem is this line in views.py:

https://github.com/graphql-python/graphene-django/blob/55769e814f3fc3da6c6d39696d6d1460fd8c9c89/graphene_django/views.py#L141

Why is the `ensure_csrf_cookie` decorator used? graphene_django should respect the settings.py configuration and only use CSFR if it is enabled for the project. There is currently no way as far as I can tell to stop this cookie being set.

I am using django 2.2.16, graphene_django 2.8.2.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.