Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Encrypt the Enable Banking account IBAN at rest (#5357)

GFRbdd3f9540aa4
diff --git a/app/models/enable_banking_account.rb b/app/models/enable_banking_account.rb
index b74e9d9644..03a4afb013 100644
--- a/app/models/enable_banking_account.rb
+++ b/app/models/enable_banking_account.rb
@@ -5,6 +5,9 @@ class EnableBankingAccount < ApplicationRecord
if encryption_ready?
encrypts :raw_payload
encrypts :raw_transactions_payload
+ # Not deterministic: the IBAN is never looked up by value, so equal IBANs
+ # need not share a ciphertext.
+ encrypts :iban
end
belongs_to :enable_banking_item
diff --git a/lib/active_record_encryption_config.rb b/lib/active_record_encryption_config.rb
index 8ff1483abf..a5751db0cb 100644
--- a/lib/active_record_encryption_config.rb
+++ b/lib/active_record_encryption_config.rb
@@ -70,7 +70,7 @@ module ActiveRecordEncryptionConfig
# older, narrower version back into "not complete" until they re-run the
# task - otherwise the legacy-plaintext fallback would get disabled for
# models the install's last backfill never actually covered.
- CURRENT_BACKFILL_VERSION = 10
+ CURRENT_BACKFILL_VERSION = 11
# Single source of truth for which models/fields security:backfill_encryption
# covers, keyed by the same symbol the task's `results` hash uses. Model
@@ -129,7 +129,7 @@ module ActiveRecordEncryptionConfig
plaid_accounts: [ "PlaidAccount", %i[raw_payload raw_transactions_payload raw_holdings_payload raw_liabilities_payload] ],
simplefin_accounts: [ "SimplefinAccount", %i[raw_payload raw_transactions_payload raw_holdings_payload] ],
lunchflow_accounts: [ "LunchflowAccount", %i[raw_payload raw_transactions_payload raw_holdings_payload] ],
- enable_banking_accounts: [ "EnableBankingAccount", %i[raw_payload raw_transactions_payload] ],
+ enable_banking_accounts: [ "EnableBankingAccount", %i[raw_payload raw_transactions_payload iban] ],
truelayer_accounts: [ "TruelayerAccount", %i[raw_payload raw_transactions_payload] ],
fio_accounts: [ "FioAccount", %i[raw_payload raw_transactions_payload iban] ],
snaptrade_accounts: [ "SnaptradeAccount", %i[raw_payload raw_transactions_payload raw_holdings_payload raw_activities_payload raw_balances_payload account_number] ],
diff --git a/test/lib/tasks/security_backfill_test.rb b/test/lib/tasks/security_backfill_test.rb
index c196619589..5134f44272 100644
--- a/test/lib/tasks/security_backfill_test.rb
+++ b/test/lib/tasks/security_backfill_test.rb
@@ -53,6 +53,7 @@ class SecurityBackfillTest < ActiveSupport::TestCase
eb_item = EnableBankingItem.create!(
family: families(:dylan_family), name: "Backfill EB", country_code: "FI", application_id: "app", client_certificate: "cert"
)
+ eb_account = EnableBankingAccount.create!(enable_banking_item: eb_item, name: "Checking", uid: "uid_backfill", currency: "EUR")
akahu_account = AkahuAccount.create!(
akahu_item: AkahuItem.create!(family: families(:dylan_family), name: "Backfill Akahu", app_token: "app", user_token: "user"),
name: "Everyday", account_id: "acc_backfill", currency: "NZD"
@@ -62,6 +63,8 @@ class SecurityBackfillTest < ActiveSupport::TestCase
connection = ActiveRecord::Base.connection
connection.execute(ActiveRecord::Base.sanitize_sql([
"UPDATE enable_banking_items SET last_psu_ip = ? WHERE id = ?", "203.0.113.7", eb_item.id ]))
+ connection.execute(ActiveRecord::Base.sanitize_sql([
+ "UPDATE enable_banking_accounts SET iban = ? WHERE id = ?", "FI2112345600000785", eb_account.id ])) # pipelock:ignore IBAN
connection.execute(ActiveRecord::Base.sanitize_sql([
"UPDATE akahu_accounts SET formatted_account = ? WHERE id = ?", "12-3456-7654321-00", akahu_account.id ]))
@@ -69,6 +72,8 @@ class SecurityBackfillTest < ActiveSupport::TestCase
assert_equal "203.0.113.7", eb_item.reload.last_psu_ip
assert_equal "12-3456-7654321-00", akahu_account.reload.formatted_account
+ assert_equal "FI2112345600000785", eb_account.reload.iban # pipelock:ignore IBAN
+ refute_includes eb_account.read_attribute_before_type_cast(:iban).to_s, "12345600000785"
refute_includes eb_item.read_attribute_before_type_cast(:last_psu_ip).to_s, "203.0.113.7"
refute_includes akahu_account.read_attribute_before_type_cast(:formatted_account).to_s, "7654321"
end
@@ -378,7 +383,8 @@ class SecurityBackfillTest < ActiveSupport::TestCase
7 => "362ec2acfad421eaf6299bdeae78d859e13f8d4a65b6a3e615a80b274219698a",
8 => "a4d113aa214e8754361484267d377174b2aeda3fe01c5ca0c553f9ab76ef2ab0",
9 => "9f814939a5125a6903d9ba4e96392056ffafe9f6110b10b5c1cae0d87a564ac7",
- 10 => "0bcaa72ed675acde5d5ae2ce72305bf73375c0faa5580fe80e3985e88aa4f9e4"
+ 10 => "0bcaa72ed675acde5d5ae2ce72305bf73375c0faa5580fe80e3985e88aa4f9e4",
+ 11 => "e706a4aba7b25ef1ec3d9dacbd6ca489e4abe577b54875ac377a48138890b450"
}.freeze
test "backfill manifest changes come with a CURRENT_BACKFILL_VERSION bump" do