RSS

trunk : 6126

dkl%redhat.com
2008-07-10 04:56:11
Revision ID: cvs-1:dklredhat.com-20080710095611-h9gp7599q5ksxkcs
Bug 428659 â€“ Setting SSL param to 'authenticated sessions' only protects logins and param doesn't protect WebService calls at all Patch by Dave Lawrence <dkl@redhat.com> - r/a=mkanat

collapse all collapse all

added added

removed removed

66
    }
66
    }
67
 
67
 
68
    # Redirect to SSL if required
68
    # Redirect to SSL if required
69
    if (Bugzilla->params->{'sslbase'} ne '' 
69
    Bugzilla->cgi->require_https(Bugzilla->params->{'sslbase'})
70
        and Bugzilla->params->{'ssl'} ne 'never') 
70
        if ssl_require_redirect();
71
    {
71
 
72
        $cgi->require_https(Bugzilla->params->{'sslbase'});
 
 
73
    }
 
 
74
    print $cgi->header();
72
    print $cgi->header();
75
    $template->process("account/auth/login.html.tmpl",
73
    $template->process("account/auth/login.html.tmpl",
76
                       { 'target' => $cgi->url(-relative=>1) }) 
74
                       { 'target' => $cgi->url(-relative=>1) }) 
72
    $self->charset(Bugzilla->params->{'utf8'} ? 'UTF-8' : '');
72
    $self->charset(Bugzilla->params->{'utf8'} ? 'UTF-8' : '');
73
 
73
 
74
    # Redirect to SSL if required
74
    # Redirect to SSL if required
75
    if (Bugzilla->params->{'sslbase'} ne ''
75
    if (i_am_cgi() && Bugzilla->usage_mode != USAGE_MODE_WEBSERVICE 
76
        && Bugzilla->params->{'ssl'} eq 'always'
76
        && ssl_require_redirect()) 
77
        && i_am_cgi())
 
 
78
    {
77
    {
79
        $self->require_https(Bugzilla->params->{'sslbase'});
78
        $self->require_https(Bugzilla->params->{'sslbase'});
80
    }
79
    }
297
 
296
 
298
# Redirect to https if required
297
# Redirect to https if required
299
sub require_https {
298
sub require_https {
300
    my $self = shift;
299
    my ($self, $url) = @_;
301
    if ($self->protocol ne 'https') {
300
    # Do not create query string if data submitted via XMLRPC
302
        my $url = shift;
301
    my $query = Bugzilla->usage_mode == USAGE_MODE_WEBSERVICE ? 0 : 1;
303
        if (defined $url) {
302
    # XMLRPC clients (SOAP::Lite at least) requires 301 to redirect properly
304
            $url .= $self->url('-path_info' => 1, '-query' => 1, '-relative' => 1);
303
    my $status = Bugzilla->usage_mode == USAGE_MODE_WEBSERVICE ? 301 : 302;
305
        } else {
304
    if (defined $url) {
306
            $url = $self->self_url;
305
        $url .= $self->url('-path_info' => 1, '-query' => $query, '-relative' => 1);
307
            $url =~ s/^http:/https:/i;
306
    } else {
308
        }
307
        $url = $self->self_url;
309
        print $self->redirect(-location => $url);
308
        $url =~ s/^http:/https:/i;
310
        exit;
 
 
311
    }
309
    }
 
 
310
    print $self->redirect(-location => $url, -status => $status). "\n";
 
 
311
    exit;
312
}
312
}
313
 
313
 
314
1;
314
1;
378
This routine checks if the current page is being served over https, and
378
This routine checks if the current page is being served over https, and
379
redirects to the https protocol if required, retaining QUERY_STRING.
379
redirects to the https protocol if required, retaining QUERY_STRING.
380
 
380
 
381
It takes an option argument which will be used as the base URL.  If $baseurl
381
It takes an optional argument which will be used as the base URL.  If $baseurl
382
is not provided, the current URL is used.
382
is not provided, the current URL is used.
383
 
383
 
384
=back
384
=back
36
                             html_quote url_quote xml_quote
36
                             html_quote url_quote xml_quote
37
                             css_class_quote html_light_quote url_decode
37
                             css_class_quote html_light_quote url_decode
38
                             i_am_cgi get_netaddr correct_urlbase
38
                             i_am_cgi get_netaddr correct_urlbase
39
                             lsearch
39
                             lsearch ssl_require_redirect
40
                             diff_arrays diff_strings
40
                             diff_arrays diff_strings
41
                             trim wrap_hard wrap_comment find_wrap_point
41
                             trim wrap_hard wrap_comment find_wrap_point
42
                             format_time format_time_decimal validate_date
42
                             format_time format_time_decimal validate_date
218
    return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0;
218
    return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0;
219
}
219
}
220
 
220
 
 
 
221
sub ssl_require_redirect {
 
 
222
    my $method = shift;
 
 
223
 
 
 
224
    # Redirect to SSL if required.
 
 
225
    if (!(uc($ENV{HTTPS}) eq 'ON' || $ENV{'SERVER_PORT'} == 443)
 
 
226
        && Bugzilla->params->{'sslbase'} ne '') 
 
 
227
    {
 
 
228
        if (Bugzilla->params->{'ssl'} eq 'always'
 
 
229
            || (Bugzilla->params->{'ssl'} eq 'authenticated sessions'
 
 
230
                && Bugzilla->user->id)
 
 
231
            || (Bugzilla->params->{'ssl'} eq 'authenticated sessions'
 
 
232
                && !Bugzilla->user->id && $method eq 'User.login')) 
 
 
233
        {
 
 
234
            return 1;
 
 
235
        }
 
 
236
    }
 
 
237
 
 
 
238
    return 0;
 
 
239
}
 
 
240
 
221
sub correct_urlbase {
241
sub correct_urlbase {
222
    my $ssl = Bugzilla->params->{'ssl'};
242
    my $ssl = Bugzilla->params->{'ssl'};
223
    return Bugzilla->params->{'urlbase'} if $ssl eq 'never';
243
    return Bugzilla->params->{'urlbase'} if $ssl eq 'never';
19
 
19
 
20
use strict;
20
use strict;
21
use Bugzilla::WebService::Constants;
21
use Bugzilla::WebService::Constants;
 
 
22
use Bugzilla::Util;
22
use Date::Parse;
23
use Date::Parse;
23
use XMLRPC::Lite;
24
use XMLRPC::Lite;
24
 
25
 
54
    return;
55
    return;
55
}
56
}
56
 
57
 
 
 
58
sub handle_redirect {
 
 
59
    my ($action, $uri, $method) = @_;
 
 
60
    my $full_method = $uri . "." . $method;
 
 
61
 
 
 
62
    # Redirect to SSL if required.
 
 
63
    Bugzilla->cgi->require_https(Bugzilla->params->{'sslbase'})
 
 
64
        if ssl_require_redirect($full_method);
 
 
65
}
 
 
66
 
57
# For some methods, we shouldn't call Bugzilla->login before we call them
67
# For some methods, we shouldn't call Bugzilla->login before we call them
58
use constant LOGIN_EXEMPT => { };
68
use constant LOGIN_EXEMPT => { };
59
 
69
 
35
use Bugzilla::Constants;
35
use Bugzilla::Constants;
36
use Bugzilla::Error;
36
use Bugzilla::Error;
37
use Bugzilla::Update;
37
use Bugzilla::Update;
 
 
38
use Bugzilla::Util;
38
 
39
 
39
# Check whether or not the user is logged in
40
# Check whether or not the user is logged in
40
my $user = Bugzilla->login(LOGIN_OPTIONAL);
41
my $user = Bugzilla->login(LOGIN_OPTIONAL);
46
my $cgi = Bugzilla->cgi;
47
my $cgi = Bugzilla->cgi;
47
# Force to use HTTPS unless Bugzilla->params->{'ssl'} equals 'never'.
48
# Force to use HTTPS unless Bugzilla->params->{'ssl'} equals 'never'.
48
# This is required because the user may want to log in from here.
49
# This is required because the user may want to log in from here.
49
if (Bugzilla->params->{'sslbase'} ne '' and Bugzilla->params->{'ssl'} ne 'never') {
50
$cgi->require_https(Bugzilla->params->{'sslbase'}) 
50
    $cgi->require_https(Bugzilla->params->{'sslbase'});
51
    if ssl_require_redirect();
51
}
 
 
52
 
52
 
53
my $template = Bugzilla->template;
53
my $template = Bugzilla->template;
54
my $vars = {};
54
my $vars = {};
347
    $vars->{'date'} = str2time($date);
347
    $vars->{'date'} = str2time($date);
348
 
348
 
349
    # We require a HTTPS connection if possible.
349
    # We require a HTTPS connection if possible.
350
    if (Bugzilla->params->{'sslbase'} ne ''
350
    Bugzilla->cgi->require_https(Bugzilla->params->{'sslbase'}) 
351
        && Bugzilla->params->{'ssl'} ne 'never')
351
        if ssl_require_redirect();
352
    {
352
 
353
        $cgi->require_https(Bugzilla->params->{'sslbase'});
 
 
354
    }
 
 
355
    print $cgi->header();
353
    print $cgi->header();
356
 
354
 
357
    $template->process('account/email/confirm-new.html.tmpl', $vars)
355
    $template->process('account/email/confirm-new.html.tmpl', $vars)
53
 
53
 
54
my $response = Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI
54
my $response = Bugzilla::WebService::XMLRPC::Transport::HTTP::CGI
55
    ->dispatch_with($dispatch)
55
    ->dispatch_with($dispatch)
56
    ->on_action(sub { Bugzilla::WebService::handle_login($dispatch, @_) } )
56
    ->on_action(sub { 
 
 
57
                    my ($action, $uri, $method) = @_;
 
 
58
                    Bugzilla::WebService::handle_login($dispatch, @_);
 
 
59
                    Bugzilla::WebService::handle_redirect(@_);
 
 
60
                } )
57
    ->handle;
61
    ->handle;

Loggerhead runs on Bazaar branches