pypi django-tenants 4.0.4

4 days ago

Security release

This release fixes a vulnerability that let a tenant take over an existing
schema that isn't a tenant's (GHSA-492h-rq3v-xf2h, high). A tenant created with
the name of an existing schema -- another application's schema, a
PG_EXTRA_SEARCH_PATHS schema, or information_schema -- silently used that
schema: it could read and write its tables, and deleting the tenant with
auto_drop_schema dropped it. Applications that let an untrusted user influence
a tenant's schema_name could be exploited.

Affected: all versions before 4.0.4. All users should upgrade.

See the advisory for full details, impact and mitigations:
GHSA-492h-rq3v-xf2h

New setting

If users can choose or influence schema names, set
TENANT_REJECT_EXISTING_SCHEMA = True.
It rejects any schema name that
already exists in the database (compared ignoring case). It is off by default
so that tenants can still be created for existing schemas on purpose, for
example ones restored from a backup. See the new "Letting users choose schema
names" section of the security docs.

Upgrade notes

  • information_schema and the schemas in PG_EXTRA_SEARCH_PATHS are reserved:
    a tenant cannot be created with, or renamed to, one of these names, and they
    are never dropped through a tenant. Nor is the public schema: deleting the
    public tenant, or any tenant with one of these names, with force_drop or
    auto_drop_schema (as delete_tenant does) raises ValidationError and
    deletes nothing. To delete only such a row, set auto_drop_schema = False
    on the instance and delete it without force_drop. Keep the public schema
    name out of user-chosen names.
  • If creating a tenant fails after it was given a schema that already existed,
    the cleanup now removes only the tenant's row and keeps the schema. Before,
    it dropped the schema.
  • The case-insensitive uniqueness check on schema names now also runs when a
    save changes a tenant's schema_name, including a change of case to its own
    name. Saves that don't change the schema name are unaffected.

Don't miss a new django-tenants release

NewReleases is sending notifications on new releases.