Stop streaming the Enable Banking panel to the family
Summary
After an Enable Banking sync, EnableBankingItem::SyncCompleteEvent broadcast the admin-only Settings › Providers panel on the family Turbo stream, which every family member subscribes to. The panel's form filled in the stored client_certificate, the connection's private key, so every member's browser received it. This PR stops the broadcast. It also makes the panel stop sending the stored credentials (the key and the application ID) back to the browser at all, the same way the Brex panel handles its token.
Closes jaysbeekay/sure#350
Upstream PR: we-promise/sure#4044 (same branch, same commit). Upstream issue: we-promise/sure#4043.
What changed
EnableBankingItem::SyncCompleteEvent: the panelbroadcast_replace_tois removed.family.broadcast_sync_complete(the sync toast) still runs, and it already makes each browser re-fetch its own page on an authenticated request, so an admin on the settings page still sees the new status._enable_banking_panel.html.erb: the certificatetext_arearenders blank (value: ""). Once a certificate is stored, the field's help text reads "Leave blank to keep the current certificate". The new keysettings.providers.enable_banking_panel.keep_client_certificate_hintis translated in all 16 settings locales, as Brex's is. It renders only while the field is editable: once the connection is authenticated the fields are disabled and not submitted, so the hint is hidden there. The PEM example placeholder is unchanged._enable_banking_panel.html.erb, application ID: thetext_fieldrenders empty (value: nil), so the stored ID is no longer echoed back either. The existing update placeholder already reads "Enter new ID to update". The lock condition the panel wrote out three times is now one local,credentials_locked.EnableBankingItemsController#enable_banking_item_params: on update, a blankclient_certificateis dropped, so saving the form without pasting a new one keeps the stored certificate. This is the same lineBrexItemsControlleruses for its token. The same rule coversapplication_id: one list of credentials, dropped when blank on a persisted item. Create is unaffected and still requires both (validates :application_id, presence: trueandvalidates :client_certificate, presence: true, on: :create).config/initializers/filter_parameter_logging.rb::application_idadded, so it stays out of request logs.
Deliberately not changed:
- The account card broadcast in the same event. That one belongs to we-promise/sure#3630, which is handled separately.
encrypts :application_id. The application ID goes in the clear in the JWT header (kid) of every request Sure signs (Provider::EnableBanking#generate_jwt), so it identifies the key rather than being the secret. Encrypting it at rest would be a separate change with its own backfill.filter_parametersnow keeps it out of the logs.
Demo data
No demo data needed: demo families have no Enable Banking connection.
Screenshots
The visible changes are on the credential fields of Settings › Providers › Enable Banking for a saved connection. The certificate field is now empty, showing the usual PEM example placeholder, with the help text "Leave blank to keep the current certificate" under it, instead of the stored PEM. The application ID field is empty too, showing its existing "Enter new ID to update" placeholder. When the connection is authenticated, both fields stay disabled as before and the hint isn't shown. Nothing else in the layout changes.
Migration notes
No migration.
Verification
Tests were written first. On main (a92dec1e6), three of the new tests failed:
EnableBankingItem::SyncCompleteEventTest"a finished sync does not stream the settings panel to the family": a stream targetingenable_banking-providers-panelwas present.EnableBankingItemsControllerTest"the panel does not send the stored certificate back to the browser": the PEM was in the page.- "an update with a blank certificate keeps the stored one": the stored certificate was overwritten.
These pass before and after, as guards should:
- "a finished sync still refreshes the connection card and the sync toast" (renamed and narrowed in the review round below);
- "an update with a new certificate replaces the stored one";
- "a create still requires a certificate".
Breaking the fix on purpose fails a test each time (first round):
| Breakage | Caught by |
|---|---|
| Panel broadcast put back | does not stream the settings panel |
value: "" removed from the field | does not send the stored certificate back |
| Help text removed | does not send the stored certificate back |
| Keep-on-blank line removed | blank certificate keeps the stored one |
| Sync toast dropped from the event | still refreshes the card and the toast |
Review round (the we-promise/sure#4044 review comment 6059318886)
Four commits answer the four points:
66b0ce155Stop pre-filling the Enable Banking application IDd9bdd8f3aAssert only the sync toast after an Enable Banking sync9017e897fShow the keep-certificate hint only on an editable field745b2a06cTranslate the keep-certificate hint into Brazilian Portuguese
New tests, each written first:
- "the panel does not send the stored application id back to the browser". It failed before the fix: the stored ID was in the page.
- "an update with a blank application id keeps the stored one". It failed before the fix with a 422: the blank overwrote the stored ID, and presence validation rejected it.
- "the application id is filtered from logs". It failed without the initializer change, with
application_idunfiltered. - "the panel hides the keep-certificate hint while the credentials are locked". It failed before the fix: the hint was in the page.
- Guards that pass before and after: "an update with a new application id replaces the stored one" and "a create still requires an application id".
The sync-toast test is renamed to "a finished sync still sends the sync toast" and no longer expects the enable_banking_item_<id> card target, which we-promise/sure#4046 removes on purpose. With the card broadcast deleted, the old test fails and the new one passes.
| Breakage | Caught by |
|---|---|
| Application ID pre-filled again | does not send the stored application id back |
| Keep-on-blank covers only the certificate | blank application id keeps the stored one |
| Keep-on-blank covers only the application ID | blank certificate keeps the stored one |
| Credentials dropped even when present | new application id replaces / new certificate replaces |
| Application ID presence validation removed | a create still requires an application id |
:application_id removed from filter_parameters | the application id is filtered from logs |
| Hint shown on the locked field | hides the keep-certificate hint while locked |
| Hint never shown | does not send the stored certificate back |
| Fields never locked | hides the keep-certificate hint while locked |
| Sync toast dropped from the event | a finished sync still sends the sync toast |
One mutation survives, and it's equivalent: dropping blank credentials on create as well. On a new record the missing attribute is nil, and the presence validation rejects it either way.
Commands:
bin/rails teston745b2a06c: 10,845 runs, 46,239 assertions, 0 failures, 0 errors, 33 skips (TZ=UTC). Enable Banking controller tests: 24 runs, 0 failures.bin/rubocopon the changed Ruby files: no offenses.erb_linton the panel: no errors.bin/brakeman --no-pager: 0 warnings.bin/rails testond9a55178d: 10,839 runs, 46,221 assertions, 0 failures, 0 errors, 33 skips (run withTZ=UTC; without it, one holdings test that usesDate.todayfails when the run crosses local midnight).- Enable Banking model/controller tests and
Settings::ProvidersControllerTest: 157 runs, 0 failures. bin/rubocopon the changed Ruby files: no offenses.erb_linton the panel: no errors.bin/brakeman --no-pager: 0 warnings.- No JavaScript changed.
Secret scan
The test certificate is generated with OpenSSL::PKey::RSA and identified by a line of its body, and the panel's PEM placeholder line isn't touched. So the diff adds no private-key header, which the security-scan (pipelock) job rejects.
Blast radius
enable_banking_item_paramshas two callers,createandupdate. Increate,@enable_banking_itemis nil when the params are read, so the guard doesn't apply.- When the connection is authenticated, the fields are
disabledand aren't submitted, so the keep-on-blank rule doesn't apply and the hint is hidden. application_idis also read byProvider::EnableBanking(JWTkid), the provider adapter, thenew_connectioncopy inauthorizeandFamily#create_enable_banking_item!. All of them read the stored value and are unchanged.filter_parametersmatches partially, so Doorkeeper's integerapplication_idcolumns onoauth_access_grantsandoauth_access_tokensnow also read[FILTERED]ininspectoutput. No OAuth request parameter is namedapplication_id.- Locales: every settings locale with an Enable Banking panel block now carries the hint.
config/locales/views/application/fr.ymlrepeats the French panel keys, andsettings/fr.ymlsupplies the hint. - The panel is rendered by
Settings::ProvidersControllerandEnableBankingItemsController(both admin-only), and no longer by the event. new_connectioncopies the certificate server-side and doesn't read the form.- Siblings:
git grep broadcast_replace_tooverapp/modelsandapp/jobsfinds no othersettings/providers/*partial sent on the family stream.