# Missing cookies when using ASGI and HTTP/2

**URL:** <https://forum.djangoproject.com/t/missing-cookies-when-using-asgi-and-http-2/40946>\
**Category:** Mystery Errors\
**Created:** [May 15, 2025, 1:44pm UTC](https://forum.djangoproject.com/t/missing-cookies-when-using-asgi-and-http-2/40946 "2025-05-15T13:44:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IngmarStein](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ingmarstein/32/28522_2.png) [@IngmarStein](https://forum.djangoproject.com/u/IngmarStein)\
**Post date:** [May 15, 2025, 1:44pm UTC](https://forum.djangoproject.com/t/missing-cookies-when-using-asgi-and-http-2/40946/1 "2025-05-15T13:44:22Z")

</div>

[[BUG] Missing csrftoken cookie when using granian over HTTP/2 · Issue #9935 · paperless-ngx/paperless-ngx · GitHub](https://github.com/paperless-ngx/paperless-ngx/issues/9935) describes the issue in more detail. In a nutshell: when serving a Django app using ASGI and HTTP/2, cookies may get dropped. In case this hits the `csrftoken` cookie, it might explain the various “CSRF verification failed” topics in this forum category.

I had a brief look at the coke and it looks like the ASGI module joins multiple values for the same header using commas but `parse_cookie` splits by semicolon.

Same same issue has also hit other ASGI frameworks: [Separate cookie headers are not parsed into `Request.cookies` under HTTP/2 · encode/starlette · Discussion #2916 · GitHub](https://github.com/encode/starlette/discussions/2916)

I’m not familiar with Django, so it would be great if someone could fact-check the above.

---

<div class="post-metadata">

**Author:** ![IngmarStein](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ingmarstein/32/28522_2.png) [@IngmarStein](https://forum.djangoproject.com/u/IngmarStein)\
**Post date:** [May 15, 2025, 1:45pm UTC](https://forum.djangoproject.com/t/missing-cookies-when-using-asgi-and-http-2/40946/2 "2025-05-15T13:45:22Z")

</div>

And because new users can only include two links in a post, here are the code pointers:

ASGI module: [django/django/core/handlers/asgi.py at main · django/django · GitHub](https://github.com/django/django/blob/main/django/core/handlers/asgi.py#L97-L98)

`parse_cookie`: [django/django/http/cookie.py at main · django/django · GitHub](https://github.com/django/django/blob/main/django/http/cookie.py#L12)

---

<div class="post-metadata">

**Author:** ![carltongibson](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/carltongibson/32/267_2.png) [@carltongibson](https://forum.djangoproject.com/u/carltongibson)\
**Post date:** [May 15, 2025, 2:39pm UTC](https://forum.djangoproject.com/t/missing-cookies-when-using-asgi-and-http-2/40946/3 "2025-05-15T14:39:29Z")

</div>

Hi @IngmarStein, thanks for opening the discussion.

Yes, ASGIRequest needs to special case handling the `cookie` header here, in a similar way as it does with content-length &co.

Here’s a minimal reproduce:

```python
from django.conf import settings
from django.core.handlers.asgi import ASGIRequest

settings.configure(DEBUG=True)

scope = {
    "type": "http",
    "asgi": {
        "version": "3.0",
        "spec_version": "2.3",
    },
    "http_version": "2.0",
    "method": "GET",
    "scheme": "http",
    "path": "/",
    "raw_path": b"/",
    "query_string": b"",
    "root_path": "",
    "headers": [
        (b"cookie", b"a=abc;"),
        (b"cookie", b"b=def;"),
        (b"cookie", b"c=ghi;")
    ],
    "client": ("127.0.0.1", 10000),
    "server": ("127.0.0.1", 8000),
    "extensions": {}
}

request = ASGIRequest(scope, None)

print(request.COOKIES) # Prints: {'a': 'abc', ',b': 'def', ',c': 'ghi'}
assert request.COOKIES == {'a': 'abc', 'b': 'def', 'c': 'ghi'}

```

Would you care to create a ticket on the issue tracker? [https://code.djangoproject.com](https://code.djangoproject.com)  
You can link back here if you like?

---

<div class="post-metadata">

**Author:** ![IngmarStein](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/ingmarstein/32/28522_2.png) [@IngmarStein](https://forum.djangoproject.com/u/IngmarStein)\
**Post date:** [May 15, 2025, 2:45pm UTC](https://forum.djangoproject.com/t/missing-cookies-when-using-asgi-and-http-2/40946/4 "2025-05-15T14:45:42Z")

</div>

Thanks for the confirmation and the repro! I’ve created [#36399 (Missing cookies when using ASGI and HTTP/2) – Django](https://code.djangoproject.com/ticket/36399) to track this. The special case seems easy enough.
