You are here: Foswiki>Tasks Web>Item10669 (10 Dec 2020, MichaelDaum)Edit Attach

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

pencil
Priority: Low
Current State: Closed
Released In: 1.1.5
Target Release: patch
Applies To: Engine
Component:
Branches: Release01x01 trunk
Reported By: JustinClarke
Waiting For:
Last Change By: MichaelDaum
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

Questionable url rewrite has been removed in Item14996.

-- MichaelDaum - 10 Dec 2020
 

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 distro:b7878a6a9fa3 distro:d04d19689148 distro:ee9b6b182dfa distro:5652f1af8f9d distro:1779a1b14f53 distro:2c5d31e0a69f
TargetRelease patch
ReleasedIn 1.1.5
CheckinsOnBranches Release01x01 trunk
trunkCheckins distro:d04d19689148 distro:5652f1af8f9d distro:2c5d31e0a69f
Release01x01Checkins distro:b7878a6a9fa3 distro:ee9b6b182dfa distro:1779a1b14f53
Topic revision: r14 - 10 Dec 2020, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy