pypi django-tenants 4.0.5

41 minutes ago

Security release

This release fixes two vulnerabilities in how django-tenants restores the
previous tenant when leaving schema_context(), tenant_context() or
with tenant:. In both, a connection could be left on another tenant, so
later queries read or wrote that tenant's data.

  • Context managers on a non-default database alias (GHSA-q7xr-949m-53qg,
    medium). With TENANT_DB_ALIAS or database=, schema_context() and
    tenant_context() restored the tenant of the default connection onto the
    alias they had switched. Only affects projects where both default and the
    other alias use the django-tenants backend. Reported by @zerox80.
  • Concurrent use of with tenant: and the decorator form
    (GHSA-8558-24hp-q3wq, medium). with tenant: kept the tenants to restore in
    a list shared by every thread, and @schema_context(...) /
    @tenant_context(...) kept them on one instance shared by every call. In
    threaded workers, overlapping uses could restore each other's tenant.

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

See the advisories for full details and workarounds.

Upgrade notes

  • All three context managers now keep the tenants to restore on a stack on
    the database connection (which is per thread). There is no change for code
    that uses them normally.
  • Subclasses of schema_context or tenant_context that override
    __enter__ or __exit__ must call super() in both, so the stack stays
    balanced.
  • The private class attribute TenantMixin._previous_tenant has been removed.

Don't miss a new django-tenants release

NewReleases is sending notifications on new releases.