fix(sources): require secrets again when a source's address changes #26

Manually merged
jfro merged 0 commits from fix/11-secret-retarget into main 2026-11-01 17:48:02 +00:00
Owner

Closes #11 (gap audit F2).

Sources.persist_attrs/2 and test_connection/2 kept a blank secret as "keep stored" even when the source's URL changed, so Test connection or Save sent the stored credential to the newly entered host. Any logged-in account could read out every stored API key that way.

What changes

  • A saved source is retargeted when any address field changes: a :url field, or one keyed :url or :host (Docker's unix:///https:// address and QNAP's host are :string).
  • Retargeted: every stored secret that's left blank gets "enter it again, since the address changed", so Test connection returns the form errors without polling, and Save is refused. Saving with new secrets stores only those; the old ones are dropped.
  • Unchanged address: same as before, blank keeps the stored secret.
  • Field docs describe the rule.

Tests: 3 new in sources_test.exs ("changing a source's address"): Test connection and Save to a new address with a blank secret are refused, the DB keeps the old endpoint, and the new secret replaces the old one; an unchanged address still keeps it. The first two fail on main. mix precommit: 627 pass.

Screenshot: Proxmox Backup source, URL changed and Test connection pressed, desktop and 390px:
11-retarget-desktop
11-retarget-mobile

Closes #11 (gap audit F2). `Sources.persist_attrs/2` and `test_connection/2` kept a blank secret as "keep stored" even when the source's URL changed, so Test connection or Save sent the stored credential to the newly entered host. Any logged-in account could read out every stored API key that way. **What changes** - A saved source is *retargeted* when any address field changes: a `:url` field, or one keyed `:url` or `:host` (Docker's `unix://`/`https://` address and QNAP's host are `:string`). - Retargeted: every stored secret that's left blank gets "enter it again, since the address changed", so Test connection returns the form errors without polling, and Save is refused. Saving with new secrets stores only those; the old ones are dropped. - Unchanged address: same as before, blank keeps the stored secret. - `Field` docs describe the rule. **Tests**: 3 new in `sources_test.exs` ("changing a source's address"): Test connection and Save to a new address with a blank secret are refused, the DB keeps the old endpoint, and the new secret replaces the old one; an unchanged address still keeps it. The first two fail on main. `mix precommit`: 627 pass. **Screenshot**: Proxmox Backup source, URL changed and Test connection pressed, desktop and 390px: ![11-retarget-desktop](https://git.knope.dev/attachments/573ed688-8617-47a6-b153-16a73965957f) ![11-retarget-mobile](https://git.knope.dev/attachments/90f44551-d2bf-43c8-aa10-5089ffad5127)
jfro added this to the v1.0 milestone 2026-11-01 17:03:40 +00:00
fix(sources): require secrets again when a source's address changes
All checks were successful
CI / test (pull_request) Successful in 24s
022a94befc
Leaving a secret blank kept the stored one even when the URL changed, so
Test connection or Save sent the stored credential to whatever host was
just entered, and any logged-in account could read out every stored API
key. Changing a :url field (or one keyed :url or :host) now drops the
stored secrets: they have to be entered again, with an error saying why.

Closes #11
Author
Owner

Review (Nye) at 022a94b: ready.

  • Every edit path (form validate, Save, Test connection) goes through change_source.
  • retarget_all_types_test.exs covers all 10 source types with an address + secret (19 pairs): changing the URL/host requires each secret again; whitespace-only changes don't.
  • secret_retarget_test.exs (F2 audit test, updated for the fix): Test connection is refused and sends nothing, Save is refused, the stored key survives, a new key replaces it.
  • mix precommit passes, 630 tests.

Non-blocking: changing only TLS trust (fingerprint/CA) keeps the stored secrets; exploiting that also needs network position, so a follow-up at most.

Review (Nye) at 022a94b: ready. - Every edit path (form validate, Save, Test connection) goes through `change_source`. - `retarget_all_types_test.exs` covers all 10 source types with an address + secret (19 pairs): changing the URL/host requires each secret again; whitespace-only changes don't. - `secret_retarget_test.exs` (F2 audit test, updated for the fix): Test connection is refused and sends nothing, Save is refused, the stored key survives, a new key replaces it. - `mix precommit` passes, 630 tests. Non-blocking: changing only TLS trust (fingerprint/CA) keeps the stored secrets; exploiting that also needs network position, so a follow-up at most.
jfro manually merged commit bb700f37d7 into main 2026-11-01 17:48:02 +00:00
Sign in to join this conversation.
No description provided.