Skip to content

Fix: public API toggle silently fails to save on auth/CSRF error - #57

Open
rsimplicio wants to merge 1 commit into
kroeberd:mainfrom
rsimplicio:fix/public-api-toggle-silent-failure
Open

Fix: public API toggle silently fails to save on auth/CSRF error#57
rsimplicio wants to merge 1 commit into
kroeberd:mainfrom
rsimplicio:fix/public-api-toggle-silent-failure

Conversation

@rsimplicio

Copy link
Copy Markdown

Summary

  • togglePublicApi() updated the switch UI optimistically before the save request resolved, and only checked the JSON body's ok field to show a success toast — a non-2xx response (expired session → 401, stale CSRF → 403) left the switch showing "on" with no error shown, while nothing was actually persisted server-side.
  • Confirmed via direct testing against /api/config that persistence itself was already correct once a request succeeds (survives disk write, restart, etc.) — this was purely a client-side silent-failure bug.
  • Now the UI only updates after a confirmed 2xx + {ok:true} response; a failed save surfaces a visible error toast instead of failing silently.
  • Particularly relevant here since this setting controls whether /api/state is exposed without authentication — a silently-wrong toggle is a bigger problem on a security-relevant control than a cosmetic one.

Test plan

  • node --check on the extracted script block — no syntax errors
  • Built and ran the branch via the repo's own Dockerfile in an isolated container
  • Simulated the success path (valid session + correct CSRF) — {"ok":true}, public_api_state correctly flips and persists to disk
  • Simulated the failure path (valid session + stale/wrong CSRF, same response shape as an expired session) — {"ok":false,"error":"CSRF validation failed"}, and disk state correctly stays unchanged rather than silently claiming success

togglePublicApi() updated the switch UI optimistically before the
save request resolved, and only checked JSON body `ok` for a success
toast — a non-2xx response (expired session -> 401, stale CSRF -> 403)
left the toggle showing "on" with no error, while nothing was actually
persisted. Confirmed via direct API testing that persistence itself
was already correct; this was purely a client-side silent-failure bug.

Now the UI only updates after a confirmed 2xx + {ok:true} response,
and a failed save surfaces a visible error toast instead of failing
silently. Particularly relevant here since this setting controls
whether /api/state is exposed without authentication.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant