Skip to content

fix(ui): the SSH toggle read the ops payload one level too shallow, so it inverted the operator's intent (#2411) - #2413

Merged
dolho merged 1 commit into
devfrom
fix/2411-ssh-toggle-payload-shape
Aug 28, 2026
Merged

dolho merged 1 commit into
devfrom
fix/2411-ssh-toggle-payload-shape

Conversation

@dolho

@dolho dolho commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

The SSH access toggle read GET /api/settings/ops/config flat while the endpoint nests settings twice, so it was undefined === 'true' on every load: the switch rendered OFF whatever was stored, and since the click handler negates that state, the first click always sent true — an operator with ephemeral SSH enabled, clicking to disable it, re-enabled it and then watched it render as off.

The write path was always correct. The mismatch was one-sided, which is why it looked like a change stuck for the session and silently reverted on reload.

The issue's own suggested fix is not sufficient

#2411 proposes response.data.settings?.ssh_access_enabled. That is still wrong, for the same underlying reason. get_ops_settings builds a descriptor per key:

ops_config[key] = {"value": current_value, "default": default_value,
                   "description": ..., "is_default": ...}

So settings.ssh_access_enabled is an object, and object === 'true' is false — the toggle would still have rendered OFF while looking fixed. The .value hop is the one that matters, and a test pins it so the half-fix cannot come back as a "simplification".

Why a pure module rather than a one-line edit

The issue says the value is in the test rather than the fix, and that is only achievable with a seam: Settings.vue cannot be mounted here — @vue/test-utils is not a dependency and vitest runs environment: 'node' — so a rule kept inline is a rule no test can reach. That is exactly how a one-line read bug survived inside a security control.

utils/opsSettings.js owns both spellings — readOpsBool for the read, opsBoolValue for the write — in one file rather than at opposite ends of a 3500-line SFC, which is what let them drift.

Acceptance criteria

AC Status
Toggle reflects the stored value, verified both enabled and disabled ✅
With SSH enabled, one click disables it ✅
Regression test naming the issue that fails without the fix ✅ mutation-checked, below
Malformed/absent payload degrades to false (safe direction) ✅ 9 cases
No sibling binding shares the mismatch ✅ and now pinned by a test, not eyeballed once

The endpoint is untouched, per the issue's explicit instruction — PUT /ops/config takes the nested shape and the other ops readers depend on the current contract.

false is the safe degrade direction on purpose: ssh_access_enabled defaults to "false" server-side, and a control that cannot read its own state must not claim the permissive one.

Verification

Each side of the fix was mutation-checked rather than assumed:

reader reverted to payload?.[key]           → 4 failed
SFC reverted to the flat read that shipped  → 2 failed
restored                                     → 18 passed

Full frontend suite: 64 files / 1454 tests, green. vite build clean. Raw-color ratchet unaffected (no new colour usage).

Closes #2411

🤖 Generated with Claude Code

…o it inverted the operator's intent (#2411)

`GET /api/settings/ops/config` nests settings TWICE, and `Settings.vue` read
them flat:

    { settings: { ssh_access_enabled: { value: "true", default: "false", … } } }

`response.data.ssh_access_enabled` is `undefined`, `undefined === 'true'` is
`false`, and the switch rendered OFF whatever was stored. Because the click
handler computes `!sshAccessEnabled.value`, the FIRST click then always sent
`true` — an operator with ephemeral SSH enabled, clicking to DISABLE it,
re-enabled it and watched it render as off. The write path was always correct,
so the mismatch was one-sided: a change appeared to stick for the session and
silently reverted on reload, which is why it went unnoticed.

## The issue's own suggested fix is not sufficient

#2411 proposes `response.data.settings?.ssh_access_enabled`. That is still
wrong, for the same underlying reason: `get_ops_settings` builds a DESCRIPTOR
per key (`value`/`default`/`description`/`is_default`), so it resolves to an
object and `object === 'true'` is `false` — the toggle would still have rendered
OFF while looking fixed. The `.value` hop is the one that matters. Pinned by its
own test so the half-fix cannot be reintroduced as a "simplification".

## Why a pure module rather than a one-line edit

`Settings.vue` cannot be mounted in this project's test setup — `@vue/test-utils`
is not a dependency and vitest runs `environment: 'node'` — so a rule kept
inline is a rule no test can reach. That is exactly how a one-line read bug
survived inside a security control, and it is the reason the issue says the
value is in the test rather than the fix.

`utils/opsSettings.js` owns both spellings: `readOpsBool` for the read and
`opsBoolValue` for the write, together in one file instead of at opposite ends
of a 3500-line SFC, which is what let them drift in the first place. It accepts
the descriptor form and a bare string, since the only thing separating them is a
wrapper the reader does not need.

Everything unreadable degrades to `false` (AC #4) — absent key, absent
`settings`, null payload, a number, `settings` that is not an object. `false` is
the SAFE direction: `ssh_access_enabled` defaults to `"false"` server-side, and
a security control that cannot read its own state must not claim the permissive
one.

The endpoint is untouched, per the issue's explicit instruction: `PUT
/ops/config` takes the nested shape and the other ops readers depend on the
current contract. The endpoint is the side that is right.

## Verification

18 tests, and each side of the fix mutation-checked rather than assumed:

- reader reverted to `payload?.[key]`            → 4 failed
- SFC reverted to the flat read that shipped     → 2 failed
- restored                                        → 18 passed

AC #5 is pinned rather than eyeballed once: a test asserts `ops/config` is read
in exactly one place, so a second GET added later has to come through the same
reader. Full frontend suite 64 files / 1454 tests; `vite build` clean.

Closes #2411

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@dolho dolho added complexity-low Complexity: low (board points 1-3) priority-p1 Critical path theme-security Theme: Security type-bug Bug fix labels Aug 27, 2026
@dolho
dolho requested a review from obasilakis August 27, 2026 12:59

@obasilakis obasilakis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/validate-pr — approving.

Correct diagnosis and the fix goes to the right place. Worth stating plainly what this was: a security control that rendered OFF regardless of what was stored, on a UI whose click handler negates the rendered state — so an operator with ephemeral SSH enabled, clicking to disable it, re-enabled it and then watched it render as off. The write path was always right, which is exactly why it looked like it stuck for the session and reverted on reload.

The detail that makes this more than a one-line patch is noticing that the fix the issue itself proposes — response.data.settings?.ssh_access_enabled — is still wrong: it resolves to the descriptor object, and object === 'true' is false. The toggle would have stayed broken while looking fixed, and the test pinning that is the most valuable assertion in the file.

Degrading everything unreadable to false is the right direction for this flag specifically, and the comment says why rather than asserting it.

The axios.get('/api/settings/ops/config') call-count assertion is a good structural pin: it makes a second reader added later come through the same rule instead of re-deriving the shape.

Checklist: base dev, Closes #2411, security scan clean, no packaging or infra surface, no schema change. Docs commit-message-only per the tiered rule. CI green including e2e.

One note, non-blocking: readOpsBool accepts 'TRUE' and ' true ' while the server's validate_ops_setting requires exactly 'true'/'false'. The comment justifies it (a hand-edited DB row should not silently read as false) and the asymmetry is in the tolerant direction on the read side only, so it is fine — just flagging that reader and writer no longer agree on the accepted vocabulary.

theme-security on a P1: this is a frontend read fix and the backend gate on ephemeral SSH minting is untouched, so I did not run /cso --diff over it.

@dolho
dolho merged commit 075f98f into dev Aug 28, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

complexity-low Complexity: low (board points 1-3) priority-p1 Critical path theme-security Theme: Security type-bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants