Issue Details (XML | Word | Printable)

Key: MODPYTHON-50
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Nicolas Lehuen
Reporter: Graham Dumpleton
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
mod_python

Session use outside of <Directory> directive.

Created: 30/Apr/05 04:29 PM   Updated: 05/Mar/06 01:55 PM
Return to search
Component/s: core
Affects Version/s: 3.1.4
Fix Version/s: 3.2.7

Time Tracking:
Not Specified

Resolution Date: 30/Apr/05 08:59 PM


 Description  « Hide
MODPYTHON-31 was previously closed with outcome of "Won't Fix".
The orginal problem as described in the report was actually not connected
to the Python traceback which was supplied, but the Python traceback
still identified a problem which shold be fixed. Have logged this separate
report to cover this issue.

The issue again came up recently on the mailing list as:

  http://www.modpython.org/pipermail/mod_python/2005-April/017933.html

Specifically, if PythonHandler is specified outside of any <Directory>
directive and sessions are used, you can get the error:

Mod_python error: "PythonHandler mod_python.psp"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in
HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 297, in
handler
    p.run()

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 191, in run
    session = Session.Session(req)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 389, in
Session
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 294, in
__init__
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 132, in
__init__
    Cookie.add_cookie(self._req, self.make_cookie())

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 160, in
make_cookie
    c.path = dirpath[len(docroot):]

TypeError: unsubscriptable object

This is ultimately caused by code in BaseSession.make_cookie() which reads:

    def make_cookie(self):

        if self._secret:
            c = Cookie.SignedCookie(COOKIE_NAME, self._sid,
                                    secret=self._secret)
        else:
            c = Cookie.Cookie(COOKIE_NAME, self._sid)

        config = self._req.get_options()
        if config.has_key("ApplicationPath"):
            c.path = config["ApplicationPath"]
        else:
            docroot = self._req.document_root()
            # the path where *Handler directive was specified
            dirpath = self._req.hlist.directory
            c.path = dirpath[len(docroot):]

            # Sometimes there is no path, e.g. when Location
            # is used. When Alias or UserDir are used, then
            # the path wouldn't match the URI. In those cases
            # just default to '/'
            if not c.path or not self._req.uri.startswith(c.path):
                c.path = '/'

        return c

What happens when PythonHandler is defined outside of a <Directory>
directive is that req.hlist.directory is None, thus indexing into dirpath
fails.

A workaround is to set ApplicationPath option, but true fix would be
to write code something like:

            # the path where *Handler directive was specified
            dirpath = self._req.hlist.directory
            if dirpath:
                docroot = self._req.document_root()
                c.path = dirpath[len(docroot):]
            else:
                c.path ='/'

            # Sometimes there is no path, e.g. when Location
            # is used. When Alias or UserDir are used, then
            # the path wouldn't match the URI. In those cases
            # just default to '/'
            if not c.path or not self._req.uri.startswith(c.path):
                c.path = '/'

This would eliminate the problem altogether and avoid user having to
use workaround of setting ApplicationPath option.

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Repository Revision Date User Message
ASF #165405 Sat Apr 30 11:58:51 UTC 2005 nlehuen Fix for MODPYTHON-50.
Files Changed
MODIFY /httpd/mod_python/trunk/lib/python/mod_python/Session.py

Nicolas Lehuen added a comment - 30/Apr/05 08:59 PM
Fixed as suggested by Graham.

Nicolas Lehuen made changes - 30/Apr/05 08:59 PM
Field Original Value New Value
Assignee Nicolas Lehuen [ nlehuen ]
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Nicolas Lehuen made changes - 30/Apr/05 08:59 PM
Description MODPYTHON-31 was previously closed with outcome of "Won't Fix".
The orginal problem as described in the report was actually not connected
to the Python traceback which was supplied, but the Python traceback
still identified a problem which shold be fixed. Have logged this separate
report to cover this issue.

The issue again came up recently on the mailing list as:

  http://www.modpython.org/pipermail/mod_python/2005-April/017933.html

Specifically, if PythonHandler is specified outside of any <Directory>
directive and sessions are used, you can get the error:

Mod_python error: "PythonHandler mod_python.psp"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in
HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 297, in
handler
    p.run()

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 191, in run
    session = Session.Session(req)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 389, in
Session
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 294, in
__init__
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 132, in
__init__
    Cookie.add_cookie(self._req, self.make_cookie())

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 160, in
make_cookie
    c.path = dirpath[len(docroot):]

TypeError: unsubscriptable object

This is ultimately caused by code in BaseSession.make_cookie() which reads:

    def make_cookie(self):

        if self._secret:
            c = Cookie.SignedCookie(COOKIE_NAME, self._sid,
                                    secret=self._secret)
        else:
            c = Cookie.Cookie(COOKIE_NAME, self._sid)

        config = self._req.get_options()
        if config.has_key("ApplicationPath"):
            c.path = config["ApplicationPath"]
        else:
            docroot = self._req.document_root()
            # the path where *Handler directive was specified
            dirpath = self._req.hlist.directory
            c.path = dirpath[len(docroot):]

            # Sometimes there is no path, e.g. when Location
            # is used. When Alias or UserDir are used, then
            # the path wouldn't match the URI. In those cases
            # just default to '/'
            if not c.path or not self._req.uri.startswith(c.path):
                c.path = '/'

        return c

What happens when PythonHandler is defined outside of a <Directory>
directive is that req.hlist.directory is None, thus indexing into dirpath
fails.

A workaround is to set ApplicationPath option, but true fix would be
to write code something like:

            # the path where *Handler directive was specified
            dirpath = self._req.hlist.directory
            if dirpath:
                docroot = self._req.document_root()
                c.path = dirpath[len(docroot):]
            else:
                c.path ='/'

            # Sometimes there is no path, e.g. when Location
            # is used. When Alias or UserDir are used, then
            # the path wouldn't match the URI. In those cases
            # just default to '/'
            if not c.path or not self._req.uri.startswith(c.path):
                c.path = '/'

This would eliminate the problem altogether and avoid user having to
use workaround of setting ApplicationPath option.
MODPYTHON-31 was previously closed with outcome of "Won't Fix".
The orginal problem as described in the report was actually not connected
to the Python traceback which was supplied, but the Python traceback
still identified a problem which shold be fixed. Have logged this separate
report to cover this issue.

The issue again came up recently on the mailing list as:

  http://www.modpython.org/pipermail/mod_python/2005-April/017933.html

Specifically, if PythonHandler is specified outside of any <Directory>
directive and sessions are used, you can get the error:

Mod_python error: "PythonHandler mod_python.psp"

Traceback (most recent call last):

  File "/usr/lib/python2.3/site-packages/mod_python/apache.py", line 299, in
HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 297, in
handler
    p.run()

  File "/usr/lib/python2.3/site-packages/mod_python/psp.py", line 191, in run
    session = Session.Session(req)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 389, in
Session
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 294, in
__init__
    timeout=timeout, lock=lock)

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 132, in
__init__
    Cookie.add_cookie(self._req, self.make_cookie())

  File "/usr/lib/python2.3/site-packages/mod_python/Session.py", line 160, in
make_cookie
    c.path = dirpath[len(docroot):]

TypeError: unsubscriptable object

This is ultimately caused by code in BaseSession.make_cookie() which reads:

    def make_cookie(self):

        if self._secret:
            c = Cookie.SignedCookie(COOKIE_NAME, self._sid,
                                    secret=self._secret)
        else:
            c = Cookie.Cookie(COOKIE_NAME, self._sid)

        config = self._req.get_options()
        if config.has_key("ApplicationPath"):
            c.path = config["ApplicationPath"]
        else:
            docroot = self._req.document_root()
            # the path where *Handler directive was specified
            dirpath = self._req.hlist.directory
            c.path = dirpath[len(docroot):]

            # Sometimes there is no path, e.g. when Location
            # is used. When Alias or UserDir are used, then
            # the path wouldn't match the URI. In those cases
            # just default to '/'
            if not c.path or not self._req.uri.startswith(c.path):
                c.path = '/'

        return c

What happens when PythonHandler is defined outside of a <Directory>
directive is that req.hlist.directory is None, thus indexing into dirpath
fails.

A workaround is to set ApplicationPath option, but true fix would be
to write code something like:

            # the path where *Handler directive was specified
            dirpath = self._req.hlist.directory
            if dirpath:
                docroot = self._req.document_root()
                c.path = dirpath[len(docroot):]
            else:
                c.path ='/'

            # Sometimes there is no path, e.g. when Location
            # is used. When Alias or UserDir are used, then
            # the path wouldn't match the URI. In those cases
            # just default to '/'
            if not c.path or not self._req.uri.startswith(c.path):
                c.path = '/'

This would eliminate the problem altogether and avoid user having to
use workaround of setting ApplicationPath option.
Fix Version/s 3.2.0 [ 11060 ]
Graham Dumpleton made changes - 05/Mar/06 01:55 PM
Status Resolved [ 5 ] Closed [ 6 ]