Skip to content

Commit 3d91341

Browse files
authored
Bug 1503483 - Convert redirects to absolute path
1 parent 61c2457 commit 3d91341

24 files changed

Lines changed: 59 additions & 90 deletions

‎Bugzilla.pm‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,9 @@ sub login {
303303
my $self_url = trim($cgi->self_url);
304304
my $sig_type = 'prev_url:' . $authenticated_user->id;
305305
my $self_url_sig = issue_hash_sig($sig_type, $self_url);
306-
my $redir_url
307-
= URI->new(Bugzilla->localconfig->{urlbase} . "reset_password.cgi");
306+
my $redir_url = URI->new('reset_password.cgi');
308307
$redir_url->query_form(prev_url => $self_url, prev_url_sig => $self_url_sig);
309-
print $cgi->redirect($redir_url);
310-
exit;
308+
$cgi->base_redirect($redir_url->as_string);
311309
}
312310
}
313311
elsif (!i_am_webservice()
@@ -329,8 +327,7 @@ sub login {
329327

330328
if ($grace_period == 0 || $expired) {
331329
if (!($on_mfa_page || $on_token_page || $do_logout)) {
332-
print Bugzilla->cgi->redirect("userprefs.cgi?tab=mfa");
333-
exit;
330+
$cgi->base_redirect('userprefs.cgi?tab=mfa');
334331
}
335332
}
336333
else {

‎Bugzilla/App/Plugin/Glue.pm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ sub register {
7373
my ($c, $type) = @_;
7474

7575
if ($type == LOGIN_REQUIRED) {
76-
$c->redirect_to('/login');
76+
$c->redirect_to(Bugzilla->localconfig->{basepath} . 'login');
7777
return undef;
7878
}
7979
else {

‎Bugzilla/CGI.pm‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,15 @@ sub redirect_to_urlbase {
885885
exit;
886886
}
887887

888+
sub base_redirect {
889+
my ($self, $path, $is_perm) = @_;
890+
print $self->redirect(
891+
-location => Bugzilla->localconfig->{basepath} . ($path || ''),
892+
-status => $is_perm ? '301 Moved Permanently' : '302 Found'
893+
);
894+
exit;
895+
}
896+
888897
sub url_is_attachment_base {
889898
my ($self, $id) = @_;
890899
return 0 if !use_attachbase() or !i_am_cgi();
@@ -1042,6 +1051,11 @@ instead of calling this directly.
10421051
10431052
Redirects from the current URL to one prefixed by the urlbase parameter.
10441053
1054+
=item C<base_redirect>
1055+
1056+
Redirects to the given path relative to the `basepath` parameter which is
1057+
typically the root (`/`).
1058+
10451059
=item C<set_dated_content_disp>
10461060
10471061
Sets an appropriate date-dependent value for the Content Disposition header

‎Bugzilla/MFA.pm‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ sub verify_token {
8989
my $event = get_token_extra_data($token);
9090
delete_token($token);
9191
if (!$event) {
92-
print Bugzilla->cgi->redirect('index.cgi');
93-
exit;
92+
Bugzilla->cgi->base_redirect();
9493
}
9594
return $event;
9695
}

‎Bugzilla/Search/Quicksearch.pm‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,8 @@ sub quicksearch {
282282
my $modified_query_string = $cgi->canonicalise_query(@params_to_strip);
283283

284284
if ($cgi->param('load')) {
285-
my $urlbase = Bugzilla->localconfig->{urlbase};
286-
287285
# Param 'load' asks us to display the query in the advanced search form.
288-
print $cgi->redirect(
289-
-uri => "${urlbase}query.cgi?format=advanced&amp;" . $modified_query_string);
286+
$cgi->base_redirect("query.cgi?format=advanced&$modified_query_string");
290287
}
291288

292289
# Otherwise, pass the modified query string to the caller.
@@ -333,9 +330,7 @@ sub _bug_numbers_only {
333330
if ($searchstring !~ /,/ && !i_am_webservice()) {
334331

335332
# Single bug number; shortcut to show_bug.cgi.
336-
print $cgi->redirect(
337-
-uri => Bugzilla->localconfig->{urlbase} . "show_bug.cgi?id=$searchstring");
338-
exit;
333+
$cgi->base_redirect("show_bug.cgi?id=$searchstring");
339334
}
340335
else {
341336
# List of bug numbers.

‎attachment.cgi‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ sub get_attachment {
266266
unless ($userid && $valid_token) {
267267

268268
# Not a valid token.
269-
print $cgi->redirect('-location' => Bugzilla->localconfig->{urlbase} . $path);
270-
exit;
269+
$cgi->base_redirect($path);
271270
}
272271

273272
# Change current user without creating cookies.
@@ -389,12 +388,10 @@ sub view {
389388
{do_redirect => \$do_redirect});
390389

391390
if ($do_redirect) {
392-
my $uri = URI->new(Bugzilla->localconfig->{urlbase} . 'attachment.cgi');
391+
my $uri = URI->new('attachment.cgi');
393392
$uri->query_param(id => $attachment->id);
394393
$uri->query_param(content_type => $contenttype) if $contenttype_override;
395-
396-
print $cgi->redirect('-location' => $uri);
397-
exit 0;
394+
$cgi->base_redirect($uri->as_string);
398395
}
399396

400397
# Don't send a charset header with attachments--they might not be UTF-8.

‎chart.cgi‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,8 @@ if (!Bugzilla->feature('new_charts')) {
6262
# Go back to query.cgi if we are adding a boolean chart parameter.
6363
if (grep(/^cmd-/, $cgi->param())) {
6464
my $params = $cgi->canonicalise_query("format", "ctype", "action");
65-
print $cgi->redirect("query.cgi?format="
66-
. $cgi->param('query_format')
67-
. ($params ? "&$params" : ""));
68-
exit;
65+
$cgi->base_redirect("query.cgi?format="
66+
. $cgi->param('query_format') . ($params ? "&$params" : ''));
6967
}
7068

7169
my $action = $cgi->param('action');
@@ -87,8 +85,7 @@ $action ||= "assemble";
8785
# Go to buglist.cgi if we are doing a search.
8886
if ($action eq "search") {
8987
my $params = $cgi->canonicalise_query("format", "ctype", "action");
90-
print $cgi->redirect("buglist.cgi" . ($params ? "?$params" : ""));
91-
exit;
88+
$cgi->base_redirect('buglist.cgi' . ($params ? "?$params" : ""));
9289
}
9390

9491
$user->in_group(Bugzilla->params->{"chartgroup"}) || ThrowUserError(
@@ -224,11 +221,9 @@ elsif ($action eq "convert_search") {
224221
my $params = new Bugzilla::CGI($query->edit_link);
225222

226223
# These two parameters conflict with the one below.
227-
$url = $params->canonicalise_query('format', 'query_format');
228-
$url = '&amp;' . html_quote($url);
224+
$url = '&' . $params->canonicalise_query('format', 'query_format');
229225
}
230-
print $cgi->redirect(-location => Bugzilla->localconfig->{urlbase}
231-
. "query.cgi?format=create-series$url");
226+
$cgi->base_redirect("query.cgi?format=create-series$url");
232227
}
233228
else {
234229
ThrowUserError('unknown_action', {action => $action});

‎colchange.cgi‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,7 @@ if (defined $cgi->param('rememberedquery')) {
139139

140140
my $params = new Bugzilla::CGI($cgi->param('rememberedquery'));
141141
$params->param('columnlist', join(",", @collist));
142-
$vars->{'redirect_url'} = "buglist.cgi?" . $params->query_string();
143-
144-
# If we're running on Microsoft IIS, $cgi->redirect discards
145-
# the Set-Cookie lines. In mod_perl, $cgi->redirect with cookies
146-
# causes the page to be rendered as text/plain.
147-
# Workaround is to use the old-fashioned redirection mechanism.
148-
# See bug 214466 and bug 376044 for details.
149-
print $cgi->redirect($vars->{'redirect_url'});
150-
exit;
142+
$cgi->base_redirect('buglist.cgi?' . $params->query_string());
151143
}
152144

153145
if (defined $cgi->param('columnlist')) {

‎extensions/BMO/Extension.pm‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ sub page_before_template {
230230
Bugzilla::Extension::BMO::Reports::Internship::report($vars);
231231
}
232232
elsif ($page eq 'email_queue.html') {
233-
print Bugzilla->cgi->redirect('view_job_queue.cgi');
233+
Bugzilla->cgi->base_redirect('view_job_queue.cgi');
234234
}
235235
elsif ($page eq 'release_tracking_report.html') {
236236
require Bugzilla::Extension::BMO::Reports::ReleaseTracking;
@@ -305,8 +305,7 @@ sub bounty_attachment {
305305

306306
Bugzilla::BugMail::Send($bug->id, {changer => $user});
307307

308-
print Bugzilla->cgi->redirect('show_bug.cgi?id=' . $bug->id);
309-
exit;
308+
Bugzilla->cgi->base_redirect('show_bug.cgi?id=' . $bug->id);
310309
}
311310

312311
if ($attachment) {

‎extensions/BMO/lib/Reports/Groups.pm‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ sub membership_report {
8484
my $who = $cgi->param('who');
8585
if (!defined($who) || $who eq '') {
8686
if ($page eq 'group_membership.txt') {
87-
print $cgi->redirect("page.cgi?id=group_membership.html&output=txt");
88-
exit;
87+
$cgi->base_redirect('page.cgi?id=group_membership.html&output=txt');
8988
}
9089
$vars->{'output'} = $cgi->param('output');
9190
return;

0 commit comments

Comments
 (0)