web redirects should use relative URLs #1928
Labels
No Label
0.2.0
0.3.0
0.4.0
0.5.0
0.5.1
0.6.0
0.6.1
0.7.0
0.8.0
0.9.0
1.0.0
1.1.0
1.10.0
1.10.1
1.10.2
1.10a2
1.11.0
1.12.0
1.12.1
1.13.0
1.14.0
1.15.0
1.15.1
1.2.0
1.3.0
1.4.1
1.5.0
1.6.0
1.6.1
1.7.0
1.7.1
1.7β
1.8.0
1.8.1
1.8.2
1.8.3
1.8β
1.9.0
1.9.0-s3branch
1.9.0a1
1.9.0a2
1.9.0b1
1.9.1
1.9.2
1.9.2a1
LeastAuthority.com automation
blocker
cannot reproduce
cloud-branch
code
code-dirnodes
code-encoding
code-frontend
code-frontend-cli
code-frontend-ftp-sftp
code-frontend-magic-folder
code-frontend-web
code-mutable
code-network
code-nodeadmin
code-peerselection
code-storage
contrib
critical
defect
dev-infrastructure
documentation
duplicate
enhancement
fixed
invalid
major
minor
n/a
normal
operational
packaging
somebody else's problem
supercritical
task
trivial
unknown
was already fixed
website
wontfix
worksforme
No Milestone
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Reference: tahoe-lafs/trac-2024-07-25#1928
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Certain uses of the web interface result in unfollowable redirects.
This request to the web interface returns a redirect to a newly created directory, as a relative URL:
curl -v -F t=mkdir -F redirect_to_result=true http://localhost:3456/uri
< Location: uri/URI%3ADIR2%3Ajhjqp....
I think this is good. Unfortunately, this relative URL does not include a trailing slash, so when it is followed the response is another redirect, to append the slash. This second redirect is not relative. It begins with http://hostname:port/uri/URI.... where "hostname" is the host part of the value in the request's Host header and "port" is the configured web.port. Even if the request's Host header includes a port number, the web.port is used in the absolute URL constructed.
I think all redirects should use relative URLs, because according to https://en.wikipedia.org/wiki/HTTP_location "most popular web browsers tolerate the passing of a relative URL as the value for a Location header.[needed]citation".
If absolute URLs must be constructed for some reason, the port from the Host header should be used.
The motivation for this request is to make the web interface more usable on ports that are not the configured web.port, for example via SSH port forwarding or a Tor hidden service.
This also makes it easier to run tahoe as an unprivileged user while proxying port 80 to it.
If I'm not mistaken, currently, such a proxying configuration would require rewriting the absolute redirects in Tahoe's responses (perhaps with Apache's ProxyPassReverse directive) to avoid having certain functions (like the 2nd redirect after creating a directory) fail.
By always using relative redirects, simple TCP proxies (like SSH port forwarding) can be accommodated and the web ui shouldn't need to think about port numbers in URLs at all.
+1.
I'm trying to reverse proxy the tahoe web frontend through nginx in order to use nginx's built-in auth_basic functionality, since there currently isn't a way to authenticate access to the web interface. I can successfully look at the welcome page, but if I want to access a tahoe URI, it'll try to use the port configured in tahoe.cfg, instead of passing through nginx. Since tahoe is running on localhost, my connection fails.
These are the relevant configuration bits for tahoe and nginx, respectively.
#1861 seems to be in conflict with this ticket.
#2299 was a duplicate:
warner wrote on that ticket:
Lcstyle wrote on #461:
I think this is true for the pages that are easily reachable via obvious links, but not for the case in the Description of this bug. I'm not sure what exactly is happening in #2299 / comment:91149.
Replying to leif:
As well as fixing the redirect to be local, for efficiency we should change the mkdir to redirect to the URL ending with a slash.
Replying to bsd:
+1 - this also happens when creating directories.
IMHO, this is quite a show stopper for Tahoe in production environments.
(e.g. in a virtual machine, behind the reverse proxy of the host)
As a workaround, you can make nginx modify responses accordingly, for example:
proxy_redirect http://example.com:8080/ http://example.com/;
See also nginx docs
Replying to lpirl:
I was going to suggest this should be added to lafs-rpg until this bug is fixed... but then I decided to do some digging and see if the bug would actually be difficult to fix in Tahoe.
What I found is that, at least with Twisted 13.0.0 and Nevow 0.11.1, the correct port number from the request's
Host
header is now included in the reponse'sLocation
header! So, the workarounds shouldn't be necessary anymore and we can put TCP proxies in front of our web gateways and not end up with broken redirects.Here is what I found while trying to determine how these redirects are made:
rend.Page
and use itsaddSlash
feature.request.URLPath()
which I believe is from twisted.web.server.Request.URLPath, which calls twisted.python.urlpath.URLPath.fromRequest which calls back to twisted.web.server.Request.prePathURL which calls_prePathURL
which finally calls twisted.web.http.Request.getHost which returns a twisted.internet.tcp.Port from which it (Request.getHost
) brazenly accesses the apparently-undocumented instance attributeport
and stuffs it in a URL. (Or so it seems.)mkdir -p foo/bar; twistd -n web -p unix:*tmp/unixweb --path foo
and a made a TCP-to-unix proxy withsocat TCP4-LISTEN:8080,fork,reuseaddr unix:*tmp/unixweb
and then sent a request withcurl -v <http://127.0.0.1:8080/bar>
... but much to my surprise I got a response withLocation: <http://127.0.0.1:8080/bar/>
! So then I tested with Tahoe using my original instructions in this ticket description and found that the correct port number is now there as well. From reading the code I linked to above I'm not actually sure how this is happening, but it is.HTTP/1.0
requests (meaning, without aHost
header), theLocation
header in the response begins with<http://None/>
).addSlash
, check out warner's Nevow issue #52: deprecation warning in addSlash redirects on py2.6, regarding Tahoe issue #2312.Anyway, although this problem is now not so bad anymore, I'm not going to close this ticket because I still think we should have relative redirects everywhere. Hopefully the links above will help me or someone else figure out how to make that happen in the future.
Actually, as long as we have any absolute redirects, a rewrite workaround will still be necessary in the case that someone wants to put SSL in front of their web gateway because Twisted has no way of knowing that its absolute redirects should be
https://
.Replying to leif:
Exactly, and using SSL is essential when accessing the WUI over the Internet (regarding the confidentiality of the URLs).
Couldn't Twisted look for
X-Forwarded-*
headers? Esp.X-Forwarded-Proto
(or the more recentForwarded
header)?You could also use i2p or tor hidden services or SSH tunnels or various other things instead of HTTPS :)
Yes, I suppose if your TLS frontend is aware of HTTP and can add a header, Twisted could be made to look at that (maybe it started to at some point? as I said above I don't actually understand how it is getting the port number correct now).
It would be simpler if it could just make relative redirects, though.
True, but sometimes HTTP and ordinary Web browser access is desired. :)
And yes, this ticket is still valid since making the proxy fixing the redirects is really nothing more than a workaround.