Ticket #8328 (new enhancement)
Opened 3 years ago
Last modified 15 months ago
Repeat SCRIPT_NAME fixup using SCRIPT_URL after environment selection
| Reported by: | Martin.vGagern@… | Owned by: | cboos |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.13 |
| Component: | web frontend | Version: | 0.11-stable |
| Severity: | normal | Keywords: | |
| Cc: | |||
| Release Notes: | |||
| API Changes: | |||
Description (last modified by cboos) (diff)
Ticket #2299 introduced a very useful feature to guess the SCRIPT_NAME from the SCRIPT_URL. However, this works less than optimal in some scenarios using an env_parent_dir.
Example: suppose you want to serve multiple project home pages using multiple virtual hosts from apache, and suppose further that, in order to save memory e.g. on a virtual server, you want to serve all Trac requests from a single FastCGI process. You can configure the process to serve from a parent of all trac environments, and add a line like this to the individual vhosts:
ScriptAlias /trac/ /path/to/trac.fcgi/my.environment.name/
This works well enough, except for the links. The link detection checks that the SCRIPT_URL (e.g. /trac/wiki/PageName) ends with the PATH_INFO (e.g. /my.environment.name/wiki/PageName) - which is not the case. Subsequently, the first part of the PATH_INFO is used to choose the environment, and moved from PATH_INFO to SCRIPT_NAME, causing a wrong script name of /trac/my.environment.name.
This can easily be solved by doing the same fixup after the environment has been chosen. In that case, PATH_INFO only contains /wiki/PageName which allows correct detection of /trac as the SCRIPT_NAME for that environment, not all environments.
In order to produce correct link in the listing of all available projects (in setups providing access to this list, not in a vhost like the one above), the fixup before should probably be kept in place as well, or be moved to send_project_index. Because it has to be executed from two places, it might make sense to factor it into a separate function.
A patch for this is easy. If you want me to write one, I'll do so. For now, I've simply moved the whole block dealing with script_url to after the env_path selection, as I don't need the project listing. So the concept is proven.
Attachments
Change History
Changed 3 years ago by Martin.vGagern@…
- Attachment LateScriptNameFixup.patch added
comment:1 follow-up: ↓ 2 Changed 3 years ago by cboos
- Milestone set to next-major-0.1X
comment:2 in reply to: ↑ 1 Changed 3 years ago by Martin.vGagern@…
Replying to cboos:
This looks like a quite useful change, but I fail to see all the implications
What makes you think there are more implications than you can see?
Seriously, I'm not 100% sure I've considered all possibilities, but still pretty sure that the thing is at least as safe as the current version.
and as I can't really test that,
If you want me to create an apache config for a test setup and send it to you (or rather attach it here), let me know.
I'll move it to a further release.
That would probably be 0.13, right? As I've patched my own copy, I personally am in no hurry to see this committed, so I can wait a year. Of course it would be even better if there were a branch for the next stable release, so that features like this can be committed to trunk and receive testing there without affecting 0.12.
comment:3 Changed 3 years ago by Martin.vGagern@…
While you are at it, you might consider using REQUEST_URI as a fallback in cases where SCRIPT_URL is undefined. It seems SCRIPT_URL is defined only if the mod_rewrite engine is enabled, whether that particular request was rewritten or not. With a ScriptAlias as described above, but without rewrite engine, SCRIPT_URL is not available, and REQUEST_URI is the second best bet.
Changed 3 years ago by Martin.vGagern@…
- Attachment RequestUri.patch added
Fall back to REQUEST_URI if SCRIPT_URL is unset
Changed 3 years ago by Martin.vGagern@…
- Attachment RequestUri.2.patch added
Fall back to REQUEST_URI if SCRIPT_URL is unset
comment:4 Changed 2 years ago by Martin.vGagern@…
I'll take back my patches about REQUEST_URI, as that won't work properly in the presence of url quoting. Back to my initial patch, which should be much safer.
comment:5 Changed 23 months ago by cboos
- Keywords verify added
comment:6 Changed 15 months ago by cboos
- Description modified (diff)
- Keywords verify removed
- Milestone changed from next-major-0.1X to 0.13
- Owner set to cboos
I admit I had a hard time getting my head around this…
Let me try to summarize.
The current situation, in case of TRAC_ENV_PARENT_DIR scenario, we have something like that:
ScriptAlias /trac/ /var/path/on/fs/to/script.fcgi
Now if we receive a request like: /trac/my.trac.env/wiki/WikiStart, Apache sets the variables like this:
REQUEST_URI /trac/my.trac.env/wiki/WikiStart SCRIPT_URL /trac/my.trac.env/wiki/WikiStart PATH_INFO /my.trac.env/wiki/WikiStart -------------------------------------------- SCRIPT_NAME /trac
We actually want to reconstruct SCRIPT_NAME from SCRIPT_URL (as we can't trust the current value of SCRIPT_NAME which might have been subject to rewriting), and for that we take the difference between SCRIPT_URL and PATH_INFO. The first segment in PATH_INFO will give us the name of the Trac environment, the rest will be the req.path_info.
Now in your situation, you want to have a direct access to the environment via a virtual host, and to that end you "augment" the file path in the ScriptAlias directive with an arbitrary name, like that:
ScriptAlias /trac/ /var/path/on/fs/to/script.fcgi/my.trac.env/
According to what you said, Apache will somehow detect that /var/path/on/fs/to/script.fcgi/my.trac.env/ doesn't exist on the file system, and will prepend /my.trac.env to the PATH_INFO:
REQUEST_URI /trac/wiki/WikiStart SCRIPT_URL /trac/wiki/WikiStart PATH_INFO /my.trac.env/wiki/WikiStart
I haven't verified this by myself, but I tried something similar with mod_wsgi, and I indeed see the same:
WSGIScriptAlias /trac /packages/trac/virtualenv-0.13/bin/trac.wsgi/my.trac.env/
REQUEST_URI /trac/wiki/WikiStart
SCRIPT_URL /trac/wiki/WikiStart
PATH_INFO /my.trac.env/wiki/WikiStart
comment:7 Changed 15 months ago by Martin.vGagern@…
Yes, your summary is accurate.



This looks like a quite useful change, but I fail to see all the implications and as I can't really test that, I'll move it to a further release.