Skip to content

Commit

Permalink
web: fix CSRF vulnerability in edit passwd function
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpanderson authored and lfield committed Dec 13, 2024
1 parent 743e6f3 commit f2f305f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion html/inc/account.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function make_login_token($user) {
$user->update("login_token_time=$now");
return $user->login_token;
}
$token = substr(random_string(), 0, 8);
$token = substr(random_string(), 0, 16);
$user->update("login_token='$token', login_token_time=$now");
return $token;
}
Expand Down
9 changes: 8 additions & 1 deletion html/user/edit_passwd_action.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@
check_get_args(array());

$user = get_logged_in_user();
$email_addr = strtolower(post_str("email_addr", true));

$token = post_str("token");
if ($token != $user->login_token) {
error_page("bad token");
}
if (time() - $user->login_token_time > 86400) {
error_page("expired token");
}

$passwd = post_str("passwd");

Expand Down
11 changes: 10 additions & 1 deletion html/user/edit_passwd_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@

page_head(tra("Change password"));


form_start(secure_url_base()."edit_passwd_action.php", "post");
form_input_text(tra("New password"), "passwd", "", "password",'id="passwd"',passwd_visible_checkbox("passwd"));
form_input_hidden('token', make_login_token($user));
form_input_text(tra(
"New password"),
"passwd",
"",
"password",
'id="passwd"',
passwd_visible_checkbox("passwd")
);
form_submit(tra("Change password"));
form_end();
page_tail();
Expand Down

0 comments on commit f2f305f

Please sign in to comment.