You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "David E. Wheeler" <da...@kineticode.com> on 2010/01/26 23:58:49 UTC

Redirect WTF

Fellow mod_perlers,

Here's a weird one for you. I'm testing Bricolage on mod_perl 2, getting it ready for release, and noticed that some sort of redirect is happening when I don't expect it.

To whit, I have this configuration:

NameVirtualHost *:80
<VirtualHost *:80>
  DocumentRoot           /usr/local/bricolage/comp
  ServerName             benedict.local
  DefaultType            "text/html; charset=utf-8"
  AddDefaultCharset      utf-8
  SetHandler             modperl
  PerlResponseHandler    Bric::App::Handler
  PerlAccessHandler      Bric::App::AccessHandler
  PerlCleanupHandler     Bric::App::CleanupHandler
  PerlOptions            +GlobalRequest
  RedirectMatch          permanent .*\/favicon\.ico$ http://benedict.local/media/images/bricicon.ico
  TraceEnable            off
  PerlTransHandler       Bric::App::PreviewHandler::uri_handler
  <Location /logout>
    PerlAccessHandler   Bric::App::AccessHandler::logout_handler
    PerlCleanupHandler  Bric::App::CleanupHandler
  </Location>
  <Location /login>
    SetHandler          modperl
    PerlAccessHandler   Bric::App::AccessHandler::okay
    PerlResponseHandler Bric::App::Handler
    PerlCleanupHandler  Bric::App::CleanupHandler
  </Location>
  <Location /media>
    SetHandler          default-handler
    PerlAccessHandler   Apache2::Const::OK
    PerlCleanupHandler  Apache2::Const::OK
  </Location>
  <Location /media/js>
    ForceType           "text/javascript; charset=utf-8"
  </Location>
  <Location /media/css>
    ForceType           "text/css"
  </Location>
  <Location /data>
    SetHandler          default-handler
  </Location>
  <Location /soap>
    SetHandler          modperl
    PerlResponseHandler Bric::SOAP::Handler
    PerlAccessHandler   Apache2::Const::OK
  </Location>
  <Location /dist>
    SetHandler          modperl
    PerlResponseHandler Bric::Dist::Handler
  </Location>
  <Location /data/preview>
    ExpiresActive       On
    ExpiresDefault      "now plus 0 seconds"
    PerlFixupHandler    Apache2::Const::OK
  </Location>
</VirtualHost>

Note that the hosthame is "benedict.local". Now I often just use localhost when using Bricolage, and most of the time that works fine. But there is one JavaScript-triggered redirect button that looks like this:

    window.location.href = '/admin/profile/dest?id=1024'

And when I click it, The request goes to mod_perl and I see it come through the access handler and the fixup handler as a request to localhost. But then the PerlReponseHandler never fires! Instead, I see another request come in for the same URL path, but this time for the host name benedict.local. It's almost as if something in Apache or mod_perl is seeing that the request is for a different domain name and helpfully trying to redirect. But it's not helpful (I get a new login screen), and I don't understand why the same thing doesn't happen for other requests.

Is there something like that in mod_perl2 and I'm just missing it? Or is it more likely that there's some other mysterious bit of code in Bricolage that's doing it and I just haven't found it yet? If the latter, what comes between the PerlFixupHandler and PerlResponseHandler? Because in that first request, the fixup handler fires but the response handler never does.

TIA,

David















Re: Redirect WTF

Posted by Adam Prime <ad...@utoronto.ca>.
David E. Wheeler wrote:
> On Jan 27, 2010, at 7:23 AM, Adam Prime wrote:
> 
>> This smells like a UseCanonicalName On + mod_dir redirect to me.  If the directory /admin/profile/dest exists in the document root, there's a good chance it is.
> 
> Ooh, thanks! I can see that I have mod_dir as a DSO, but I'm not loading it. The only modules loaded are:
> 
>     LoadModule 	 perl_module /usr/local/apache2/modules/mod_perl.so
>     LoadModule 	 expires_module modules/mod_expires.so
>     LoadModule 	 apreq_module modules/mod_apreq2.so
> 
> Might the core be loading it somehow?

It appears that mod_dir is compiled and loaded by default unless you 
take steps to exclude it:

http://httpd.apache.org/docs/2.2/mod/mod_dir.html

http://httpd.apache.org/docs/2.2/mod/module-dict.html#Status

Adam

Re: Redirect WTF

Posted by "David E. Wheeler" <da...@kineticode.com>.
On Jan 27, 2010, at 7:23 AM, Adam Prime wrote:

> This smells like a UseCanonicalName On + mod_dir redirect to me.  If the directory /admin/profile/dest exists in the document root, there's a good chance it is.

Ooh, thanks! I can see that I have mod_dir as a DSO, but I'm not loading it. The only modules loaded are:

    LoadModule 	 perl_module /usr/local/apache2/modules/mod_perl.so
    LoadModule 	 expires_module modules/mod_expires.so
    LoadModule 	 apreq_module modules/mod_apreq2.so

Might the core be loading it somehow?

Thanks,

Daivd

Re: Redirect WTF

Posted by Adam Prime <ad...@utoronto.ca>.
David E. Wheeler wrote:
> Fellow mod_perlers,
> 
> <snip>
> 
> Note that the hosthame is "benedict.local". Now I often just use localhost when using Bricolage, and most of the time that works fine. But there is one JavaScript-triggered redirect button that looks like this:
> 
>     window.location.href = '/admin/profile/dest?id=1024'
> 
> And when I click it, The request goes to mod_perl and I see it come through the access handler and the fixup handler as a request to localhost. But then the PerlReponseHandler never fires! Instead, I see another request come in for the same URL path, but this time for the host name benedict.local. It's almost as if something in Apache or mod_perl is seeing that the request is for a different domain name and helpfully trying to redirect. But it's not helpful (I get a new login screen), and I don't understand why the same thing doesn't happen for other requests.
> 
> Is there something like that in mod_perl2 and I'm just missing it? Or is it more likely that there's some other mysterious bit of code in Bricolage that's doing it and I just haven't found it yet? If the latter, what comes between the PerlFixupHandler and PerlResponseHandler? Because in that first request, the fixup handler fires but the response handler never does.
> 

This smells like a UseCanonicalName On + mod_dir redirect to me.  If the 
directory /admin/profile/dest exists in the document root, there's a 
good chance it is.

HTH,

Adam

Re: Redirect WTF

Posted by "David E. Wheeler" <da...@kineticode.com>.
On Jan 26, 2010, at 3:18 PM, Fred Moyer wrote:

> I don't know if this could be an issue, but if I were to write this
> config snippet, I would create a root <Location /> block, and put the
> transhandler outside that (with the other location based directives
> inside).

The transhandler isn't used in production Bricolage installs, so I'm not too worried about it. It's mostly just there for folks evaluating Bricolage, as it manages a sort of internal preview server. Production installs turn that off and use an external server for previews.

Thanks,

David


Re: Redirect WTF

Posted by Fred Moyer <fr...@redhotpenguin.com>.
On Tue, Jan 26, 2010 at 2:58 PM, David E. Wheeler <da...@kineticode.com> wrote:
> Fellow mod_perlers,
>
> Here's a weird one for you. I'm testing Bricolage on mod_perl 2, getting it ready for release, and noticed that some sort of redirect is happening when I don't expect it.
>
> To whit, I have this configuration:

I don't know if this could be an issue, but if I were to write this
config snippet, I would create a root <Location /> block, and put the
transhandler outside that (with the other location based directives
inside).

>
> NameVirtualHost *:80
> <VirtualHost *:80>
>  DocumentRoot           /usr/local/bricolage/comp
>  ServerName             benedict.local
>  DefaultType            "text/html; charset=utf-8"
>  AddDefaultCharset      utf-8
>  SetHandler             modperl
>  PerlResponseHandler    Bric::App::Handler
>  PerlAccessHandler      Bric::App::AccessHandler
>  PerlCleanupHandler     Bric::App::CleanupHandler
>  PerlOptions            +GlobalRequest
>  RedirectMatch          permanent .*\/favicon\.ico$ http://benedict.local/media/images/bricicon.ico
>  TraceEnable            off
>  PerlTransHandler       Bric::App::PreviewHandler::uri_handler
>  <Location /logout>
>    PerlAccessHandler   Bric::App::AccessHandler::logout_handler
>    PerlCleanupHandler  Bric::App::CleanupHandler
>  </Location>
>  <Location /login>
>    SetHandler          modperl
>    PerlAccessHandler   Bric::App::AccessHandler::okay
>    PerlResponseHandler Bric::App::Handler
>    PerlCleanupHandler  Bric::App::CleanupHandler
>  </Location>
>  <Location /media>
>    SetHandler          default-handler
>    PerlAccessHandler   Apache2::Const::OK
>    PerlCleanupHandler  Apache2::Const::OK
>  </Location>
>  <Location /media/js>
>    ForceType           "text/javascript; charset=utf-8"
>  </Location>
>  <Location /media/css>
>    ForceType           "text/css"
>  </Location>
>  <Location /data>
>    SetHandler          default-handler
>  </Location>
>  <Location /soap>
>    SetHandler          modperl
>    PerlResponseHandler Bric::SOAP::Handler
>    PerlAccessHandler   Apache2::Const::OK
>  </Location>
>  <Location /dist>
>    SetHandler          modperl
>    PerlResponseHandler Bric::Dist::Handler
>  </Location>
>  <Location /data/preview>
>    ExpiresActive       On
>    ExpiresDefault      "now plus 0 seconds"
>    PerlFixupHandler    Apache2::Const::OK
>  </Location>
> </VirtualHost>
>
> Note that the hosthame is "benedict.local". Now I often just use localhost when using Bricolage, and most of the time that works fine. But there is one JavaScript-triggered redirect button that looks like this:
>
>    window.location.href = '/admin/profile/dest?id=1024'
>
> And when I click it, The request goes to mod_perl and I see it come through the access handler and the fixup handler as a request to localhost. But then the PerlReponseHandler never fires! Instead, I see another request come in for the same URL path, but this time for the host name benedict.local. It's almost as if something in Apache or mod_perl is seeing that the request is for a different domain name and helpfully trying to redirect. But it's not helpful (I get a new login screen), and I don't understand why the same thing doesn't happen for other requests.
>
> Is there something like that in mod_perl2 and I'm just missing it? Or is it more likely that there's some other mysterious bit of code in Bricolage that's doing it and I just haven't found it yet? If the latter, what comes between the PerlFixupHandler and PerlResponseHandler? Because in that first request, the fixup handler fires but the response handler never does.
>
> TIA,
>
> David
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>