Devise (Rails)
Privacy rules for Devise 4.9 and 5.0 on MySQL, MariaDB, PostgreSQL, and SQLite
Covers the e-mail addresses, password hash, tokens, and sign-in IPs on a Devise model's table, plus devise-two-factor secrets and Doorkeeper OAuth tokens.
Coverage
- Versions: Devise 4.9 and 5.0; devise-two-factor 5.x–6.4; Doorkeeper 5.9.
- Engines: MySQL, MariaDB, PostgreSQL, SQLite.
- Table prefix: the template assumes unprefixed table names. Devise uses no prefix; the model name sets the table (
rails generate devise Admincreatesadmins), so replaceusersif yours differs.
Template
privacy:
rules:
emails:
columns:
- users.email
- users.unconfirmed_email
entity: EMAIL_ADDRESS
operator: hash
ip-addresses:
columns:
- users.current_sign_in_ip
- users.last_sign_in_ip
entity: IP_ADDRESS
operator: hash
passwords:
columns:
- users.encrypted_password
# devise-two-factor (optional)
- users.otp_backup_codes
entity: PASSWORD_HASH
operator: redact
tokens:
columns:
- users.reset_password_token
- users.confirmation_token
- users.unlock_token
entity: AUTH_TOKEN
operator: redact
otp-secrets:
columns:
# devise-two-factor (optional)
- users.otp_secret
entity: OTP_SECRET
operator: redact
secrets:
columns:
# devise-two-factor (optional)
- users.encrypted_otp_secret
- users.encrypted_otp_secret_iv
- users.encrypted_otp_secret_salt
# Doorkeeper (optional)
- oauth_applications.secret
- oauth_access_grants.token
- oauth_access_grants.code_challenge
- oauth_access_tokens.token
- oauth_access_tokens.refresh_token
- oauth_access_tokens.previous_refresh_token
entity: API_KEY
operator: redactChoices
encrypted_passwordis a bcrypt hash despite its name;confirmation_tokenis stored in plain, and anyone holding it can confirm the account.unconfirmed_email,confirmation_token,unlock_token, and the IP columns exist only with:confirmable,:lockable, or:trackable.- Optional parts: delete the commented devise-two-factor and Doorkeeper columns if you do not run those gems. Installs upgraded from devise-two-factor 4.x keep the old
encrypted_otp_secret*columns. - Doorkeeper stores tokens and client secrets in plain unless
hash_token_secretsorhash_application_secretsis on; with theplainPKCE method,code_challengeis the verifier itself. - Each further Devise model has its own table with the same columns; add its columns, and profile columns such as
users.name, to the matching rules.
Trade-offs
- Indexed ruled columns:
users.email,users.reset_password_token;confirmation_tokenandunlock_tokenif you enabled their indexes; Doorkeeperoauth_access_grants.token,oauth_access_tokens.token,oauth_access_tokens.refresh_token. - Lookups that stop working: finding a user by e-mail, IP address, or token.
- Join keys that stay unruled:
idand foreign keys, such asusers.id, Doorkeeper'sresource_owner_id,application_id, andoauth_applications.uid.
Not covered
devise_invitable, OmniAuth,devise-securitycolumns: extension schemas not included.oauth_applications.name,redirect_uri,scopes: app metadata, not personal data.activerecord-session_storesessionstable: optional gem, not included.