mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 20:26:48 +00:00
Every upstream release and this fork's up to v2.0.0 created the first user as admin/admin. The first-login password change only covered the password the panel generates itself (data/admin_password), so an upgraded installation whose admin never changed the default kept a working admin/admin login with no prompt, on the pages and through API tokens. Migration accounts.0013 marks a user named admin whose password is "admin" with must_change_password: the next login goes to the password change form, and the API refuses the user's tokens until then. Only that one name is checked, so the migration hashes one password at most. Found by upgrading an installation of the upstream release of September 2026 (installer and Docker) to this version: admin/admin still signed in.
19 lines
936 B
Python
19 lines
936 B
Python
from django.conf import settings
|
|
from django.contrib.auth.hashers import check_password
|
|
from django.db import migrations
|
|
|
|
|
|
def flag_default_admin_password(apps, schema_editor):
|
|
"""Versions up to v2.0.0 created the first user as admin/admin. An
|
|
installation that never changed it must replace it at the next login."""
|
|
alias = schema_editor.connection.alias
|
|
User = apps.get_model(*settings.AUTH_USER_MODEL.split("."))
|
|
Attributes = apps.get_model("accounts", "UserAttributes")
|
|
for user in User.objects.using(alias).filter(username="admin"):
|
|
if check_password("admin", user.password):
|
|
Attributes.objects.using(alias).update_or_create(user_id=user.pk, defaults={"must_change_password": True})
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [("accounts", "0012_user_instance_constraint")]
|
|
operations = [migrations.RunPython(flag_default_admin_password, migrations.RunPython.noop)]
|