Skip to content

Generate temporary passwords with the secrets module - #2855

Merged
nhoening merged 2 commits into
FlexMeasures:mainfrom
joyshmitz:fix/secrets-temporary-password
Nov 10, 2026
Merged

nhoening merged 2 commits into
FlexMeasures:mainfrom
joyshmitz:fix/secrets-temporary-password

Conversation

@joyshmitz

Copy link
Copy Markdown
Collaborator

Description

  • set_random_password draws the temporary password with secrets.choice instead of random.choice
  • Added a test
  • Added changelog item in documentation/changelog.rst

That password is the real password of a newly created user, and of a user whose password is reset, until they choose their own through the emailed link. As written in #2854, I found no way to predict it today, so this is hardening and not the fix of a vulnerability.

Look & Feel

Nothing changes for users: the password is still 24 lowercase letters, and it is still never shown or mailed.

How to test

pytest flexmeasures/data/tests/test_user_services.py::test_random_password_does_not_come_from_the_random_module

The test seeds the random module with the same value twice and expects two different passwords. With random.choice put back it fails, because both passwords are then the same.

The full suite gives 3463 passed and 7 failed on my machine. Those seven are the same ones that fail for me on the unchanged branch of #2849, as listed in #2853 (sorting by name under a C.UTF-8 collation, test_numerical_errors[cbc], test_closest_sensor).

Further Improvements

None.

Related Items

Closes #2854


Sign-off

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on code under GPL or other license that is incompatible with FlexMeasures

set_random_password drew the password of a newly created user, and of a user whose password is reset, from the random module, which is not meant for security purposes. That password is the user's real password until they choose their own.

Closes FlexMeasures#2854

Signed-off-by: Serhii <jshmitz@me.com>
Signed-off-by: Serhii <jshmitz@me.com>
@nhoening nhoening added this to the 1.2.0 milestone Nov 10, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 flexmeasures | 🛠️ Build #35788227 | 📁 Comparing d0d7c23 against latest (027a2c9)

  🔍 Preview build  

2 files changed
± changelog.html
± api/v3_0.html

@nhoening nhoening 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.

Thanks!

@nhoening
nhoening merged commit e39d983 into FlexMeasures:main Nov 10, 2026
8 checks passed
@joyshmitz
joyshmitz deleted the fix/secrets-temporary-password branch November 10, 2026 17:41
@Flix6x Flix6x modified the milestones: 1.2.0, 1.1.1 Nov 11, 2026
Flix6x added a commit that referenced this pull request Nov 11, 2026
The v1.1.1 patch release backports #2855, #2861, #2838, #2829, #2851, #2845, #2859, #2850 and #2860 to the 1.1.x branch.
Move their changelog bullets out of the v1.2.0 section into a new v1.1.1 section, worded and ordered as on 1.1.x,
so the same fixes are not listed as unreleased once 1.1.1 ships.
The bullet for #2861 takes the 1.1.x wording, which adds that Python 3.10 keeps the earlier Pillow, dnspython and filelock.
The API change log needs no split: v3.0-35 holds only #2859, which ships in v1.1.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Flix6x added a commit that referenced this pull request Nov 11, 2026
…le (#2855)

(cherry picked from commit e39d983, leaving out its changelog entry)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Flix6x added a commit that referenced this pull request Nov 11, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate the temporary password of a new or reset user with the secrets module

3 participants