Encrypt the remaining provider identifiers at rest #4336
All Vouch review confidence checks passed
Residual risk 0.38 = Change Risk (0.71) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.71 · 504 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.372
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.071
Real PR Conversation Timeline
1 comments
"Review active on #4336"
general
weight: 0.35
jjmata
Problem
Some provider fields still store personal data as plaintext in the database, even though the fields next to them are already encrypted:
enable_banking_items.last_psu_ip: the user's IP address. Enable Banking needs it for a while after login.akahu_accounts.formatted_account: the full New Zealand bank account number.akahu_accounts.institution_metadata: holds a second copy of that number and the account holder's name. No code reads either key.lunchflow_accounts.raw_holdings_payload: the brokerage holdings. The other Lunch Flow payloads are already encrypted.What changes
encrypts, inside the existingif encryption_ready?blocks. Nothing looks them up by value, so they use non-deterministic encryption.account_numberandholderintoinstitution_metadata. A migration removes both keys from existing rows. The number stays readable through the encryptedformatted_account, and both values remain in the encrypted raw payload.- Each attribute uses
support_unencrypted_data: true. A plaintext value stays readable instead of raisingActiveRecord::Encryption::Errors::Decryption. That covers rows from earlier syncs, rows written by a process still on the old code during a deploy, and instances that only configure keys later.- A migration also encrypts the plaintext already stored in these columns, so the data does not stay plaintext at rest until someone runs the backfill. It skips values that are already encrypted (string and jsonb columns), pages by id, and does nothing when encryption is not configured.
-
security:backfill_encryptionnow lists the new columns.Not included
enable_banking_accounts.iban: #3510 already encrypts it, deterministically, because the IBAN work looks it up. A secondencryptswith a different scheme here would leave the column unreadable once both land.transactions.extra: rules and search query that column.Tests
support_unencrypted_data, the backfill task on plaintext rows, both migrations, and the Akahu importer no longer writing account details into metadata.ACTIVE_RECORD_ENCRYPTION_*keys are set, and CI does not set them. I ran them locally with keys: they pass with the change and fail without it.bin/rails testpasses (12,442 runs). Rubocop and Brakeman are clean.<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
Summary by CodeRabbit
- Sensitive provider account identifiers and financial data are now encrypted at rest.
- Existing unencrypted records remain readable during migration, while new and backfilled data is encrypted.
- Akahu institution metadata no longer stores account numbers or account-holder names.
- Protected account details remain available through the appropriate account fields.
- Existing records are automatically updated to apply encryption and remove sensitive metadata without interrupting access.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->