]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1503483 - Convert redirects to absolute path
authorKohei Yoshino <kohei.yoshino@gmail.com>
Tue, 5 Mar 2019 21:35:40 +0000 (16:35 -0500)
committerGitHub <noreply@github.com>
Tue, 5 Mar 2019 21:35:40 +0000 (16:35 -0500)
24 files changed:
Bugzilla.pm
Bugzilla/App/Plugin/Glue.pm
Bugzilla/CGI.pm
Bugzilla/MFA.pm
Bugzilla/Search/Quicksearch.pm
attachment.cgi
chart.cgi
colchange.cgi
extensions/BMO/Extension.pm
extensions/BMO/lib/Reports/Groups.pm
extensions/BMO/lib/Reports/ReleaseTracking.pm
extensions/GuidedBugEntry/Extension.pm
extensions/Voting/Extension.pm
github.cgi
long_list.cgi
new_bug.cgi
post_bug.cgi
relogin.cgi
report.cgi
showattachment.cgi
token.cgi
userprefs.cgi
votes.cgi
xml.cgi

index d7720b22255389ad61c221e85ff94a3b92e01cdf..022c2531a772db164f4d6a4f4569066b7d32e570 100644 (file)
@@ -303,11 +303,9 @@ sub login {
       my $self_url     = trim($cgi->self_url);
       my $sig_type     = 'prev_url:' . $authenticated_user->id;
       my $self_url_sig = issue_hash_sig($sig_type, $self_url);
-      my $redir_url
-        = URI->new(Bugzilla->localconfig->{urlbase} . "reset_password.cgi");
+      my $redir_url    = URI->new('reset_password.cgi');
       $redir_url->query_form(prev_url => $self_url, prev_url_sig => $self_url_sig);
-      print $cgi->redirect($redir_url);
-      exit;
+      $cgi->base_redirect($redir_url->as_string);
     }
   }
   elsif (!i_am_webservice()
@@ -329,8 +327,7 @@ sub login {
 
     if ($grace_period == 0 || $expired) {
       if (!($on_mfa_page || $on_token_page || $do_logout)) {
-        print Bugzilla->cgi->redirect("userprefs.cgi?tab=mfa");
-        exit;
+        $cgi->base_redirect('userprefs.cgi?tab=mfa');
       }
     }
     else {
index b8b0c20bd1893308e275ccf9492f728cfa8828f8..9dca9fd608333736ec03ff451a96ac93849bbac9 100644 (file)
@@ -73,7 +73,7 @@ sub register {
       my ($c, $type) = @_;
 
       if ($type == LOGIN_REQUIRED) {
-        $c->redirect_to('/login');
+        $c->redirect_to(Bugzilla->localconfig->{basepath} . 'login');
         return undef;
       }
       else {
index 29b7174f44827c1b52b7a683d24ab8116a0f55f5..1656a869b082a5f82756a3e67b8df49a97173f4a 100644 (file)
@@ -885,6 +885,15 @@ sub redirect_to_urlbase {
   exit;
 }
 
+sub base_redirect {
+  my ($self, $path, $is_perm) = @_;
+  print $self->redirect(
+    -location => Bugzilla->localconfig->{basepath} . ($path || ''),
+    -status   => $is_perm ? '301 Moved Permanently' : '302 Found'
+  );
+  exit;
+}
+
 sub url_is_attachment_base {
   my ($self, $id) = @_;
   return 0 if !use_attachbase() or !i_am_cgi();
@@ -1042,6 +1051,11 @@ instead of calling this directly.
 
 Redirects from the current URL to one prefixed by the urlbase parameter.
 
+=item C<base_redirect>
+
+Redirects to the given path relative to the `basepath` parameter which is
+typically the root (`/`).
+
 =item C<set_dated_content_disp>
 
 Sets an appropriate date-dependent value for the Content Disposition header
index bd28f622180cf6dd26eecc7fc9401febc39b4347..4851394eb89e1cc8f2bece92f7ebf4a106126049 100644 (file)
@@ -89,8 +89,7 @@ sub verify_token {
   my $event = get_token_extra_data($token);
   delete_token($token);
   if (!$event) {
-    print Bugzilla->cgi->redirect('index.cgi');
-    exit;
+    Bugzilla->cgi->base_redirect();
   }
   return $event;
 }
index aa23fbc335c48d6c03ffa511c061f86e747b93b9..7d152aafbaa006dc7a12e6b8d0670950283b4f9c 100644 (file)
@@ -282,11 +282,8 @@ sub quicksearch {
   my $modified_query_string = $cgi->canonicalise_query(@params_to_strip);
 
   if ($cgi->param('load')) {
-    my $urlbase = Bugzilla->localconfig->{urlbase};
-
     # Param 'load' asks us to display the query in the advanced search form.
-    print $cgi->redirect(
-      -uri => "${urlbase}query.cgi?format=advanced&amp;" . $modified_query_string);
+    $cgi->base_redirect("query.cgi?format=advanced&$modified_query_string");
   }
 
   # Otherwise, pass the modified query string to the caller.
@@ -333,9 +330,7 @@ sub _bug_numbers_only {
   if ($searchstring !~ /,/ && !i_am_webservice()) {
 
     # Single bug number; shortcut to show_bug.cgi.
-    print $cgi->redirect(
-      -uri => Bugzilla->localconfig->{urlbase} . "show_bug.cgi?id=$searchstring");
-    exit;
+    $cgi->base_redirect("show_bug.cgi?id=$searchstring");
   }
   else {
     # List of bug numbers.
index df1b009fbb5f18166589f45575af2f572d516caa..081f4468ba8893815f8954acc327361946aa7fad 100755 (executable)
@@ -266,8 +266,7 @@ sub get_attachment {
         unless ($userid && $valid_token) {
 
           # Not a valid token.
-          print $cgi->redirect('-location' => Bugzilla->localconfig->{urlbase} . $path);
-          exit;
+          $cgi->base_redirect($path);
         }
 
         # Change current user without creating cookies.
@@ -389,12 +388,10 @@ sub view {
     {do_redirect => \$do_redirect});
 
   if ($do_redirect) {
-    my $uri = URI->new(Bugzilla->localconfig->{urlbase} . 'attachment.cgi');
+    my $uri = URI->new('attachment.cgi');
     $uri->query_param(id => $attachment->id);
     $uri->query_param(content_type => $contenttype) if $contenttype_override;
-
-    print $cgi->redirect('-location' => $uri);
-    exit 0;
+    $cgi->base_redirect($uri->as_string);
   }
 
   # Don't send a charset header with attachments--they might not be UTF-8.
index 7652680e4dfe24cb5befa19beb8b77f87f485db9..3c5536852bf18021e0b1c15a4e8ce04e85ac70e8 100755 (executable)
--- a/chart.cgi
+++ b/chart.cgi
@@ -62,10 +62,8 @@ if (!Bugzilla->feature('new_charts')) {
 # Go back to query.cgi if we are adding a boolean chart parameter.
 if (grep(/^cmd-/, $cgi->param())) {
   my $params = $cgi->canonicalise_query("format", "ctype", "action");
-  print $cgi->redirect("query.cgi?format="
-      . $cgi->param('query_format')
-      . ($params ? "&$params" : ""));
-  exit;
+  $cgi->base_redirect("query.cgi?format="
+      . $cgi->param('query_format') . ($params ? "&$params" : ''));
 }
 
 my $action    = $cgi->param('action');
@@ -87,8 +85,7 @@ $action ||= "assemble";
 # Go to buglist.cgi if we are doing a search.
 if ($action eq "search") {
   my $params = $cgi->canonicalise_query("format", "ctype", "action");
-  print $cgi->redirect("buglist.cgi" . ($params ? "?$params" : ""));
-  exit;
+  $cgi->base_redirect('buglist.cgi' . ($params ? "?$params" : ""));
 }
 
 $user->in_group(Bugzilla->params->{"chartgroup"}) || ThrowUserError(
@@ -224,11 +221,9 @@ elsif ($action eq "convert_search") {
     my $params = new Bugzilla::CGI($query->edit_link);
 
     # These two parameters conflict with the one below.
-    $url = $params->canonicalise_query('format', 'query_format');
-    $url = '&amp;' . html_quote($url);
+    $url = '&' . $params->canonicalise_query('format', 'query_format');
   }
-  print $cgi->redirect(-location => Bugzilla->localconfig->{urlbase}
-      . "query.cgi?format=create-series$url");
+  $cgi->base_redirect("query.cgi?format=create-series$url");
 }
 else {
   ThrowUserError('unknown_action', {action => $action});
index 542d3471904946d7cf72cac4b792f5131dec8fed..dadb5565df54c5983c5aaddf80002d0f00ffe321 100755 (executable)
@@ -139,15 +139,7 @@ if (defined $cgi->param('rememberedquery')) {
 
   my $params = new Bugzilla::CGI($cgi->param('rememberedquery'));
   $params->param('columnlist', join(",", @collist));
-  $vars->{'redirect_url'} = "buglist.cgi?" . $params->query_string();
-
-  # If we're running on Microsoft IIS, $cgi->redirect discards
-  # the Set-Cookie lines. In mod_perl, $cgi->redirect with cookies
-  # causes the page to be rendered as text/plain.
-  # Workaround is to use the old-fashioned  redirection mechanism.
-  # See bug 214466 and bug 376044 for details.
-  print $cgi->redirect($vars->{'redirect_url'});
-  exit;
+  $cgi->base_redirect('buglist.cgi?' . $params->query_string());
 }
 
 if (defined $cgi->param('columnlist')) {
index 6d368deeb590ee82f09aaf56077230360217624d..62ea207502ef6eec8f44b698455c58850496239d 100644 (file)
@@ -230,7 +230,7 @@ sub page_before_template {
     Bugzilla::Extension::BMO::Reports::Internship::report($vars);
   }
   elsif ($page eq 'email_queue.html') {
-    print Bugzilla->cgi->redirect('view_job_queue.cgi');
+    Bugzilla->cgi->base_redirect('view_job_queue.cgi');
   }
   elsif ($page eq 'release_tracking_report.html') {
     require Bugzilla::Extension::BMO::Reports::ReleaseTracking;
@@ -305,8 +305,7 @@ sub bounty_attachment {
 
     Bugzilla::BugMail::Send($bug->id, {changer => $user});
 
-    print Bugzilla->cgi->redirect('show_bug.cgi?id=' . $bug->id);
-    exit;
+    Bugzilla->cgi->base_redirect('show_bug.cgi?id=' . $bug->id);
   }
 
   if ($attachment) {
index 844ca282b01e13584b782d56f65d9acf244aef10..52fdffa94829a3fc9505219764dab5b9413abe6f 100644 (file)
@@ -84,8 +84,7 @@ sub membership_report {
   my $who = $cgi->param('who');
   if (!defined($who) || $who eq '') {
     if ($page eq 'group_membership.txt') {
-      print $cgi->redirect("page.cgi?id=group_membership.html&output=txt");
-      exit;
+      $cgi->base_redirect('page.cgi?id=group_membership.html&output=txt');
     }
     $vars->{'output'} = $cgi->param('output');
     return;
index 79f5b16237fd45d4c394dec2945ebe628f7c0d90..b6ed41b05aa284a824f295bceefa8195eaf0f359 100644 (file)
@@ -304,11 +304,7 @@ sub report {
     my $bugs = $dbh->selectcol_arrayref($query, undef, @params);
     push @$bugs, 0 unless @$bugs;
 
-    my $urlbase = Bugzilla->localconfig->{urlbase};
-    my $cgi     = Bugzilla->cgi;
-    print $cgi->redirect(
-      -url => "${urlbase}buglist.cgi?bug_id=" . join(',', @$bugs));
-    exit;
+    Bugzilla->cgi->base_redirect('buglist.cgi?bug_id=' . join(',', @$bugs));
   }
 
   #
index 72bae0d84c339c7c26aa69be169fc7fec1354319..bed190c02b20bd111cc963881a59cbe4b3d7d112 100644 (file)
@@ -42,12 +42,11 @@ sub enter_bug_start {
 
     # skip the first step if a product is provided
     if ($cgi->param('product')) {
-      print $cgi->redirect('enter_bug.cgi?format=guided'
+      $cgi->base_redirect('enter_bug.cgi?format=guided'
           . ($cgi->param('format_forced') ? '&format_forced=1' : '')
           . '#h=dupes' . '|'
           . url_quote($cgi->param('product')) . '|'
           . url_quote($cgi->param('component') || ''));
-      exit;
     }
 
     # Do not redirect to product forms if we came from there already
index 523ee653d8853df5131c75ddb17d2c35d946a810..df1500364fe4c70d3835731ca26d0e18c9905728 100644 (file)
@@ -534,8 +534,7 @@ sub _update_votes {
       exit;
     }
     elsif ($cgi->param('delete_all_votes') == 0) {
-      print $cgi->redirect("page.cgi?id=voting/user.html");
-      exit;
+      $cgi->base_redirect('page.cgi?id=voting/user.html');
     }
   }
   else {
index 25b2a3b5a08efd45939c9b2ff125f597cc384e3b..2d53f9b9e85e47dbbde071488e23a5dc7c4edf14 100755 (executable)
@@ -73,13 +73,12 @@ elsif (lc($cgi->request_method) eq 'get') {
   my $state_cookie = $cgi->cookie('github_state');
 
   # If the state or params are missing, or the github_state cookie is missing
-  # we just redirect to index.cgi.
+  # we just redirect to the homepage.
   unless ($state_param
     && $state_cookie
     && ($cgi->param('code') || $cgi->param('email')))
   {
-    print $cgi->redirect($urlbase . "index.cgi");
-    exit;
+    $cgi->base_redirect();
   }
 
   my $invalid_request = $state_param ne $state_cookie;
@@ -118,13 +117,13 @@ elsif (lc($cgi->request_method) eq 'get') {
   $target_uri->query_param_delete('logout');
 
   if ($target_uri->path =~ /attachment\.cgi/) {
-    my $attachment_uri = URI->new($urlbase . "attachment.cgi");
+    my $attachment_uri = URI->new('attachment.cgi');
     $attachment_uri->query_param(id => scalar $target_uri->query_param('id'));
     if ($target_uri->query_param('action')) {
       $attachment_uri->query_param(
         action => scalar $target_uri->query_param('action'));
     }
-    print $cgi->redirect($attachment_uri);
+    $cgi->base_redirect($attachment_uri->as_string);
   }
   else {
     print $cgi->redirect($target_uri);
index 6c72d4f1f42d99e6d62ee5fe6827f08ec968f4c0..41a893c90f785196b6b2b61b1429ebfcacb27107 100755 (executable)
@@ -38,4 +38,4 @@ my @ids = split(/[\s,]+/, $buglist);
 
 my $ids = join('', map { $_ = "&id=" . $_ } @ids);
 
-print $cgi->redirect("show_bug.cgi?format=multiple$ids");
+$cgi->base_redirect("show_bug.cgi?format=multiple$ids");
index b212293612f127dee2937dd10b2c7dce351e7b5e..97f593fbb2b9680199675b564aa1348e40d64713 100755 (executable)
@@ -123,8 +123,7 @@ if (lc($cgi->request_method) eq 'post') {
     push(@all_mail_results, $ref_sent);
   }
 
-  print $cgi->redirect(
-    Bugzilla->localconfig->{urlbase} . 'show_bug.cgi?id=' . $new_bug->bug_id);
+  $cgi->base_redirect('show_bug.cgi?id=' . $new_bug->bug_id);
 }
 else {
   print $cgi->header();
index ceef33c2461786a06da4d0200915a11fbc25e871..cb4e5db9904c4d730f824efb20f2ac651c7885ef 100755 (executable)
@@ -44,8 +44,7 @@ my $vars     = {};
 
 # redirect to enter_bug if no field is passed.
 unless ($cgi->param()) {
-  print $cgi->redirect(Bugzilla->localconfig->{urlbase} . 'enter_bug.cgi');
-  exit;
+  $cgi->base_redirect('enter_bug.cgi');
 }
 
 # BMO: Don't allow updating of bugs if disabled
index b7020b09895e23ed351c435796697a31d5914b51..aa00be7f185f6d65d472622aea252dc4e54223af 100755 (executable)
@@ -31,9 +31,8 @@ my $target;
 
 if (!$action) {
 
-  # redirect to index.cgi if no action is defined.
-  print $cgi->redirect(Bugzilla->localconfig->{urlbase} . 'index.cgi');
-  exit;
+  # redirect to the homepage if no action is defined.
+  $cgi->base_redirect();
 }
 
 # prepare-sudo: Display the sudo information & login page
index 63497b026acff4016c46fb0f4016b43de1f4693d..46038c7b2ed2a991b7e1f8004b9a3168f893525d 100755 (executable)
@@ -30,13 +30,8 @@ $cgi->content_security_policy(report_only => 0);
 # Go straight back to query.cgi if we are adding a boolean chart.
 if (grep(/^cmd-/, $cgi->param())) {
   my $params = $cgi->canonicalise_query("format", "ctype");
-  my $location
-    = "query.cgi?format="
-    . $cgi->param('query_format')
-    . ($params ? "&$params" : "");
-
-  print $cgi->redirect($location);
-  exit;
+  $cgi->base_redirect('query.cgi?format='
+      . $cgi->param('query_format') . ($params ? "&$params" : ''));
 }
 
 Bugzilla->login();
index b6bddbea68fb68f4690f369f58bc33a6e40d2a23..867f90a9ae8b4cabb23e9e77c242124b5648209f 100755 (executable)
@@ -36,9 +36,4 @@ my $id = $cgi->param('attach_id');
 detaint_natural($id) if defined $id;
 $id ||= "";
 
-print $cgi->redirect(
-  -location => "attachment.cgi?id=$id",
-  -status   => '301 Permanent Redirect'
-);
-
-exit;
+$cgi->base_redirect("attachment.cgi?id=$id", 1);
index 821772b1b1ce9b8629ffbcbd90f22788ebc39d7f..90acf2f55eeaf6c82ed331989f988f81ff986546 100755 (executable)
--- a/token.cgi
+++ b/token.cgi
@@ -461,8 +461,13 @@ sub verify_mfa_login {
   my $token = shift;
   my ($user, $event) = mfa_event_from_token($token);
   $user->authorizer->mfa_verified($user, $event);
-  print Bugzilla->cgi->redirect($event->{url} // 'index.cgi');
-  exit;
+
+  if ($event->{url}) {
+    print Bugzilla->cgi->redirect($event->{url});
+    exit;
+  }
+
+  Bugzilla->cgi->base_redirect();
 }
 
 sub mfa_event_from_token {
@@ -475,8 +480,7 @@ sub mfa_event_from_token {
   # sanity check
   if (!$user->mfa) {
     delete_token($token);
-    print Bugzilla->cgi->redirect('index.cgi');
-    exit;
+    Bugzilla->cgi->base_redirect();
   }
 
   # verify
index 2ac8dd4d52449264c49c005055b2374bc15cdefb..a308726f6953e80f6fb29f0b313a40fdbeb90233 100755 (executable)
@@ -214,8 +214,7 @@ sub DisableAccount {
   $user->update();
 
   Bugzilla->logout();
-  print Bugzilla->cgi->redirect(Bugzilla->localconfig->{urlbase});
-  exit;
+  Bugzilla->cgi->base_redirect();
 }
 
 sub DoSettings {
index 6655146745081361df2f54fd8e47879bc3537bce..57912cd7713e55d551dc85316f6d3c50b42a2df0 100755 (executable)
--- a/votes.cgi
+++ b/votes.cgi
@@ -48,5 +48,4 @@ else {
   ThrowUserError('unknown_action', {action => $action});
 }
 
-print $cgi->redirect('page.cgi?' . $cgi->query_string);
-exit;
+$cgi->base_redirect('page.cgi?' . $cgi->query_string);
diff --git a/xml.cgi b/xml.cgi
index 06425755966b5a3f6d72ad5aa28ead9f6ea390bb..2f72c92ab690bf12c39d1956740301c0dcf46ce9 100755 (executable)
--- a/xml.cgi
+++ b/xml.cgi
@@ -40,4 +40,4 @@ if (defined $cgi->param('id')) {
 
 my $ids = join('', map { $_ = "&id=" . $_ } @ids);
 
-print $cgi->redirect("show_bug.cgi?ctype=xml$ids");
+$cgi->base_redirect("show_bug.cgi?ctype=xml$ids");