The foswiki svn repository will become read-only on Friday 8/8. Developers should register for a http://github.com/ account for commit access to foswiki.

Item10669: Relax the check which assigns {DefaultUrlHost} as the urlHost, to detect localhost URL variants using https and custom port numbers

Priority: CurrentState: AppliesTo: Component: WaitingFor:
Low Closed Engine    
lib/Foswiki.pm at line 1693 should be modified to check whether the urlHost begins with 'http://localhost' rather than being equal to it. This fixes edge cases such as mine, where a proxy-passing setup means the urlHost is actually 'http://localhost:81'.

This was asked as a question here: http://foswiki.org/Support/Question842

-- JustinClarke - 22 Apr 2011

er, wow.

I use mod_proxy_html and other mess, and here you are with another simpler solution.

thankyou. I've changed it so that you use the 'RemovePort' option, and then we compare to http://localhost - can you tell me if that works for you?

-- SvenDowideit -

Does this need to accommodate https: and not just http:

-- GeorgeClark - 08 Mar 2012

I really don't know.

    if ( $url && $url =~ m{^([^:]*://[^/]*).*$} ) {
        $this->{urlHost} = $1;

        if ( $Foswiki::cfg{RemovePortNumber} ) {
            $this->{urlHost} =~ s/\:[0-9]+$//;
        }
        # If the urlHost in the url is localhost, this is a lot less
        # useful than the default url host. This is because new CGI("")
        # assigns this host by default - it's a default setting, used
        # when there is nothing better available.
        if ( $this->{urlHost} =~ /(https?):\/\/localhost/i ) {
            my $protocol = $1;
            $this->{urlHost} = $Foswiki::cfg{DefaultUrlHost};
        }

lets say for a moment that I do test for both http and https as above, what should happen? should both be unconditionally re-written to point to the one protocol (ie, force http to always be https or visversa, or should DefaultUrlHost be changed depending on incoming protocol, or what?)

I find the entire thing a bit horrifyingly obtuse, and always get annoyed that my foswiki is re-writing my url's if i'm using localhost.

clearly, some really really strong docco explaining why you'd want to do what would help - I can't say i entirely understandy why the RemovePortNumber configure option exists - and the help for it tells me nothing about the use case.

SO, I'm going to wimp out and write it this way:

    #{urlHost}  is needed by loadSession..
    my $url = $query->url();
    if ( $url && $url =~ m{^([^:]*://[^/]*).*$} ) {
        $this->{urlHost} = $1;

        if ( $Foswiki::cfg{RemovePortNumber} ) {
            $this->{urlHost} =~ s/\:[0-9]+$//;
        }
        # If the urlHost in the url is localhost, this is a lot less
        # useful than the default url host. This is because new CGI("")
        # assigns this host by default - it's a default setting, used
        # when there is nothing better available.
        if ( $this->{urlHost} =~ /(https?):\/\/localhost/i ) {
            my $protocol = $1;
            #only replace localhost _if_ the protocol matches the one specified in the DefaultUrlHost
            if ($Foswiki::cfg{DefaultUrlHost} =~ /^$protocol/i ) {
                $this->{urlHost} = $Foswiki::cfg{DefaultUrlHost};
            }
        }
    }
    else {
        $this->{urlHost} = $Foswiki::cfg{DefaultUrlHost};
    }

-- SvenDowideit - 10 Mar 2012

ok, re-written it after writing unit tests - which meant adding (some) support for full url processing in Unit::Request

-- SvenDowideit - 14 Mar 2012

Re-titled for release notes, because I had no idea what this was about when I first read it.

-- PaulHarvey - 14 Mar 2012

 

ItemTemplate edit

Summary Relax the check which assigns {DefaultUrlHost} as the urlHost, to detect localhost URL variants using https and custom port numbers
ReportedBy JustinClarke
Codebase 1.1.4, 1.1.4 RC2, 1.1.4 RC1, 1.1.4 beta2, 1.1.4 beta1, 1.1.3, trunk
SVN Range
AppliesTo Engine
Component
Priority Low
CurrentState Closed
WaitingFor
Checkins Foswikirev:14251 Foswikirev:14252 Foswikirev:14272 Foswikirev:14275 Foswikirev:14311 Foswikirev:14312
TargetRelease patch
ReleasedIn 1.1.5
CheckinsOnBranches Release01x01 trunk
trunkCheckins Foswikirev:14252 Foswikirev:14275 Foswikirev:14312
Release01x01Checkins Foswikirev:14251 Foswikirev:14272 Foswikirev:14311
Topic revision: r13 - 11 Apr 2012, GeorgeClark
 
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. see CopyrightStatement. Creative Commons License