home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / UnmaskQuery.pm < prev    next >
Encoding:
Perl POD Document  |  2001-07-13  |  3.6 KB  |  109 lines

  1. package Apache::HeavyCGI::UnmaskQuery;
  2. use Apache::Constants qw(:common);
  3. use constant AHU_DEBUG => 0;
  4. use strict;
  5. use vars qw($VERSION);
  6. $VERSION = sprintf "%d.%03d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/;
  7.  
  8.  
  9. sub handler {
  10.   my($r) = @_;
  11.   my $uri = $r->uri;
  12.   if ( my($u1,$u2) = $uri =~ / ^ ([^?]+?) ; ([^?]*) $ /x ) {
  13.     $r->uri($u1);
  14.     # $u2 =~ s/%..//g; # just testing
  15.     $u2 =~ s/;/&/g if $u2 =~ /&/; # don't mix: bug in Apache::Request ?
  16.     $r->args($u2);
  17.     warn "UnmaskQuery(v$VERSION): u1[$u1]u2[$u2]" if AHU_DEBUG;
  18.   } elsif ($uri =~ /\?/) {
  19.     my $args = $r->args;
  20.     if ($args =~ /&/ and $args =~ s/;/&/g) { # don't mix!
  21.       $r->args($args);
  22.       warn "UnmaskQuery(v$VERSION): args[$args]" if AHU_DEBUG;
  23.     } else {
  24.       warn "UnmaskQuery(v$VERSION): nothing" if AHU_DEBUG;
  25.     }
  26.   } elsif ( my($u1,$u2) = $uri =~ m/^(.*?)%3[Bb](.*)$/ ) {
  27.     # protect against old proxies that escape volens nolens
  28.     $r->uri($u1);
  29.     $u2 =~ s/%3B/;/gi;
  30.     $u2 =~ s/%26/;/gi; # &
  31.     $u2 =~ s/%3D/=/gi;
  32.     $r->args($u2);
  33.     warn "UnmaskQuery(v$VERSION): oldproxy-u1[$u1]u2[$u2]"
  34.     if 1||AHU_DEBUG;
  35.   }
  36.  
  37.   DECLINED;
  38. }
  39.  
  40. 1;
  41.  
  42. __END__
  43.  
  44. =head1 NAME
  45.  
  46. Apache::HeavyCGI::UnmaskQuery - Allow queries without a questionmark
  47.  
  48. =head1 SYNOPSIS
  49.  
  50.   <Perl>
  51.   require Apache::HeavyCGI::UnmaskQuery;
  52.   $PerlPostReadRequestHandler = "Apache::HeavyCGI::UnmaskQuery";
  53.   </Perl>
  54.  
  55.  -or-
  56.  
  57.   PerlModule Apache::HeavyCGI::UnmaskQuery
  58.   PerlPostReadRequestHandler Apache::HeavyCGI::UnmaskQuery
  59.  
  60. =head1 DESCRIPTION
  61.  
  62. This Apache Handler can be used from apache 1.3 (when
  63. post_read_request was introduced) upwards to turn a request that looks
  64. like an ordinary static request to the unsuspecting observer into a
  65. query that can be handled by the CGI or Apache::Request module or by
  66. the $r->args method.
  67.  
  68. The reason why you might want to do this lies in the fact that many
  69. cache servers in use today (1999) are configured wrongly in that they
  70. disallow caching of URIs with a questionmark in them. By composing
  71. URIs with a semicolon instead of a questionmark, these cache servers
  72. can be tricked into working correctly.
  73.  
  74. Thus this handler replaces the first semicolon in any request for an
  75. URI with a questionmark (unless that URI does already contain a
  76. questionmark). As this is being done in the very early stage of
  77. apache's handling phase, namely in a PerlPostReadRequestHandler, all
  78. subsequent phases can be tricked into seeing the request as a query.
  79.  
  80. Unfortunately the last paragraph is not completely true. Apache 1.3.4
  81. is not allowing C<%2F> (a slash in ASCII) and C<%00> (a binary 0) in
  82. the I<path> section of the HTTP URI, only in the I<searchoart>
  83. section. Apparently the URL is parsed before the during read_request....
  84.  
  85.     Breakpoint 1, 0x80b9d05 in ap_unescape_url ()
  86.     (gdb) bt
  87.     #0  0x80b9d05 in ap_unescape_url ()
  88.     #1  0x80b5a56 in ap_some_auth_required ()
  89.     #2  0x80b5fb0 in ap_process_request ()
  90.     #3  0x80adbcd in ap_child_terminate ()
  91.     #4  0x80add58 in ap_child_terminate ()
  92.     #5  0x80adeb3 in ap_child_terminate ()
  93.     #6  0x80ae490 in ap_child_terminate ()
  94.     #7  0x80aecc3 in main ()
  95.     (gdb) c
  96.  
  97.  
  98. So if any parameter needs to contain a slash or a binary 0,
  99. we must resort to a different escape method. Now it's turning
  100. ridiculous quickly. I believe, this is a bug in apache and must be
  101. fixed there. But what if the apche group doesn't listen to us?
  102.  
  103. Easy answer: don't escape slashes if you want to use this technique.
  104. Don't dare to need binary nulls in your parameters. Until it is
  105. figured out if apache group sees this as a bug or not.
  106.  
  107. =cut
  108.  
  109.