Skip to content
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

CookieError - Attempt to set a reserved key 'expires' #29

Closed
mrxsal opened this issue Aug 26, 2023 · 1 comment
Closed

CookieError - Attempt to set a reserved key 'expires' #29

mrxsal opened this issue Aug 26, 2023 · 1 comment

Comments

@mrxsal
Copy link

mrxsal commented Aug 26, 2023

I am occasionally getting this error in my logs coming from _render_nextjs_page_to_string:

CookieError at {path}
Attempt to set a reserved key 'expires'

For some reason, bing's crawler/bot has a cookie name set with the name expires when it crawls my pages.

It seems that all cookies in the request are passed to _render_nextjs_page_to_string which then further processes it in aiohttp.ClientSession. Apparently it cannot handle cookies with reserved keywords. Perhaps we should sanitize the cookies by removing or ignoring the "expires" cookie name or any other cookie names with reserved keywords?

Full Traceback:

Traceback (most recent call last):
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib64/python3.8/concurrent/futures/_base.py", line 432, in result
    return self.__get_result()
  File "/usr/lib64/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/var/app/current/home/views.py", line 31, in nextjs_space_detail_slug
    return await render_nextjs_page(request)
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django_nextjs/render.py", line 148, in render_nextjs_page
    content, status, response_headers = await _render_nextjs_page_to_string(
  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django_nextjs/render.py", line 99, in _render_nextjs_page_to_string
    async with aiohttp.ClientSession(
  File "/var/app/venv/staging-LQM1lest/lib64/python3.8/site-packages/aiohttp/client.py", line 254, in __init__
    self._cookie_jar.update_cookies(cookies)
  File "/var/app/venv/staging-LQM1lest/lib64/python3.8/site-packages/aiohttp/cookiejar.py", line 172, in update_cookies
    tmp[name] = cookie  # type: ignore[assignment]
  File "/usr/lib64/python3.8/http/cookies.py", line 495, in __setitem__
    self.__set(key, rval, cval)
  File "/usr/lib64/python3.8/http/cookies.py", line 485, in __set
    M.set(key, real_value, coded_value)
  File "/usr/lib64/python3.8/http/cookies.py", line 350, in set
    raise CookieError('Attempt to set a reserved key %r' % (key,))
@danialkeimasi
Copy link
Member

It's a good idea to exclude them. Thanks!

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

No branches or pull requests

2 participants