Cookie Error

Report & discuss bugs found in SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
welkom_fs
Newbie
Newbie
Posts: 7
Joined: November 22nd, 2011, 1:52 pm

Cookie Error

Post by welkom_fs »

I read a few post from 3 years ago with what sounds like similar problems
Has this been fixed and is this a new one , or still the old problem?

Its easy to simulate:

When I access a web site which is on the same server as sabnzbd and then try to access sabnzb I get this error.
Clearing cache fixes it temporary.
thus:
http://172.27.1.201/gxms -- works from server (own site on local server)
after that
http://172.27.1.201:8081 gives error
Please advice
Regards
wfs__



500 Internal Server Error

The server encountered an unexpected condition which prevented it from fulfilling the request.

Traceback (most recent call last):
File "/usr/share/sabnzbdplus/cherrypy/_cprequest.py", line 593, in respond
self.process_headers()
File "/usr/share/sabnzbdplus/cherrypy/_cprequest.py", line 661, in process_headers
self.cookie.load(value)
File "/usr/lib/python2.7/Cookie.py", line 632, in load
self.__ParseString(rawdata)
File "/usr/lib/python2.7/Cookie.py", line 665, in __ParseString
self.__set(K, rval, cval)
File "/usr/lib/python2.7/Cookie.py", line 585, in __set
M.set(key, real_value, coded_value)
File "/usr/lib/python2.7/Cookie.py", line 460, in set
raise CookieError("Illegal key value: %s" % key)
CookieError: Illegal key value: http://172.27.1.201/gxms/
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Cookie Error

Post by shypike »

There are a few pieces of software whose cookies clash for some reason with those of SABnzbd.
The phenomenon is rare but also very hard to reproduce for us.
There is a naiveté in SABnzbd that makes it assume it's the only cookie owner of the base URL.
That's not true when you combine services behind an Apache server.
So far we haven't really looked for a solution because it's a rather rare problem
and it very probably means that we have to rename all cookies, which is something
that won't be appreciated by the 99% of users that are not affected, won't like.

BTW: what is gxms?
Can you give some insight into the content of the cookie?
From the log it shows that SABnzbd reads the cookie, but doesn't know how to handle it.
Or rather the Python library doesn't know.
That either means a bug in Python (very well possible and at the least it should handle the
problem more gracefully) or the cookie is just garbage or not according to standards.

Looking at where SABnzbd crashes, it looks like it encounters a cookie name that contains
illegal characters. Meaning characters outside of:
ascii_letters + digits + "!#$%&'*+-.^_`|~"
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Cookie Error

Post by shypike »

Possibly the cookie name contains a forward slash.
For some reason, the Python cookie handler doesn't like this.
For the next release, I will patch the CherryPy web framework that we use,
so that it will simply ignore cookies that it cannot handle.

You can patch the CherryPy code that comes with SABnzbd yourself.
I would appreciate feedback when it works (or not).
Starting from the folder where SABnzbd.py resides:
cherrypy/wsgiserver/_cprequest.py
Line 660:

Code: Select all

            if name == 'Cookie':
                self.cookie.load(value)
Change that to:

Code: Select all

            if name == 'Cookie':
                try:
                    self.cookie.load(value)
                except:
                    pass
Take care of indentation, which is essential in the Python language.
welkom_fs
Newbie
Newbie
Posts: 7
Joined: November 22nd, 2011, 1:52 pm

Re: Cookie Error

Post by welkom_fs »

Hi shypike

The two cookies in Chrome for the domain 172.27.1.201 are:

Name: 9f2a98456e7d90c3c44e0c6fad889182
Content: e24q4761m98tt0jja79iv4f5e2
Domain: 172.27.1.201
Path: /
Send for: Any kind of connection
Accessible to script: Yes
Created: Saturday, October 27, 2012 10:00:39 AM
Expires: When the browsing session ends

and

Name: http://172.27.1.201/gxms/
Content: 0.75,0.75
Domain: 172.27.1.201
Path: /
Send for: Any kind of connection
Accessible to script: Yes
Created: Saturday, October 27, 2012 11:14:42 AM
Expires: Monday, November 26, 2012 11:14:42 AM

I dont think it is 'other' software related.
I have an apache server on linux and have joomla 2.5 as the server software.
gxms is nothing, just four random letters which brings me to the root folder and index.php file where the joomla template is.

I followed the code in python and inserted a few lines to debug but I have never programmed in python ):
The debugger didn't reach my lines. The error showed up before the code was reached?

I did this:

import Cookie
import os
import sys
import time
import types

import logging
logging.basicConfig(level=logging.DEBUG, filename='debug.log')

/.../

# Call title() now (and use dict.__method__(headers))
# so title doesn't have to be called twice.
name = name.title()
value = value.strip()
logging.debug('Checking name and value.')
logging.debug(name, value)

This was never in the logs so I get the impression the error is thrown before then?

Anycase, I tried your patch and it seems to work!!!
Tnx for the quick help!
User avatar
shypike
Administrator
Administrator
Posts: 19774
Joined: January 18th, 2008, 12:49 pm

Re: Cookie Error

Post by shypike »

It"'s a shortcoming of Python's cookie library and of the way
CherryPy doesn't handle error situations.
SABnzbd reads all cookies related to it's base URL, which isn't
completely correct either.
So if this fixes the issue, it's good enough for now.
The fix will be in 0.7.5 too.

BTW: neither cookie comes from SABnzbd.
Post Reply