Edgewall Software
Modify

Opened 17 years ago

Closed 14 years ago

#4217 closed defect (wontfix)

Root_uri check fails if request_uri contains multiple /

Reported by: hector.rivas@… Owned by: Christopher Lenz
Priority: low Milestone:
Component: web frontend/mod_python Version: 0.10.2
Severity: minor Keywords: request_uri root_uri
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

If you have a root_uri like:

PythonOption TracUriRoot /devel/trac

and you request something like:

https://mysite.com/devel/trac////aproject/changeset/143

This error is raised:

[Mon Nov 20 07:14:00 2006] [error] [client xxxx] PythonHandler trac.web.modpython_frontend: Traceback (most recent call last):
[Mon Nov 20 07:14:00 2006] [error] [client xxx] PythonHandler trac.web.modpython_frontend:   File "/usr/lib/python2.3/site-package
s/mod_python/apache.py", line 299, in HandlerDispatch\n    result = object(req)
[Mon Nov 20 07:14:00 2006] [error] [client xxx] PythonHandler trac.web.modpython_frontend:   File "/var/lib/python-support/python2
.3/trac/web/modpython_frontend.py", line 87, in handler\n    gateway.run(dispatch_request)
[Mon Nov 20 07:14:00 2006] [error] [client xxx] PythonHandler trac.web.modpython_frontend:   File "/var/lib/python-support/python2
.3/trac/web/wsgi.py", line 87, in run\n    response = application(self.environ, self._start_response)
[Mon Nov 20 07:14:00 2006] [error] [client xxx] PythonHandler trac.web.modpython_frontend:   File "/var/lib/python-support/python2
.3/trac/web/main.py", line 262, in dispatch_request\n    raise ValueError('TracUriRoot set to %s but request URL '
[Mon Nov 20 07:14:00 2006] [error] [client xxx] PythonHandler trac.web.modpython_frontend: ValueError: TracUriRoot set to /devel/trac but request URL is /devel/trac////aproject/changeset/143

The problem is in /trac/web/main.py function dispatch_request and can be solved adding a regex substition:

       ...
       if 'TracUriRoot' in options:
            # Special handling of SCRIPT_NAME/PATH_INFO for mod_python, which
            # tends to get confused for whatever reason
            root_uri = options['TracUriRoot'].rstrip('/')
            request_uri = environ['REQUEST_URI'].split('?', 1)[0]

            # Subtitute multiple /
            request_uri = re.sub('/+', '/', request_uri)

            if not request_uri.startswith(root_uri):
                raise ValueError('TracUriRoot set to %s but request URL '
                                 'is %s' % (root_uri, request_uri))
            environ['SCRIPT_NAME'] = root_uri
            environ['PATH_INFO'] = urllib.unquote(request_uri[len(root_uri):])
     ...

Attachments (0)

Change History (3)

comment:1 by Emmanuel Blot, 17 years ago

Priority: normallow
Severity: normalminor

I'm not sure that supporting this kind of manually formed URLs is worth adding the cost of a regular expression evaluation for every single request…

comment:2 by Christian Boos, 17 years ago

Keywords: main.py raise removed
Milestone: 0.12

That pair of lines seems indeed fragile:

root_uri = options['TracUriRoot'].rstrip('/')

this may remove an arbitrary number of '/'

and:

environ['PATH_INFO'] = urllib.unquote(request_uri[len(root_uri):])

this will leave any remaining leading '/'

I wish there would be more context for that surrounding comment:

# Special handling of SCRIPT_NAME/PATH_INFO for mod_python, which
# tends to get confused for whatever reason

but nevertheless, some simplification of this code block seems to be possible, something like:

root_uri = options['TracUriRoot'].rstrip('/')
request_uri = environ['REQUEST_URI'].split('?', 1)[0]
if not request_uri.startswith(root_uri):
    raise ValueError('TracUriRoot set to %s but request URL '
                     'is %s' % (root_uri, request_uri))
environ['SCRIPT_NAME'] = root_uri.rstrip('/')
environ['PATH_INFO'] = urllib.unquote(request_uri[len(root_uri)-1:])

(untested)

comment:3 by Christian Boos, 14 years ago

Milestone: next-major-0.1X
Resolution: wontfix
Status: newclosed

Another obscure mod_python related issue…

If this problem still happens in current versions for someone, please reopen, preferably with a patch.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christopher Lenz to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.