Skip to content

[14.0][FIX] password_security: Correctly look at previous password history - #448

Closed
adekock11 wants to merge 1 commit into
OCA:14.0from
adekock11:patch-1
Closed

adekock11 wants to merge 1 commit into
OCA:14.0from
adekock11:patch-1

Conversation

@adekock11

Copy link
Copy Markdown

If a user has previous passwords stored and the password_history is set to 0 to disable the check, the line of code would evaluate to:

rec_id.password_history_ids[0:-1]

The above returns all items in the list except for the first last entry. One expects the above to evaluate to:

rec_id.password_history_ids[0:0]

The above returns an empty list which would then correctly not raise a warning.

If a user has previous passwords stored and the `password_history` is set to 0 to disable the check, the line of code would evaluate to:

```
rec_id.password_history_ids[0:-1]
```

The above returns all items in the list except for the first last entry. One expects the above to evaluate to:

```
rec_id.password_history_ids[0:0]
```

The above returns an empty list which would then correctly not raise a warning.
@sebalix sebalix added this to the 14.0 milestone Jan 17, 2023
@sebalix sebalix changed the title [FIX] password_security: Correctly look at previous password history [14.0][FIX] password_security: Correctly look at previous password history Jan 17, 2023

@ivantodorovich ivantodorovich left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I haven't tested, but I think you're correct, without this fix the number of history passwords to check is not computed properly, but I would expand it a little bit more to completely skip this check in case recent_passes == 0, and that would save us the read on password_history_ids.

if not recent_passes:    # disabled
    continue
elif recent_passes < 0:    # unlimited
    recent_passes = rec_id.password_history_ids
else:
    recent_passes = rec_id.password_history_ids[:recent_passes]

Unit tests to reproduce the bug you're fixing would be appreciated 🙏🏻 it's the best way to fight regressions

@astirpe astirpe mentioned this pull request Feb 20, 2023
7 tasks
@astirpe

astirpe commented Mar 3, 2023

Copy link
Copy Markdown
Member

Hi @adekock11, I think the proposal of @ivantodorovich is a nice one. Are you going to implement it and complete the tests?

@amh-mw amh-mw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@adekock11 For password_security/tests/test_res_users.py

    def test_check_password_history(self):
        # Disable all password checks except for history
        set_param = self.env['ir.config_parameter'].sudo().set_param
        set_param('auth_password_policy.minlength', 0)
        user = self.env.ref('base.user_admin')
        user.company_id.update({
            'password_estimate': 0,
            'password_length': 0,
            'password_lower': 0,
            'password_history': 1,
            'password_numeric': 0,
            'password_special': 0,
            'password_upper': 0,
        })

        self.assertEqual(len(user.password_history_ids), 0)

        user.write({'password': 'admin'})
        self.assertEqual(len(user.password_history_ids), 1)

        with self.assertRaises(UserError):
            user.write({'password': 'admin'})
        user.write({'password': 'admit'})
        self.assertEqual(len(user.password_history_ids), 2)

        user.company_id.password_history = 2
        with self.assertRaises(UserError):
            user.write({'password': 'admin'})
        with self.assertRaises(UserError):
            user.write({'password': 'admit'})
        user.write({'password': 'badminton'})
        self.assertEqual(len(user.password_history_ids), 3)

        user.company_id.password_history = 0
        user.write({'password': 'badminton'})
        self.assertEqual(len(user.password_history_ids), 4)

Edit: Added test for password_history = 0

@github-actions

github-actions Bot commented Jul 2, 2023

Copy link
Copy Markdown

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions Bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Jul 2, 2023
@github-actions github-actions Bot closed this Aug 6, 2023
SiesslPhillip pushed a commit to grueneerde/OCA-server-auth that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-auth (16.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale PR/Issue without recent activity, it'll be soon closed automatically.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants