← Back to Pull requests

Mask account numbers and IBANs wherever they are shown #4339

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 20, 2026 09:31 UTC
Author

<!-- claude-projects-attribution: {"github_login":"gfr-free"} -->
_Requested by User_

Summary

Before: Several providers still showed full bank or brokerage account numbers and IBANs. Setup screens printed them (Indexa Capital, Fio, Interactive Brokers, Trade Republic, Trading 212, Akahu). Questrade, Indexa Capital, Fio, Interactive Brokers, Trade Republic and Trading 212 built them into default account names such as "TFSA (12345678)", so the full number reached account lists, reports, CSV exports, the API and the assistant. Transaction "Additional details" dumped counterparty IBANs and account numbers as raw JSON (Monobank, Fio, Akahu), Akahu wrote the counterparty account into every transaction's notes, and Mercury wrote its details object (counterparty account and routing numbers, IBAN) into notes as a Ruby hash string.

After: Every one of those places shows only the last 4 characters, e.g. •••5678. Existing account names that still contain the full number are rewritten by a data migration; anything a user wrote around the number is kept.

This is the follow-up to the shared mask_last4 helper (#3826). It implements the remaining items of that privacy series (Indexa, Questrade, Monobank) plus the reuse candidates and boundary note from the maintainer's audit comment on #3826, extended by a provider-by-provider audit of all 25 sync integrations.

Changes

  • IdentifierMask (app/models/identifier_mask.rb): one masking rule for helpers and models. ApplicationHelper#mask_last4 delegates to it. Sophtron (keeps its stored *1234 format) and the Trade Republic connection card (strip spaces, hide values under 4 characters) reuse it with their own options.

  • Setup and linking screens use mask_last4: Enable Banking, Lunch Flow, Indexa Capital, Plaid (incl. the duplicate warning), Akahu, Fio (3 views + settings panel, bank code kept), Interactive Brokers, Trade Republic, Trading 212.

  • Generated account names use the masked number: Questrade, Indexa Capital, Fio, Interactive Brokers (IbkrAccount.default_name, also used by the Flex report parser that previously named the record after the bare id), Trade Republic, Trading 212.

  • Data migration MaskAccountNumbersInGeneratedAccountNames: replaces the exact full number wherever it appears in a provider record's or linked account's name, and gives an IBKR provider record named after the bare number the default name. Renamed accounts without the number are untouched. It works in batches of 500 provider rows, joined to their linked accounts.

  • Additional details: IdentifierMask.mask_identifiers masks every value under identifier-like keys (iban, counter_iban, counter_edrpou, counter_account, other_account, account_number, routingNumber, sort_code, card_number, pan, ...), matched on the key's final words so counter_account_name, counter_account_type or account_number_last_4 stay readable. Applies to the raw dump and to SimpleFIN/Plaid structured rows. Fio's <account>/<bank> keeps the bank code.

  • Akahu: AkahuAccount#masked_account_number (dashes dropped before masking) is used by the setup views; notes keep only the last 4 digits of the counterparty account. Mercury notes only keep details when it is a plain string.

  • Data migration RemoveMercuryRoutingDetailsFromNotes: removes the trailing details hash (only when it starts with one of Mercury's details keys) from Mercury notes already stored and keeps the note in front of it. Notes the user edited (locked), or that change while the migration runs, are skipped. The details stay in the raw transactions payload.

  • Indexa Capital: stops reading and writing the duplicate account_number column (same value as indexa_capital_account_id, which every lookup already uses) via ignored_columns. The column itself stays, so workers on the previous release can still write it during a rolling deploy; a later release can drop it. The invalid-number error message is masked too.

  • Boundary documented and tested: values of 4 characters or fewer are shown in full (mask_last4("123") is •••123), so the helper is for identifiers only, never for secrets.
  • Deliberately unchanged, as the audit comment recommended: wallet address abbreviations, secret placeholders and the mobile money masker follow their own rules.

    Screenshots

    Indexa Capital setup (name and number):

    !Indexa setup before/after

    Transaction "Additional details" (Fio and Monobank counterparty, demo data):

    !Additional details before/after

    Effects on other processes

  • Balances, syncs, matching: none. Only display strings, generated names and Mercury notes change; lookups use the provider id columns, which keep the full value.

  • Account names: existing default names change once (migration), so exports, reports and API output show the masked form afterwards. Providers that rebuild names on sync (Questrade, Trade Republic) now produce the masked form.

  • Mercury notes: existing unlocked notes lose the details hash once (migration); later syncs keep them that way.

  • Rules: rules match accounts by id, not by name, so they are unaffected.

  • Related: DebugLogEntry encryption (#3833) stays separate.
  • Not covered

  • Free text supplied by the bank (payment references, descriptions) can itself contain an IBAN; that cannot be detected reliably.

  • Notes already stored by Akahu before this change are not rewritten, because the account number is mixed into free text users may have edited.

  • CoinSpot stores its raw deposit/withdrawal record in extra; no account number was confirmed there, and identifier-named keys would be masked anyway.
  • Tests

  • New tests: IdentifierMask, helper short-input boundary, extras masking (incl. nested values and look-alike keys), generated names per provider, both data migrations, Akahu notes, Mercury notes, IBKR report parser.

  • Full suite on the branch merged with current main: 12469 runs, 0 failures, 0 errors.

  • RuboCop, erb_lint and Brakeman clean. No JavaScript changes.
  • 🤖 Generated with Claude Code

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->

    Summary by CodeRabbit

  • Privacy

  • - Account and financial identifiers are now masked across account selection, setup, provider panels, transaction details, account names, validation messages, and duplicate-connection warnings.
    - Masking consistently preserves only the final four characters and handles formatted, nested, and provider-specific identifiers appropriately.

  • Bug Fixes

  • - Structured Mercury routing details are excluded from transaction notes while user-entered notes are preserved.
    - Account displays now use the correct masked values across supported providers.

  • Data Updates*

  • - Existing generated account names are updated to use masked identifiers.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: jjmata Review duration: 1117m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.388
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #4339"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.4% · Safe to merge
    30.4%