Stop the Lunch Flow panel rendering the stored API key

JA
5d ago
+69-2

Summary

The Lunch Flow panel rendered the stored API key into the page. Its API key input used text_field … type: :password with no value: nil, so Rails wrote the decrypted key into the input's value attribute. The browser masks it on screen, but it was in the HTML of the Bank sync drawer and of every Turbo re-render after an update. The field now passes value: nil, as the Brex and Mercury panels already do. Because the form then submits the key blank unless the user types a new one, a blank key no longer overwrites the stored one on update.

This mirrors exactly the Lunch Flow part of the standalone fix for the same leak across several provider panels (branch up/provider-secret-fields, head 91a48d65a, from upstream main 755ce258c; it also fixes CoinStats, Indexa Capital and Sophtron), so this stack rebases cleanly once main has that fix. In this stack Lunch Flow's permitted params live in LunchflowItemsController#item_params, the kit controller subclass since B7b, so the same two lines go there. Brex's and Mercury's panels don't leak.

Part of jaysbeekay/sure#670 (Track B, view layer, owner decision of 2026-11-16: fix the leak before the Lunch Flow views move onto the kit). Stacked on B8c (jaysbeekay/sure#748) in fork stack #687, ahead of the Lunch Flow view slices.

Upstream draft PR: https://github.com/we-promise/sure/pull/5257 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit.

Behaviour delta (Lunch Flow)

BeforeAfter
The panel's API key input (drawer and Turbo re-render)value="<the stored key>"no value; the placeholder still says "Enter new API key to update"
Updating with the API key left blankoverwrote the stored key with "" (latent until now, since the field always resubmitted the key)keeps the stored key; the other fields still change
Updating with a new API keyreplaced the keyunchanged
The accounts cache on an update without a new keydropped (the resubmitted key counted as a credential change)still dropped from the panel: it always submits base_url, which is cache-sensitive too. Kept only for a PATCH that sends neither the key nor base_url. Dropping is the conservative side: one extra provider call, never a stale list.
Creating a connectionunchangedunchanged (a blank key still fails "Api key can't be blank")

What changed

  • app/views/settings/providers/_lunchflow_panel.html.erb: value: nil on the API key field.
  • LunchflowItemsController#item_params: drop a blank api_key for a saved connection (the upstream fix's two lines from lunchflow_params).
  • Tests: the upstream fix's three LunchflowItemsControllerTest tests, verbatim and in the same place. Also a Lunch Flow-only connect-form test in a new file; the upstream fix checks the connect form in Settings::ProvidersControllerTest together with providers this stack doesn't touch.

Screenshots

Settings > Providers, the Lunch Flow connection from the test fixtures, whose stored API key is test_api_key_123. Before is this PR's base (we-promise/sure#5256's head), after is this PR's head. The masked field looks much the same, so the last column switches the input to type=text in the browser to show the value the page carries: the stored key before, nothing after.

LightDarkInput shown as text
Beforebefore-lightbefore-darkbefore-revealed
Afterafter-lightafter-darkafter-revealed

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Tests (fail-first): on the old code three fail: the re-rendered panel echoing the key, the drawer's connect form echoing it, and a blank submit erasing it. "A new API key replaces the stored key" passes before and after, as a guard.
  • Mutations: the field echoing the key again (both render tests catch it); a blank key overwriting (caught). Dropping a blank key on create too survives, because a blank key on create already fails the presence validation, so the two are equivalent.
  • bin/rails test (full, at this commit): 16,495 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop, erb_lint: no offenses. bin/brakeman: no warnings.
  • Size: non-test +4 / -2.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • item_params is read by the kit controller's create and update for Lunch Flow only.
  • Siblings: Brex's and Mercury's credential fields already pass value: nil and their params already drop a blank token; the other leaking panels are covered by the standalone fix.