Django
Privacy rules for Django 4.2, 5.2, and 6.0 on MySQL, MariaDB, PostgreSQL, and SQLite
Covers the default django.contrib.auth user table, the database session table, and the admin log.
Coverage
- Versions: 4.2 LTS, 5.2 LTS, 6.0.
- Engines: MySQL, MariaDB, PostgreSQL, SQLite.
- Table prefix: the template assumes unprefixed table names. Django uses no table prefix; tables are named
<app_label>_<model>unlessMeta.db_tableoverrides it.
Template
privacy:
rules:
emails:
columns:
- auth_user.email
entity: EMAIL_ADDRESS
operator: hash
names:
columns:
- auth_user.username
- auth_user.first_name
- auth_user.last_name
entity: PERSON
operator: hash
passwords:
columns:
- auth_user.password
entity: PASSWORD_HASH
operator: redact
tokens:
columns:
- django_session.session_key
entity: AUTH_TOKEN
operator: redact
# Optional: mixed-content columns. Ruling them hides their non-personal content too; remove to keep it readable.
mixed-content:
columns:
- django_admin_log.object_repr
- django_admin_log.change_message
entity: MIXED_CONTENT
operator: replace
# Keep: mixed-content columns that hold credentials.
mixed-content-secrets:
columns:
- django_session.session_data
entity: MIXED_CONTENT
operator: redactChoices
django_sessionrules apply only with the database session engine (dborcached_db); cache and signed-cookie sessions store nothing in the database.- Optional parts: delete the
mixed-contentrule if the assistant needs those columns readable. django_session.session_datais signed but unencrypted JSON holding the user id and project data;django_admin_log.object_repris each edited object'sstr(), often a name.- With
AUTH_USER_MODEL, the user table is<app_label>_<model>(accounts.Usergivesaccounts_user); add its columns to the matching rules. Of these columns, anAbstractBaseUsersubclass has onlypassword.
Trade-offs
- Indexed ruled columns:
auth_user.username,django_session.session_key. - Lookups that stop working: finding a user by username or e-mail, sorting by name, matching a session to its key.
- Join keys that stay unruled:
idand everyuser_id, such asauth_user_groups.user_idanddjango_admin_log.user_id.
Not covered
django_admin_log.object_id: edited object's key, personal only for e-mail keys.- Third-party packages' tables: social login, API tokens, profiles.