Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] password_security: update password_write_date on copy #713

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion password_security/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
class PasswordSecurityHome(AuthSignupHome):
def do_signup(self, qcontext):
password = qcontext.get("password")
user = request.env.user
user = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the commit and the description mention the change in the copy

But this change is not mentioned

Also the title mention "...password_write_date on copy"

Could you elaborate how this search affects the purpose of this PR, please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am open to separate this in two PRs. Conceptually they are different fixes but in practice they are both needed.

The case is when a user has 2FA activated. If that is the case, they get to this method as the public user, so the check in user._check_password(password) does not detect the use of an old password. This makes the write method run which in turn updates password_write_date. Only after then, a second call to _check_password rejects the change.

However, since password_write_date is not updated to today, the user is able to log in with the old (expired) password and use it for a long time after that.

BTW: I updated the PR description to match the commit message.

request.env.user.search([("login", "=", qcontext.get("login"))])
or request.env.user
)
user._check_password(password)
return super(PasswordSecurityHome, self).do_signup(qcontext)

Expand Down
5 changes: 5 additions & 0 deletions password_security/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def write(self, vals):
vals["password_write_date"] = fields.Datetime.now()
return super(ResUsers, self).write(vals)

def copy(self, vals):
if vals.get("password"):
vals["password_write_date"] = fields.Datetime.now()
return super(ResUsers, self).copy(vals)

@api.model
def get_password_policy(self):
data = super(ResUsers, self).get_password_policy()
Expand Down
4 changes: 3 additions & 1 deletion password_security/tests/test_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from unittest import mock

from freezegun import freeze_time
from requests.exceptions import HTTPError

from odoo import http
Expand Down Expand Up @@ -82,7 +83,8 @@ def test_03_create_user_signup(self):

# Stronger password: no error raised
vals["password"] = "asdQWE12345_3"
login, pwd = self.env["res.users"].signup(vals)
with freeze_time("2020-01-01"):
login, pwd = self.env["res.users"].signup(vals)

# check created user
created_user = self.env["res.users"].search([("login", "=", "test_user")])
Expand Down
Loading