Commit feeccb6a authored by Dave Lawrence's avatar Dave Lawrence

Bug 917669 - invalid or expired authentication tokens and cookies should throw…

Bug 917669 - invalid or expired authentication tokens and cookies should throw errors, not be silently ignored r/a=glob
parent 18637452
...@@ -14,6 +14,7 @@ use parent qw(Bugzilla::Auth::Login); ...@@ -14,6 +14,7 @@ use parent qw(Bugzilla::Auth::Login);
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Util; use Bugzilla::Util;
use Bugzilla::Error;
use List::Util qw(first); use List::Util qw(first);
...@@ -73,7 +74,9 @@ sub get_login_info { ...@@ -73,7 +74,9 @@ sub get_login_info {
AND (ipaddr = ? OR ipaddr IS NULL)', AND (ipaddr = ? OR ipaddr IS NULL)',
undef, ($login_cookie, $user_id, $ip_addr)); undef, ($login_cookie, $user_id, $ip_addr));
# If the cookie is valid, return a valid username. # If the cookie or token is valid, return a valid username.
# If they were not valid and we are using a webservice, then
# throw an error notifying the client.
if ($is_valid) { if ($is_valid) {
# If we logged in successfully, then update the lastused # If we logged in successfully, then update the lastused
# time on the login cookie # time on the login cookie
...@@ -81,12 +84,16 @@ sub get_login_info { ...@@ -81,12 +84,16 @@ sub get_login_info {
WHERE cookie = ?", undef, $login_cookie); WHERE cookie = ?", undef, $login_cookie);
return { user_id => $user_id }; return { user_id => $user_id };
} }
elsif (i_am_webservice()) {
ThrowUserError('invalid_cookies_or_token');
}
} }
# Either the he cookie is invalid, or we got no cookie. We don't want # Either the cookie or token is invalid and we are not authenticating
# to ever return AUTH_LOGINFAILED, because we don't want Bugzilla to # via a webservice, or we did not receive a cookie or token. We don't
# actually throw an error when it gets a bad cookie. It should just # want to ever return AUTH_LOGINFAILED, because we don't want Bugzilla to
# look like there was no cookie to begin with. # actually throw an error when it gets a bad cookie or token. It should just
# look like there was no cookie or token to begin with.
return { failure => AUTH_NODATA }; return { failure => AUTH_NODATA };
} }
...@@ -97,9 +104,7 @@ sub login_token { ...@@ -97,9 +104,7 @@ sub login_token {
return $self->{'_login_token'} if exists $self->{'_login_token'}; return $self->{'_login_token'} if exists $self->{'_login_token'};
if ($usage_mode ne USAGE_MODE_XMLRPC if (!i_am_webservice()) {
&& $usage_mode ne USAGE_MODE_JSON
&& $usage_mode ne USAGE_MODE_REST) {
return $self->{'_login_token'} = undef; return $self->{'_login_token'} = undef;
} }
......
...@@ -837,10 +837,7 @@ sub create { ...@@ -837,10 +837,7 @@ sub create {
# (Wrapping the message in the WebService is unnecessary # (Wrapping the message in the WebService is unnecessary
# and causes awkward things like \n's appearing in error # and causes awkward things like \n's appearing in error
# messages in JSON-RPC.) # messages in JSON-RPC.)
unless (Bugzilla->usage_mode == USAGE_MODE_JSON unless (i_am_webservice()) {
or Bugzilla->usage_mode == USAGE_MODE_XMLRPC
or Bugzilla->usage_mode == USAGE_MODE_REST)
{
$var = wrap_comment($var, 72); $var = wrap_comment($var, 72);
} }
$var =~ s/\ / /g; $var =~ s/\ / /g;
......
...@@ -14,8 +14,8 @@ use parent qw(Exporter); ...@@ -14,8 +14,8 @@ use parent qw(Exporter);
@Bugzilla::Util::EXPORT = qw(trick_taint detaint_natural detaint_signed @Bugzilla::Util::EXPORT = qw(trick_taint detaint_natural detaint_signed
html_quote url_quote xml_quote html_quote url_quote xml_quote
css_class_quote html_light_quote css_class_quote html_light_quote
i_am_cgi correct_urlbase remote_ip validate_ip i_am_cgi i_am_webservice correct_urlbase remote_ip
do_ssl_redirect_if_required use_attachbase validate_ip do_ssl_redirect_if_required use_attachbase
diff_arrays on_main_db diff_arrays on_main_db
trim wrap_hard wrap_comment find_wrap_point trim wrap_hard wrap_comment find_wrap_point
format_time validate_date validate_time datetime_from format_time validate_date validate_time datetime_from
...@@ -237,6 +237,13 @@ sub i_am_cgi { ...@@ -237,6 +237,13 @@ sub i_am_cgi {
return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0; return exists $ENV{'SERVER_SOFTWARE'} ? 1 : 0;
} }
sub i_am_webservice {
my $usage_mode = Bugzilla->usage_mode;
return $usage_mode == USAGE_MODE_XMLRPC
|| $usage_mode == USAGE_MODE_JSON
|| $usage_mode == USAGE_MODE_REST;
}
# This exists as a separate function from Bugzilla::CGI::redirect_to_https # This exists as a separate function from Bugzilla::CGI::redirect_to_https
# because we don't want to create a CGI object during XML-RPC calls # because we don't want to create a CGI object during XML-RPC calls
# (doing so can mess up XML-RPC). # (doing so can mess up XML-RPC).
...@@ -847,6 +854,7 @@ Bugzilla::Util - Generic utility functions for bugzilla ...@@ -847,6 +854,7 @@ Bugzilla::Util - Generic utility functions for bugzilla
# Functions that tell you about your environment # Functions that tell you about your environment
my $is_cgi = i_am_cgi(); my $is_cgi = i_am_cgi();
my $is_webservice = i_am_webservice();
my $urlbase = correct_urlbase(); my $urlbase = correct_urlbase();
# Data manipulation # Data manipulation
...@@ -974,6 +982,11 @@ Tells you whether or not you are being run as a CGI script in a web ...@@ -974,6 +982,11 @@ Tells you whether or not you are being run as a CGI script in a web
server. For example, it would return false if the caller is running server. For example, it would return false if the caller is running
in a command-line script. in a command-line script.
=item C<i_am_webservice()>
Tells you whether or not the current usage mode is WebServices related
such as JSONRPC, XMLRPC, or REST.
=item C<correct_urlbase()> =item C<correct_urlbase()>
Returns either the C<sslbase> or C<urlbase> parameter, depending on the Returns either the C<sslbase> or C<urlbase> parameter, depending on the
......
...@@ -181,6 +181,13 @@ For REST, you may also use the C<username> and C<password> variable ...@@ -181,6 +181,13 @@ For REST, you may also use the C<username> and C<password> variable
names instead of C<Bugzilla_login> and C<Bugzilla_password> as a names instead of C<Bugzilla_login> and C<Bugzilla_password> as a
convenience. convenience.
=item B<Added in Bugzilla 5.0>
An error is now thrown if you pass invalid cookies or an invalid token.
You will need to log in again to get new cookies or a new token. Previous
releases simply ignored invalid cookies and token support was added in
Bugzilla B<5.0>.
=back =back
=head1 STABLE, EXPERIMENTAL, and UNSTABLE =head1 STABLE, EXPERIMENTAL, and UNSTABLE
......
...@@ -1054,6 +1054,11 @@ ...@@ -1054,6 +1054,11 @@
the "Forgot Password" link. the "Forgot Password" link.
[% END %] [% END %]
[% ELSIF error == "invalid_cookies_or_token" %]
[% title = "Invalid Cookies or Token" %]
The cookies or token provide were not valid or have expired.
You may login again to get new cookies or a new token.
[% ELSIF error == "json_rpc_get_method_required" %] [% ELSIF error == "json_rpc_get_method_required" %]
When using JSON-RPC over GET, you must specify a 'method' When using JSON-RPC over GET, you must specify a 'method'
parameter. See the documentation at parameter. See the documentation at
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment