summaryrefslogtreecommitdiffstats
path: root/relogin.cgi
diff options
context:
space:
mode:
authorDavid Lawrence <dkl@mozilla.com>2015-04-24 17:56:26 +0200
committerDavid Lawrence <dkl@mozilla.com>2015-04-24 17:56:26 +0200
commit283be21f66e638667bc2ec7720cab459ecf1f698 (patch)
treecdbfbb79d503373bb2058a96f369cf75542dbe3b /relogin.cgi
parented92da4fed393bb0f645f7bad022d49fed336a2f (diff)
downloadbugzilla-283be21f66e638667bc2ec7720cab459ecf1f698.tar.gz
bugzilla-283be21f66e638667bc2ec7720cab459ecf1f698.tar.xz
Bug 1157395: CSRF in log in form
Diffstat (limited to 'relogin.cgi')
-rwxr-xr-xrelogin.cgi18
1 files changed, 17 insertions, 1 deletions
diff --git a/relogin.cgi b/relogin.cgi
index 6eb798205..cfbb52b34 100755
--- a/relogin.cgi
+++ b/relogin.cgi
@@ -58,7 +58,7 @@ elsif ($action eq 'prepare-sudo') {
object => 'sudo_session' }
);
}
-
+
# Do not try to start a new session if one is already in progress!
if (defined(Bugzilla->sudoer)) {
ThrowUserError('sudo_in_progress', { target => $user->login });
@@ -67,6 +67,22 @@ elsif ($action eq 'prepare-sudo') {
# Keep a temporary record of the user visiting this page
$vars->{'token'} = issue_session_token('sudo_prepared');
+ if ($user->authorizer->can_login) {
+ my $value = generate_random_password();
+ my %args;
+ $args{'-secure'} = 1 if Bugzilla->params->{ssl_redirect};
+
+ $cgi->send_cookie(-name => 'Bugzilla_login_request_cookie',
+ -value => $value,
+ -httponly => 1,
+ %args);
+
+ # The user ID must not be set when generating the token, because
+ # that information will not be available when validating it.
+ local Bugzilla->user->{userid} = 0;
+ $vars->{'login_request_token'} = issue_hash_token(['login_request', $value]);
+ }
+
# Show the sudo page
$vars->{'target_login_default'} = $cgi->param('target_login');
$vars->{'reason_default'} = $cgi->param('reason');